@@ -5,6 +5,10 @@ glibc loongarch
55loongarch syscall is very similar to riscv. but it is using syscall instruction like x86_64
66*/
77
8+ #include < cstddef>
9+ #include < cstdint>
10+ #include < concepts>
11+
812namespace fast_io
913{
1014
@@ -31,13 +35,14 @@ inline return_value_type system_call(auto p1) noexcept
3135}
3236
3337template <::std::uint_least64_t syscall_number>
38+ [[noreturn]]
3439inline void system_call_no_return (auto p1) noexcept
3540{
3641 register ::std::uint_least64_t a7 __asm__ (" $a7" ) = syscall_number;
3742 register ::std::uint_least64_t a0 __asm__ (" $a0" ) = (::std::uint_least64_t )p1;
3843 __asm__ __volatile__ (" syscall 0" : " +r" (a0) : " r" (a7) : " $t0" , " $t1" , " $t2" , " $t3" , " $t4" ,
3944 " $t5" , " $t6" , " $t7" , " $t8" , " memory" );
40- __builtin_unreachable ();
45+ __builtin_unreachable ();
4146}
4247
4348template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type>
@@ -52,6 +57,19 @@ inline return_value_type system_call(auto p1, auto p2) noexcept
5257 return static_cast <return_value_type>(a0);
5358}
5459
60+ template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type>
61+ requires (1 < sizeof (return_value_type))
62+ [[__gnu__::__always_inline__]]
63+ inline return_value_type inline_syscall (auto p1, auto p2) noexcept
64+ {
65+ register ::std::uint_least64_t a7 __asm__ (" $a7" ) = syscall_number;
66+ register ::std::uint_least64_t a0 __asm__ (" $a0" ) = (::std::uint_least64_t )p1;
67+ register ::std::uint_least64_t a1 __asm__ (" $a1" ) = (::std::uint_least64_t )p2;
68+ __asm__ __volatile__ (" syscall 0" : " +r" (a0) : " r" (a7), " r" (a1) : " $t0" , " $t1" , " $t2" , " $t3" , " $t4" ,
69+ " $t5" , " $t6" , " $t7" , " $t8" , " memory" );
70+ return static_cast <return_value_type>(a0);
71+ }
72+
5573template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type>
5674 requires (1 < sizeof (return_value_type))
5775inline return_value_type system_call (auto p1, auto p2, auto p3) noexcept
@@ -111,6 +129,7 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5
111129}
112130
113131template <::std::integral I>
132+ [[noreturn]]
114133inline void fast_exit (I ret) noexcept
115134{
116135 system_call_no_return<__NR_exit>(ret);
0 commit comments