[PATCH v2 2/5] LoongArch: Add support for LA32 in sysdeps/loongarch/fpu

mengqinggang mengqinggang@loongson.cn
Mon Dec 22 03:52:46 GMT 2025


在 2025/12/18 21:15, Adhemerval Zanella Netto 写道:
>
> On 18/12/25 09:30, mengqinggang wrote:
>> ---
>>   sysdeps/loongarch/fpu/e_scalb.c                  | 10 ++++++++++
>>   sysdeps/loongarch/fpu/e_scalbf.c                 | 10 ++++++++++
>>   sysdeps/loongarch/fpu/math-use-builtins-llrint.h |  2 +-
>>   sysdeps/loongarch/fpu/math-use-builtins-logb.h   |  2 +-
>>   sysdeps/loongarch/fpu/math-use-builtins-lrint.h  |  2 +-
>>   sysdeps/loongarch/fpu/math-use-builtins-rint.h   |  2 +-
>>   sysdeps/loongarch/fpu/math-use-builtins-sqrt.h   | 10 ++++++++--
>>   sysdeps/loongarch/fpu/s_scalbn.c                 | 10 ++++++++++
>>   sysdeps/loongarch/fpu/s_scalbnf.c                |  8 ++++++++
>>   sysdeps/loongarch/fpu/w_ilogb-impl.h             |  8 ++++++++
>>   sysdeps/loongarch/fpu/w_ilogbf-impl.h            |  8 ++++++++
>>   11 files changed, 66 insertions(+), 6 deletions(-)
>>
>> diff --git a/sysdeps/loongarch/fpu/e_scalb.c b/sysdeps/loongarch/fpu/e_scalb.c
>> index 039cbd6ac8..439e38c6a7 100644
>> --- a/sysdeps/loongarch/fpu/e_scalb.c
>> +++ b/sysdeps/loongarch/fpu/e_scalb.c
>> @@ -16,6 +16,8 @@
>>      License along with the GNU C Library; if not, see
>>      <https://www.gnu.org/licenses/>.  */
>>   
>> +#ifdef __loongarch64
>> +
>>   #define NO_MATH_REDIRECT
>>   #include <math.h>
>>   #include <libm-alias-finite.h>
>> @@ -57,4 +59,12 @@ __ieee754_scalb (double x, double fn)
>>   
>>     return x;
>>   }
>> +
>>   libm_alias_finite (__ieee754_scalb, __scalb)
>> +
>> +#else /* #ifdef __loongarch64 */
>> +
>> +#include <sysdeps/generic/math-type-macros-double.h>
>> +#include <math/e_scalb_template.c>
>> +
>> +#endif /* #ifdef __loongarch64 */
> I don't have a strong opinion, but maybe it would be better to add
> an extra Implies subfolder like other ABIs that support multilib
> and move the loongarch64 implementation to it:
>
>    sysdeps/loongarch/fpu/e_scalb.c -> sysdeps/loongarch/loongarch64/fpu/e_scalb.c
>
> So the selection is done automatically instead adjust to use the
> generic implementation on multiple files.


There is already a sysdeps/loongarch/lp64  for lp64 ABI. Move files 
controlled by
__loongarch64 macro to sysdeps/loongarch/lp64/fpu?

>
>> diff --git a/sysdeps/loongarch/fpu/e_scalbf.c b/sysdeps/loongarch/fpu/e_scalbf.c
>> index 4a4092cf40..c8196f7d6e 100644
>> --- a/sysdeps/loongarch/fpu/e_scalbf.c
>> +++ b/sysdeps/loongarch/fpu/e_scalbf.c
>> @@ -16,6 +16,8 @@
>>      License along with the GNU C Library; if not, see
>>      <https://www.gnu.org/licenses/>.  */
>>   
>> +#ifdef __loongarch64
>> +
>>   #define NO_MATH_REDIRECT
>>   #include <math.h>
>>   #include <libm-alias-finite.h>
>> @@ -57,4 +59,12 @@ __ieee754_scalbf (float x, float fn)
>>   
>>     return x;
>>   }
>> +
>>   libm_alias_finite (__ieee754_scalbf, __scalbf)
>> +
>> +#else /* #ifdef __loongarch64 */
>> +
>> +#include <sysdeps/generic/math-type-macros-float.h>
>> +#include <math/e_scalb_template.c>
>> +
>> +#endif /* #ifdef __loongarch64 */
>> diff --git a/sysdeps/loongarch/fpu/math-use-builtins-llrint.h b/sysdeps/loongarch/fpu/math-use-builtins-llrint.h
>> index bee5910b09..82f89d41f9 100644
>> --- a/sysdeps/loongarch/fpu/math-use-builtins-llrint.h
>> +++ b/sysdeps/loongarch/fpu/math-use-builtins-llrint.h
>> @@ -1,4 +1,4 @@
>> -#if __GNUC_PREREQ (13, 0)
>> +#if __GNUC_PREREQ (13, 0) && __loongarch_grlen == 64
>>   # define USE_LLRINT_BUILTIN 1
>>   # define USE_LLRINTF_BUILTIN 1
>>   #else
>> diff --git a/sysdeps/loongarch/fpu/math-use-builtins-logb.h b/sysdeps/loongarch/fpu/math-use-builtins-logb.h
>> index b1c3f30dc4..d8ca3d1aa2 100644
>> --- a/sysdeps/loongarch/fpu/math-use-builtins-logb.h
>> +++ b/sysdeps/loongarch/fpu/math-use-builtins-logb.h
>> @@ -1,4 +1,4 @@
>> -#if __GNUC_PREREQ (13, 0)
>> +#if __GNUC_PREREQ (13, 0) && __loongarch_grlen == 64
>>   # define USE_LOGB_BUILTIN 1
>>   # define USE_LOGBF_BUILTIN 1
>>   #else
>> diff --git a/sysdeps/loongarch/fpu/math-use-builtins-lrint.h b/sysdeps/loongarch/fpu/math-use-builtins-lrint.h
>> index 7df8aac81f..80345fdf3f 100644
>> --- a/sysdeps/loongarch/fpu/math-use-builtins-lrint.h
>> +++ b/sysdeps/loongarch/fpu/math-use-builtins-lrint.h
>> @@ -1,4 +1,4 @@
>> -#if __GNUC_PREREQ (13, 0)
>> +#if __GNUC_PREREQ (13, 0) && __loongarch_grlen == 64
>>   # define USE_LRINT_BUILTIN 1
>>   # define USE_LRINTF_BUILTIN 1
>>   #else
>> diff --git a/sysdeps/loongarch/fpu/math-use-builtins-rint.h b/sysdeps/loongarch/fpu/math-use-builtins-rint.h
>> index cd91482f5f..73ce3e45bc 100644
>> --- a/sysdeps/loongarch/fpu/math-use-builtins-rint.h
>> +++ b/sysdeps/loongarch/fpu/math-use-builtins-rint.h
>> @@ -1,4 +1,4 @@
>> -#if __GNUC_PREREQ (13, 0)
>> +#if __GNUC_PREREQ (13, 0) && __loongarch_grlen == 64
>>   #  define USE_RINT_BUILTIN 1
>>   #  define USE_RINTF_BUILTIN 1
>>   #else
>> diff --git a/sysdeps/loongarch/fpu/math-use-builtins-sqrt.h b/sysdeps/loongarch/fpu/math-use-builtins-sqrt.h
>> index e94c915ba6..f031bd7536 100644
>> --- a/sysdeps/loongarch/fpu/math-use-builtins-sqrt.h
>> +++ b/sysdeps/loongarch/fpu/math-use-builtins-sqrt.h
>> @@ -1,4 +1,10 @@
>> -#define USE_SQRT_BUILTIN 1
>> -#define USE_SQRTF_BUILTIN 1
>> +#if __loongarch_grlen == 64
>> +  #define USE_SQRT_BUILTIN 1
>> +  #define USE_SQRTF_BUILTIN 1
>> +#else
>> +  #define USE_SQRT_BUILTIN 0
>> +  #define USE_SQRTF_BUILTIN 0
>> +#endif
>> +
>>   #define USE_SQRTL_BUILTIN 0
>>   #define USE_SQRTF128_BUILTIN 0
>> diff --git a/sysdeps/loongarch/fpu/s_scalbn.c b/sysdeps/loongarch/fpu/s_scalbn.c
>> index 34d4cd40a0..cff78c7965 100644
>> --- a/sysdeps/loongarch/fpu/s_scalbn.c
>> +++ b/sysdeps/loongarch/fpu/s_scalbn.c
>> @@ -16,14 +16,24 @@
>>      License along with the GNU C Library; if not, see
>>      <https://www.gnu.org/licenses/>.  */
>>   
>> +#ifdef __loongarch64
>> +
>>   #define NO_MATH_REDIRECT
>>   #include <math.h>
>>   
>> +/* Return x * 2^fn.  */
>>   double
>>   __scalbn (double x, int fn)
>>   {
>>     double tmp;
>> +  /* Move fn to exp.  */
>>     asm volatile ("movgr2fr.d \t%0, %1" : "=f" (tmp) : "r" (fn));
>>     asm volatile ("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp));
>>     return x;
>>   }
>> +
>> +#else /* #ifdef __loongarch64 */
>> +
>> +#include <sysdeps/ieee754/dbl-64/s_scalbn.c>
>> +
>> +#endif /* #ifdef __loongarch64 */
>> diff --git a/sysdeps/loongarch/fpu/s_scalbnf.c b/sysdeps/loongarch/fpu/s_scalbnf.c
>> index fde18cf9c1..933fae8e3d 100644
>> --- a/sysdeps/loongarch/fpu/s_scalbnf.c
>> +++ b/sysdeps/loongarch/fpu/s_scalbnf.c
>> @@ -16,6 +16,8 @@
>>      License along with the GNU C Library; if not, see
>>      <https://www.gnu.org/licenses/>.  */
>>   
>> +#ifdef __loongarch64
>> +
>>   #define NO_MATH_REDIRECT
>>   #include <math.h>
>>   
>> @@ -27,3 +29,9 @@ __scalbnf (float x, int fn)
>>     asm volatile ("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp));
>>     return x;
>>   }
>> +
>> +#else /* #ifdef __loongarch64 */
>> +
>> +#include <sysdeps/ieee754/flt-32/s_scalbnf.c>
>> +
>> +#endif /* #ifdef __loongarch64 */
>> diff --git a/sysdeps/loongarch/fpu/w_ilogb-impl.h b/sysdeps/loongarch/fpu/w_ilogb-impl.h
>> index 1905373189..dd14ea791d 100644
>> --- a/sysdeps/loongarch/fpu/w_ilogb-impl.h
>> +++ b/sysdeps/loongarch/fpu/w_ilogb-impl.h
>> @@ -16,6 +16,8 @@
>>      License along with the GNU C Library; if not, see
>>      <https://www.gnu.org/licenses/>.  */
>>   
>> +#ifdef __loongarch64
>> +
>>   #include <fpu_control.h>
>>   
>>   static inline RET_TYPE
>> @@ -35,3 +37,9 @@ IMPL_NAME (double x)
>>         return x;
>>       }
>>   }
>> +
>> +#else /* #ifdef __loongarch64 */
>> +
>> +#include <sysdeps/ieee754/dbl-64/w_ilogb-impl.h>
>> +
>> +#endif /* #ifdef __loongarch64 */
>> diff --git a/sysdeps/loongarch/fpu/w_ilogbf-impl.h b/sysdeps/loongarch/fpu/w_ilogbf-impl.h
>> index 9cb4172c26..4527dbcd39 100644
>> --- a/sysdeps/loongarch/fpu/w_ilogbf-impl.h
>> +++ b/sysdeps/loongarch/fpu/w_ilogbf-impl.h
>> @@ -16,6 +16,8 @@
>>      License along with the GNU C Library; if not, see
>>      <https://www.gnu.org/licenses/>.  */
>>   
>> +#ifdef __loongarch64
>> +
>>   #include <fpu_control.h>
>>   
>>   static inline RET_TYPE
>> @@ -35,3 +37,9 @@ IMPL_NAME (float x)
>>         return x;
>>       }
>>   }
>> +
>> +#else /* #ifdef __loongarch64 */
>> +
>> +#include <sysdeps/ieee754/flt-32/w_ilogbf-impl.h>
>> +
>> +#endif /* #ifdef __loongarch64 */



More information about the Libc-alpha mailing list