]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
LoongArch: Add soft float support.
authorcaiyinyu <caiyinyu@loongson.cn>
Mon, 22 Aug 2022 08:00:51 +0000 (16:00 +0800)
committercaiyinyu <caiyinyu@loongson.cn>
Thu, 1 Sep 2022 01:10:08 +0000 (09:10 +0800)
17 files changed:
scripts/build-many-glibcs.py
sysdeps/loongarch/Makefile
sysdeps/loongarch/__longjmp.S
sysdeps/loongarch/bits/setjmp.h
sysdeps/loongarch/dl-trampoline.S
sysdeps/loongarch/fpu_control.h
sysdeps/loongarch/nofpu/Implies [new file with mode: 0644]
sysdeps/loongarch/nofpu/math-tests-exceptions.h [new file with mode: 0644]
sysdeps/loongarch/nofpu/math-tests-rounding.h [new file with mode: 0644]
sysdeps/loongarch/preconfigure
sysdeps/loongarch/preconfigure.ac
sysdeps/loongarch/setjmp.S
sysdeps/unix/sysv/linux/loongarch/Makefile
sysdeps/unix/sysv/linux/loongarch/configure
sysdeps/unix/sysv/linux/loongarch/configure.ac
sysdeps/unix/sysv/linux/loongarch/ldd-rewrite.sed
sysdeps/unix/sysv/linux/loongarch/shlib-versions

index 98f02104a2fd9eac22617aa652bace78121d29e1..db632b18a337f2ddfe3e63f2f6cffd9522886cd3 100755 (executable)
@@ -222,6 +222,10 @@ class Context(object):
                         os_name='linux-gnu',
                         variant='lp64d',
                         gcc_cfg=['--with-abi=lp64d','--disable-multilib'])
+        self.add_config(arch='loongarch64',
+                        os_name='linux-gnu',
+                        variant='lp64s',
+                        gcc_cfg=['--with-abi=lp64s','--disable-multilib'])
         self.add_config(arch='m68k',
                         os_name='linux-gnu',
                         gcc_cfg=['--disable-multilib'])
index 41c344967010e002b6596bdbf2c2e46b27b97dca..746d4c2c8fdc1c206099eb1ab6861cec5790cdb5 100644 (file)
@@ -5,11 +5,3 @@ endif
 # LoongArch's assembler also needs to know about PIC as it changes the
 # definition of some assembler macros.
 ASFLAGS-.os += $(pic-ccflag)
-
-abi-variants := lp64
-
-ifeq (,$(filter $(default-abi),$(abi-variants)))
-$(error Unknown ABI $(default-abi), must be one of $(abi-variants))
-endif
-
-abi-lp64-condition    := defined __loongarch_lp64
index 4207376f5e1b3ccf0fd10d083f2ac01313f7ba21..d6a99fcbc8453e71650861ebee27b877e6cd29f4 100644 (file)
@@ -41,6 +41,7 @@ ENTRY (__longjmp)
        REG_L s7, a0, 11*SZREG
        REG_L s8, a0, 12*SZREG
 
+#ifndef __loongarch_soft_float
        FREG_L $f24, a0, 13*SZREG + 0*SZFREG
        FREG_L $f25, a0, 13*SZREG + 1*SZFREG
        FREG_L $f26, a0, 13*SZREG + 2*SZFREG
@@ -49,6 +50,7 @@ ENTRY (__longjmp)
        FREG_L $f29, a0, 13*SZREG + 5*SZFREG
        FREG_L $f30, a0, 13*SZREG + 6*SZFREG
        FREG_L $f31, a0, 13*SZREG + 7*SZFREG
+#endif
 
        sltui   a0,a1,1
        ADD     a0, a0, a1       # a0 = (a1 == 0) ? 1 : a1
index 42f8fa765782fe3bf7add29818b49090372280f3..8b323ad2b615000eba582df7b29d849baeee3470 100644 (file)
@@ -31,8 +31,11 @@ typedef struct __jmp_buf_internal_tag
   long int __fp;
   /* Callee-saved registers.  */
   long int __regs[9];
+
+#ifndef __loongarch_soft_float
   /* Callee-saved floating point registers.  */
   double __fpregs[8];
+#endif
 
 } __jmp_buf[1];
 
index ad8ab0fda72d3f3e85c5e557a4a8f3e7a238ab52..9a8f580971ce64f13a23a9311e9985159efa9931 100644 (file)
 
 /* Assembler veneer called from the PLT header code for lazy loading.
    The PLT header passes its own args in t0-t2.  */
-
-# define FRAME_SIZE (-((-10 * SZREG - 8 * SZFREG) & ALMASK))
+#ifdef __loongarch_soft_float
+#define FRAME_SIZE (-((-10 * SZREG) & ALMASK))
+#else
+#define FRAME_SIZE (-((-10 * SZREG - 8 * SZFREG) & ALMASK))
+#endif
 
 ENTRY (_dl_runtime_resolve)
 
@@ -39,6 +42,7 @@ ENTRY (_dl_runtime_resolve)
        REG_S   a6, sp, 7*SZREG
        REG_S   a7, sp, 8*SZREG
 
+#ifndef __loongarch_soft_float
        FREG_S  fa0, sp, 10*SZREG + 0*SZFREG
        FREG_S  fa1, sp, 10*SZREG + 1*SZFREG
        FREG_S  fa2, sp, 10*SZREG + 2*SZFREG
@@ -47,6 +51,7 @@ ENTRY (_dl_runtime_resolve)
        FREG_S  fa5, sp, 10*SZREG + 5*SZFREG
        FREG_S  fa6, sp, 10*SZREG + 6*SZFREG
        FREG_S  fa7, sp, 10*SZREG + 7*SZFREG
+#endif
 
        /* Update .got.plt and obtain runtime address of callee */
        SLLI    a1, t1, 1
@@ -67,6 +72,7 @@ ENTRY (_dl_runtime_resolve)
        REG_L   a6, sp, 7*SZREG
        REG_L   a7, sp, 8*SZREG
 
+#ifndef __loongarch_soft_float
        FREG_L  fa0, sp, 10*SZREG + 0*SZFREG
        FREG_L  fa1, sp, 10*SZREG + 1*SZFREG
        FREG_L  fa2, sp, 10*SZREG + 2*SZFREG
@@ -75,6 +81,7 @@ ENTRY (_dl_runtime_resolve)
        FREG_L  fa5, sp, 10*SZREG + 5*SZFREG
        FREG_L  fa6, sp, 10*SZREG + 6*SZFREG
        FREG_L  fa7, sp, 10*SZREG + 7*SZFREG
+#endif
 
        ADDI    sp, sp, FRAME_SIZE
 
index 1cccc933a58da1f9722dc8385ca421141d1dfb64..f482395dba042aca2f927583948c8bff6f5da537 100644 (file)
 
 #include <features.h>
 
+#ifdef __loongarch_soft_float
+
+#define _FPU_RESERVED 0xffffffff
+#define _FPU_DEFAULT 0x00000000
+typedef unsigned int fpu_control_t;
+#define _FPU_GETCW(cw) (cw) = 0
+#define _FPU_SETCW(cw) (void) (cw)
+extern fpu_control_t __fpu_control;
+
+#else /* __loongarch_soft_float */
+
 /* Masks for interrupts.  */
 #define _FPU_MASK_V 0x10 /* Invalid operation */
 #define _FPU_MASK_Z 0x08 /* Division by zero  */
@@ -86,4 +97,6 @@ extern void __loongarch_fpu_setcw (fpu_control_t) __THROW;
 /* Default control word set at startup.  */
 extern fpu_control_t __fpu_control;
 
+#endif /* __loongarch_soft_float */
+
 #endif /* fpu_control.h */
diff --git a/sysdeps/loongarch/nofpu/Implies b/sysdeps/loongarch/nofpu/Implies
new file mode 100644 (file)
index 0000000..abcbadb
--- /dev/null
@@ -0,0 +1 @@
+ieee754/soft-fp
diff --git a/sysdeps/loongarch/nofpu/math-tests-exceptions.h b/sysdeps/loongarch/nofpu/math-tests-exceptions.h
new file mode 100644 (file)
index 0000000..b22bb01
--- /dev/null
@@ -0,0 +1,28 @@
+/* Configuration for math tests: support for exceptions.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef LOONGARCH_NOFPU_MATH_TESTS_EXCEPTIONS_H
+#define LOONGARCH_NOFPU_MATH_TESTS_EXCEPTIONS_H 1
+
+/* We support setting floating-point exception flags on hard-float
+   targets.  These are not supported on soft-float targets.  */
+#define EXCEPTION_TESTS_float 0
+#define EXCEPTION_TESTS_double        0
+#define EXCEPTION_TESTS_long_double   0
+
+#endif /* math-tests-exceptions.h.  */
diff --git a/sysdeps/loongarch/nofpu/math-tests-rounding.h b/sysdeps/loongarch/nofpu/math-tests-rounding.h
new file mode 100644 (file)
index 0000000..5322e48
--- /dev/null
@@ -0,0 +1,27 @@
+/* Configuration for math tests: rounding mode support.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef LOONGARCH_NOFPU_MATH_TESTS_ROUNDING_H
+#define LOONGARCH_NOFPU_MATH_TESTS_ROUNDING_H 1
+
+/* On soft-float targets we only support the "to nearest" rounding mode.  */
+#define ROUNDING_TESTS_float(MODE)             ((MODE) == FE_TONEAREST)
+#define ROUNDING_TESTS_double(MODE)            ((MODE) == FE_TONEAREST)
+#define ROUNDING_TESTS_long_double(MODE)       ((MODE) == FE_TONEAREST)
+
+#endif /* math-tests-rounding.h.  */
index 118963cda6c44175be5588b6bc3203c48392477e..f2d1a0d87bc47d2d697e27e4e68fc3b8694dac43 100644 (file)
@@ -12,7 +12,6 @@ loongarch*)
     case "$float_abi" in
     soft)
        abi_flen=0
-       as_fn_error 1 "loongarch does not yet support soft floating-point  ABI!!" "$LINENO" 5
        ;;
     single)
        as_fn_error 1 "glibc does not yet support the single floating-point ABI!!" "$LINENO" 5
index 1aba743c157b6b812fa335f66d4c909346bff1da..67e4357013675645d835abef2680294a11daa454 100644 (file)
@@ -12,7 +12,6 @@ loongarch*)
     case "$float_abi" in
     soft)
        abi_flen=0
-       AC_MSG_ERROR([loongarch does not yet support soft floating-point  ABI!!], 1)
        ;;
     single)
        AC_MSG_ERROR([glibc does not yet support the single floating-point ABI!!], 1)
index 298bb02a82692505f8ff5186ca872336c251bfc3..9b1cdea48c7037d65eef97bd2d3f2f1e1e873578 100644 (file)
@@ -50,6 +50,7 @@ ENTRY (__sigsetjmp)
        REG_S s7, a0, 11*SZREG
        REG_S s8, a0, 12*SZREG
 
+#ifndef __loongarch_soft_float
        FREG_S $f24, a0, 13*SZREG + 0*SZFREG
        FREG_S $f25, a0, 13*SZREG + 1*SZFREG
        FREG_S $f26, a0, 13*SZREG + 2*SZFREG
@@ -58,6 +59,7 @@ ENTRY (__sigsetjmp)
        FREG_S $f29, a0, 13*SZREG + 5*SZFREG
        FREG_S $f30, a0, 13*SZREG + 6*SZFREG
        FREG_S $f31, a0, 13*SZREG + 7*SZFREG
+#endif
 
 #if !IS_IN (libc) && IS_IN(rtld)
        li.w            v0, 0
index 91bd35800a9c9a7fea64a7b10a43018caa6419ab..c84a1762edd80b12d3ec699e49e5594218434a69 100644 (file)
@@ -1,3 +1,12 @@
 ifeq ($(subdir),stdlib)
 gen-as-const-headers += ucontext_i.sym
 endif
+
+abi-variants := lp64s lp64d
+
+ifeq (,$(filter $(default-abi),$(abi-variants)))
+$(error Unknown ABI $(default-abi), must be one of $(abi-variants))
+endif
+
+abi-lp64s-condition    := __WORDSIZE == 64 && defined __loongarch_soft_float
+abi-lp64d-condition    := __WORDSIZE == 64 && defined __loongarch_double_float
index 60a410303ea55fa2f7f2a05b4ff6aa24f39a3796..28216c165e3ccce1ed67ddd7782f9641fc7873a4 100644 (file)
@@ -151,11 +151,56 @@ if test $libc_cv_loongarch_int_abi = no; then
   as_fn_error $? "Unable to determine integer ABI" "$LINENO" 5
 fi
 
+libc_cv_loongarch_float_abi=no
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __loongarch_double_float
+                  yes
+                  #endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes" >/dev/null 2>&1; then :
+  libc_cv_loongarch_float_abi=d
+fi
+rm -f conftest*
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __loongarch_soft_float
+                  yes
+                  #endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes" >/dev/null 2>&1; then :
+  libc_cv_loongarch_float_abi=s
+fi
+rm -f conftest*
+
+if test "$libc_cv_loongarch_float_abi" = no; then
+  as_fn_error $? "Unable to determine floating-point ABI" "$LINENO" 5
+fi
+
 config_vars="$config_vars
-default-abi = $libc_cv_loongarch_int_abi"
+default-abi = $libc_cv_loongarch_int_abi$libc_cv_loongarch_float_abi"
 
-case $libc_cv_loongarch_int_abi in
-lp64)
+case $libc_cv_loongarch_int_abi$libc_cv_loongarch_float_abi in
+lp64s)
+  test -n "$libc_cv_slibdir" ||
+case "$prefix" in
+/usr | /usr/)
+  libc_cv_slibdir='/lib64/sf'
+  libc_cv_rtlddir='/lib64'
+  if test "$libdir" = '${exec_prefix}/lib'; then
+    libdir='${exec_prefix}/lib64/sf';
+    # Locale data can be shared between 32-bit and 64-bit libraries.
+    libc_cv_complocaledir='${exec_prefix}/lib/locale'
+  fi
+  ;;
+esac
+  ;;
+lp64d)
   test -n "$libc_cv_slibdir" ||
 case "$prefix" in
 /usr | /usr/)
index 7de1e95ff69cb49c95d5e8e9ed4faee68fefc309..04e9150a9bd71903f99e835d5f2ef859d7080e48 100644 (file)
@@ -11,10 +11,26 @@ if test $libc_cv_loongarch_int_abi = no; then
   AC_MSG_ERROR([Unable to determine integer ABI])
 fi
 
-LIBC_CONFIG_VAR([default-abi], [$libc_cv_loongarch_int_abi])
+libc_cv_loongarch_float_abi=no
+AC_EGREP_CPP(yes, [#ifdef __loongarch_double_float
+                  yes
+                  #endif
+  ],libc_cv_loongarch_float_abi=d)
+AC_EGREP_CPP(yes, [#ifdef __loongarch_soft_float
+                  yes
+                  #endif
+  ],libc_cv_loongarch_float_abi=s)
+if test "$libc_cv_loongarch_float_abi" = no; then
+  AC_MSG_ERROR([Unable to determine floating-point ABI])
+fi
+
+LIBC_CONFIG_VAR([default-abi], [$libc_cv_loongarch_int_abi$libc_cv_loongarch_float_abi])
 
-case $libc_cv_loongarch_int_abi in
-lp64)
+case $libc_cv_loongarch_int_abi$libc_cv_loongarch_float_abi in
+lp64s)
+  LIBC_SLIBDIR_RTLDDIR([lib64/sf], [lib64])
+  ;;
+lp64d)
   LIBC_SLIBDIR_RTLDDIR([lib64], [lib64])
   ;;
 esac
index f8976fd239994bfab8ed33461f83eb2395f2ee6a..cdbe5c3dc58f373a0e84782f3f2916915ae9f9a3 100644 (file)
@@ -1 +1 @@
-s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|32\)\(/[^/]*\)\(-loongarch\)\(64\|32\)\(\.so\.[0-9.]*\)[[:blank:]]*$_\1"\2\4\7 \264\4-loongarch64\7 \232\4-loongarch32\7"_
+s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|32\)\(/ld-linux-loongarch-\)\(lp\|ilp\)\(64\|32\)\(d\|s\)\(\.so\.[0-9.]*\)[[:blank:]]*$_\1"\264\4lp64d\8 \264\4lp64s\8"_
index dc2220b4bee87af147b083105c3e9febb9793fad..5f40e7f5ec65f76cd73466b0ca5147c0752e07ae 100644 (file)
@@ -2,6 +2,8 @@ DEFAULT         GLIBC_2.36
 
 %if LOONGARCH_ABI_GRLEN == 64 && LOONGARCH_ABI_FRLEN == 64
 ld=ld-linux-loongarch-lp64d.so.1
+%elif LOONGARCH_ABI_GRLEN == 64 && LOONGARCH_ABI_FRLEN == 0
+ld=ld-linux-loongarch-lp64s.so.1
 %else
 %error cannot determine ABI
 %endif