diff options
Diffstat (limited to 'libgcc')
91 files changed, 3592 insertions, 666 deletions
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index c505e88..75ba93e 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,407 @@ +2025-12-09 John Ericson <git@JohnEricson.me> + + * config/rs6000/t-slibgcc-aix: Instead of using a + TARGET_SYSTEM_ROOT make variable, just define a shell variable + as part of the rule and use that. + +2025-12-09 John Ericson <git@JohnEricson.me> + + * Makefile.in: Define NO_PIE_CFLAGS make variable via autoconf + substitution. + * configure: Regenerate. + * configure.ac: New configure check to define NO_PIE_CFLAGS + using the algorithm Andrew asked for in the linked mail. + +2025-12-09 John Ericson <git@johnericson.me> + + * configure: Regenerate. + * configure.ac: Use GCC_AC_THREAD_MODEL instead of hand-rolled + +2025-11-27 Lulu Cheng <chenglulu@loongson.cn> + + * config/loongarch/cpuinfo.c (HWCAP_LOONGARCH_LSX): Define + it if it is not defined. + (HWCAP_LOONGARCH_LASX): Likewise. + +2025-11-21 LIU Hao <lh_mouse@126.com> + + PR target/122275 + * config/i386/32/dfp-machine.h (DFP_GET_ROUNDMODE): Change `_frnd_orig` to + `unsigned short` for x87 control word. + (DFP_SET_ROUNDMODE): Manipulate the x87 control word as `unsigned short`, + and manipulate the MXCSR as `unsigned int`. + +2025-11-11 Lulu Cheng <chenglulu@loongson.cn> + + * config/loongarch/t-loongarch64: Add cpuinfo.c to LIB2ADD. + * config/loongarch/cpuinfo.c: New file. + +2025-10-25 Olivier Hainque <hainque@adacore.com> + + * config/t-vxworks (LIBGCC2_INCLUDES): Replace $(VSB_DIR) + by sysroot references. + +2025-10-20 Olivier Hainque <hainque@adacore.com> + Ashley Gay <gay@adacore.com> + + * config/gthr-vxworks.h: Include stdatomic.h and prevent indirect + inclusion of contents from the system version of that header. + +2025-10-20 Olivier Hainque <hainque@adacore.com> + + * config/gthr-vxworks-thread.c (__init_gthread_tcb): Make static. + (__delete_gthread_tcb): Likewise. + (__task_wrapper): Likewise. + (__gthread_create): Convert __task_wrapper to (void *) before going + to (FUNCPTR). + * config/gthr-vxworks-tls.c (tls_delete_hook): Accommodate prototype + variations between kernel and rtp. Return STATUS. + +2025-10-20 Olivier Hainque <hainque@adacore.com> + + * config/t-vxworks: -include vxworks-predef.h explicitly, as the + automatic inclusion is disabled by -nostdinc. + +2025-10-07 H.J. Lu <hjl.tools@gmail.com> + + PR target/120691 + * Makefile.in (DECNUMINC): Add -I$(srcdir)/config/$(cpu_type). + * config/i386/dfp-machine.h: New file. + * config/i386/32/dfp-machine.h: Likewise. + * config/i386/64/dfp-machine.h: Likewise. + +2025-09-30 Andre Vieira <andre.simoesdiasvieira@arm.com> + + * config/t-softfp: Don't use softfp_wrap for bitint functions. + (softfp_cflags): New parameter that is passed to the building of bitint + functions. + +2025-09-25 John David Anglin <danglin@gcc.gnu.org> + + * config/pa/sync-libfuncs.c (atomic_store_8): Fix asm. + +2025-09-19 Jim Lin <jim@andestech.com> + + * config/riscv/save-restore.S: Only save/restore the registers + which are really used for ILP32E/LP64. + +2025-08-21 Dimitar Dimitrov <dimitar@dinux.eu> + + * config/pru/libgcc-eabi.ver: Add __pruabi_softmpyi and + __pruabi_softmpyll symbols. + * config/pru/t-pru: Add softmpy source files. + * config/pru/pru-softmpy.h: New file. + * config/pru/softmpyi.c: New file. + * config/pru/softmpyll.c: New file. + +2025-08-13 Yang Yujie <yangyujie@loongson.cn> + + PR target/117599 + * config/loongarch/t-softfp-tf: Enable _BitInt helper functions. + * config/loongarch/t-loongarch: Same. + * config/loongarch/libgcc-loongarch.ver: New file. + +2025-08-13 Yang Yujie <yangyujie@loongson.cn> + + * config.host: Remove unused code. Include LoongArch-specific + tmake_files after the OS-specific ones. + +2025-08-08 Christophe Lyon <christophe.lyon@linaro.org> + + PR libgcc/117600 + * Makefile.in (WERROR): New. + * config/aarch64/t-aarch64: Handle WERROR. + * configure: Regenerate. + * configure.ac: Add support for --enable-werror. + +2025-08-07 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> + + * config/s390/libgcc-glibc.ver: Export _BitInt support + functions. + * config/s390/t-softfp (softfp_extras): Add fixtfbitint + floatbitinttf. + +2025-08-07 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> + + * config.host: Include makefiles t-softfp for -m64. + * config/s390/sfp-exceptions.c: New file. + * config/s390/sfp-machine.h: New file. + * config/s390/t-softfp: New file. + +2025-08-06 Jakub Jelinek <jakub@redhat.com> + + PR libgcc/121397 + * enable-execute-stack-mprotect.c (check_enabling): Remove useless + forward declaration. + +2025-07-31 Wilco Dijkstra <wilco.dijkstra@arm.com> + + * config/aarch64/cpuinfo.c (__init_cpu_features_constructor): + Remove unused features, add support for CSSC and MOPS. + +2025-07-31 Wilco Dijkstra <wilco.dijkstra@arm.com> + + * config/aarch64/cpuinfo.c: Cleanup HWCAP defines. + +2025-07-31 Yury Khrustalev <yury.khrustalev@arm.com> + + * config/aarch64/cpuinfo.c (__ifunc_arg_t): Likewise. + (__init_cpu_features): obtain and assign values for the + fields _hwcap3 and _hwcap4. + (__init_cpu_features_constructor): check _size in the + arg argument. + +2025-07-17 Richard Sandiford <richard.sandiford@arm.com> + Yury Khrustalev <yury.khrustalev@arm.com> + + * config/aarch64/linux-unwind.h (aarch64_fallback_frame_state): + If a signal was raised while there was an uncommitted lazy save, + commit the save as part of the unwind process. + +2025-07-16 John Ericson <git@JohnEricson.me> + + * Makefile.in: Delete dead `MACHMODE_H` variable + +2025-07-10 Jan Dubiec <jdx@o2.pl> + + PR target/116363 + * libgcc2.c (__fixunssfDI): Fix SFtype to UDWtype conversion for targets + without LIBGCC2_HAS_DF_MODE defined + +2025-05-27 Jakub Jelinek <jakub@redhat.com> + + * config/t-softfp (softfp_bid_list): Don't guard with + $(enable_decimal_float) == bid. + * soft-fp/bitint.h (__bid_pow10bitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_pow10bitint. + (__dpd_d2bbitint, __dpd_b2dbitint): Declare. + * soft-fp/bitintpow10.c (__dpd_d2bbitint, __dpd_b2dbitint): New + variables. + * soft-fp/fixsdbitint.c (__bid_fixsdbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixsdbitint. + Add DPD support. Fix big-endian support. + * soft-fp/fixddbitint.c (__bid_fixddbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixddbitint. + Add DPD support. Fix big-endian support. + * soft-fp/fixtdbitint.c (__bid_fixtdbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixtdbitint. + Add DPD support. Fix big-endian support. + * soft-fp/fixsdti.c (__bid_fixsdbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixsdbitint. + (__bid_fixsdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to + __dpd_fixsdti. + * soft-fp/fixddti.c (__bid_fixddbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixddbitint. + (__bid_fixddti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to + __dpd_fixddti. + * soft-fp/fixtdti.c (__bid_fixtdbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixtdbitint. + (__bid_fixtdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to + __dpd_fixtdti. + * soft-fp/fixunssdti.c (__bid_fixsdbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixsdbitint. + (__bid_fixunssdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine + to __dpd_fixunssdti. + * soft-fp/fixunsddti.c (__bid_fixddbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixddbitint. + (__bid_fixunsddti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine + to __dpd_fixunsddti. + * soft-fp/fixunstdti.c (__bid_fixtdbitint): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixtdbitint. + (__bid_fixunstdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine + to __dpd_fixunstdti. + * soft-fp/floatbitintsd.c (__bid_floatbitintsd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintsd. + Add DPD support. Avoid calling __builtin_clzll with 0 argument. Fix + big-endian support. + * soft-fp/floatbitintdd.c (__bid_floatbitintdd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintdd. + Add DPD support. Avoid calling __builtin_clzll with 0 argument. Fix + big-endian support. + * soft-fp/floatbitinttd.c (__bid_floatbitinttd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitinttd. + Add DPD support. Avoid calling __builtin_clzll with 0 argument. Fix + big-endian support. + * soft-fp/floattisd.c (__bid_floatbitintsd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintsd. + (__bid_floattisd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to + __dpd_floattisd. + * soft-fp/floattidd.c (__bid_floatbitintdd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintdd. + (__bid_floattidd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to + __dpd_floattidd. + * soft-fp/floattitd.c (__bid_floatbitinttd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitinttd. + (__bid_floattitd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to + __dpd_floattitd. + * soft-fp/floatuntisd.c (__bid_floatbitintsd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintsd. + (__bid_floatuntisd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine + to __dpd_floatuntisd. + * soft-fp/floatuntidd.c (__bid_floatbitintdd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintdd. + (__bid_floatuntidd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine + to __dpd_floatuntidd. + * soft-fp/floatuntitd.c (__bid_floatbitinttd): For + !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitinttd. + (__bid_floatuntitd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine + to __dpd_floatuntitd. + +2025-05-25 LIU Hao <lh_mouse@126.com> + + * config.host: Enable mcf thread model for aarch64-*-mingw*. + * config/i386/t-mingw-mcfgthread: Move to... + * config/mingw/t-mingw-mcfgthread: ...here. + +2025-05-21 Alexandre Oliva <oliva@adacore.com> + + * config/gthr-vxworks-thread.c: Include string.h for memset. + +2025-05-20 Jakub Jelinek <jakub@redhat.com> + + * libgcc-std.ver.in (GCC_14.0.0): Remove bitint related exports + from here. + * config/i386/libgcc-glibc.ver (GCC_14.0.0): Add them here. + * config/i386/libgcc-darwin.ver (GCC_14.0.0): Likewise. + * config/i386/libgcc-sol2.ver (GCC_14.0.0): Likewise. + * config/aarch64/libgcc-softfp.ver (GCC_14.0.0): Likewise. + +2025-05-20 Jakub Jelinek <jakub@redhat.com> + + * libgcc2.c (bitint_reduce_prec): For big endian + __LIBGCC_BITINT_ORDER__ use ++*p and --*p instead of + ++p and --p. + * soft-fp/bitint.h (bitint_reduce_prec): Likewise. + +2025-05-17 Oleg Endo <olegendo@gcc.gnu.org> + + * config/sh/lib1funcs.S (ashiftrt_r4_32): Increase alignment. + (movemem): Force alignment of the mova intruction. + +2025-04-25 Thomas Schwinge <tschwinge@baylibre.com> + + PR target/119853 + PR target/119854 + * config/gcn/crt0.c (_fini_array): Call + '__GCC_offload___cxa_finalize'. + * config/nvptx/gbl-ctors.c (__static_do_global_dtors): Likewise. + +2025-04-19 Jiaxun Yang <jiaxun.yang@flygoat.com> + + PR target/118257 + * config/sh/sfp-machine.h (_FPU_GETCW): Implement with builtin. + (_FPU_SETCW): Likewise. + (FP_EX_ENABLE_SHIFT): Derive from arch spec. + (FP_EX_CAUSE_SHIFT): Likewise. + (FP_RND_MASK): Likewise. + (FP_EX_INVALID): Likewise. + (FP_EX_DIVZERO): Likewise. + (FP_EX_ALL): Likewise. + (FP_EX_OVERFLOW): Likewise. + (FP_EX_UNDERFLOW): Likewise. + (FP_EX_INEXACT): Likewise. + (_FP_DECL_EX): Declear default FCSR value. + (FP_RND_NEAREST): Derive from arch spec. + (FP_RND_ZERO): Likewise. + (FP_INIT_ROUNDMODE): Likewise. + (FP_ROUNDMODE): Likewise. + (FP_TRAPPING_EXCEPTIONS): Likewise. + (FP_HANDLE_EXCEPTIONS): Implement with _FPU_SETCW. + +2025-04-19 Jiaxun Yang <jiaxun.yang@flygoat.com> + + PR target/111814 + * config/sh/sfp-machine.h (_FP_NANFRAC_B): Reverse signaling bit. + (_FP_NANFRAC_H): Likewise. + (_FP_NANFRAC_S): Likewise. + (_FP_NANFRAC_D): Likewise. + (_FP_NANFRAC_Q): Likewise. + (_FP_KEEPNANFRACP): Enable for target. + (_FP_QNANNEGATEDP): Enable for target. + (_FP_CHOOSENAN): Port from MIPS. + +2025-04-14 Thomas Schwinge <tschwinge@baylibre.com> + + PR target/118794 + * config/gcn/unwind-gcn.c (_Unwind_Resume): New. + * config/nvptx/unwind-nvptx.c (_Unwind_Resume): Likewise. + +2025-04-14 Eric Botcazou <ebotcazou@adacore.com> + + PR target/119673 + * config/i386/gthr-win32.h (__GTHREAD_ALWAYS_INLINE): New macro. + (__GTHREAD_INLINE): Likewise. + (__GTHR_W32_InterlockedCompareExchange): Delete. + (__gthread_active_p): Mark as __GTHREAD_INLINE instead of + static inline. + (__gthread_create): Likewise. + (__gthread_join): Likewise. + (__gthread_self): Likewise. + (__gthread_detach): Likewise. + (__gthread_equal): Likewise. + (__gthread_yield): Likewise. + (__gthread_once): Likewise. + (__gthread_key_create): Likewise. + (__gthread_key_delete): Likewise. + (__gthread_getspecific): Likewise. + (__gthread_setspecific): Likewise. + (__gthread_mutex_init_function): Likewise. + (__gthread_mutex_destroy): Likewise. + (__gthread_mutex_lock): Likewise. + (__gthread_mutex_trylock): Likewise. + (__gthread_mutex_timedlock): Likewise. + (__gthread_mutex_unlock): Likewise. + (__gthread_recursive_mutex_trylock): Likewise. + (__gthread_cond_init_function): Likewise. + (__gthread_cond_broadcast): Likewise. + (__gthread_cond_signal): Likewise. + (__gthread_cond_wait): Likewise. + (__gthread_cond_timedwait): Likewise. + (__GTHREAD_WIN32_INLINE): Likewise. + (__GTHREAD_WIN32_COND_INLINE): Likewise. + (__gthread_recursive_mutex_init_function): Likewise. + (__gthread_recursive_mutex_destroy): Likewise. + (__gthread_recursive_mutex_lock): Likewise. + (__gthread_recursive_mutex_unlock): Likewise. + (__gthread_cond_destroy): Likewise. + (__gthread_cond_wait_recursive): Likewise. + +2025-04-08 Thomas Schwinge <tschwinge@baylibre.com> + + * config/gcn/unwind-gcn.c (_Unwind_RaiseException) + (_Unwind_Resume_or_Rethrow): New. + * config/nvptx/unwind-nvptx.c (_Unwind_RaiseException) + (_Unwind_Resume_or_Rethrow): Likewise. + +2025-04-08 Thomas Schwinge <tschwinge@baylibre.com> + + * config/gcn/unwind-gcn.c (_Unwind_DeleteException): New. + * config/nvptx/unwind-nvptx.c (_Unwind_DeleteException): Likewise. + +2025-04-07 Thomas Schwinge <tschwinge@baylibre.com> + + * config/nvptx/alloca.c: New. + * config/nvptx/t-nvptx (LIB2ADD): Add it. + +2025-04-07 Georg-Johann Lay <avr@gjlay.de> + + * config/avr/lib1funcs.S (__mulhisi3, __umulhisi3): Use + __mulhisi3_helper for better performance on AVRrc. + +2025-04-06 Georg-Johann Lay <avr@gjlay.de> + + * config/avr/t-avr (LIB1ASMFUNCS): Add (and remove from + FUNCS_notiny): _mulhisi3, _umulhisi3, _mulqq3, _mulhq3, _muluhq3, + _mulha3, _muluha3 _muluha3_round, _usmuluha3, _ssmulha3, + _divqq3, _udivuqq3, _divqq_helper, _divhq3, _udivuhq3. + _divha3 _udivuha3, _ssneg_2, _ssabs_1, _ssabs_2, + _mask1, _ret, _roundqq3 _rounduqq3, + _round_s2, _round_u2, _round_2_const, _addmask_2. + * config/avr/lib1funcs.S (__umulhisi3, __mulhisi3): Make + work on AVRrc. + * config/avr/lib1funcs-fixed.S: Build 8-bit and 16-bit functions + on AVRrc, too. + 2025-04-05 Georg-Johann Lay <avr@gjlay.de> * config/avr/lib1funcs.S (__umulhisi3) [Have MUL]: Reduce call diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 0719fd0..f0cbcb8 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -87,6 +87,7 @@ CC = @CC@ CFLAGS = @CFLAGS@ RANLIB = @RANLIB@ LN_S = @LN_S@ +WERROR = @WERROR@ PWD_COMMAND = $${PWDCMD-pwd} @@ -193,7 +194,6 @@ AWK = @AWK@ GCC_FOR_TARGET = $(CC) LIPO = @LIPO@ LIPO_FOR_TARGET = $(LIPO) -MACHMODE_H = machmode.h mode-classes.def insn-modes.h NM = @NM@ NM_FOR_TARGET = $(NM) RANLIB_FOR_TARGET = $(RANLIB) @@ -220,7 +220,6 @@ export INSTALL_DATA export LIB1ASMSRC export LIBGCC2_CFLAGS export LIPO_FOR_TARGET -export MACHMODE_H export NM_FOR_TARGET export STRIP_FOR_TARGET export RANLIB_FOR_TARGET @@ -233,7 +232,8 @@ version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER) ifeq ($(decimal_float),yes) ifeq ($(enable_decimal_float),bid) -DECNUMINC = -I$(srcdir)/config/libbid -DENABLE_DECIMAL_BID_FORMAT +DECNUMINC = -I$(srcdir)/config/$(cpu_type) -I$(srcdir)/config/libbid \ + -DENABLE_DECIMAL_BID_FORMAT else DECNUMINC = -I$(srcdir)/../libdecnumber/$(enable_decimal_float) \ -I$(srcdir)/../libdecnumber @@ -298,6 +298,8 @@ override CFLAGS := $(filter-out -fprofile-generate -fprofile-use,$(CFLAGS)) INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \ $(INCLUDES) @set_have_cc_tls@ @set_use_emutls@ +NO_PIE_CFLAGS = @NO_PIE_CFLAGS@ + # Options to use when compiling crtbegin/end. CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \ $(NO_PIE_CFLAGS) -finhibit-size-directive -fno-inline -fno-exceptions \ diff --git a/libgcc/config.host b/libgcc/config.host index 6a88ee5..82ea177 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -141,19 +141,6 @@ lm32*-*-*) ;; loongarch*-*) cpu_type=loongarch - tmake_file="loongarch/t-loongarch" - if test "${libgcc_cv_loongarch_hard_float}" = yes; then - tmake_file="${tmake_file} t-hardfp-sfdf t-hardfp" - else - tmake_file="${tmake_file} t-softfp-sfdf" - fi - if test "${ac_cv_sizeof_long_double}" = 16; then - tmake_file="${tmake_file} loongarch/t-softfp-tf" - fi - if test "${host_address}" = 64; then - tmake_file="${tmake_file} loongarch/t-loongarch64" - fi - tmake_file="${tmake_file} t-softfp" ;; m32r*-*-*) cpu_type=m32r @@ -472,6 +459,9 @@ aarch64-*-mingw*) posix) tmake_thr_file="mingw/t-mingw-pthread" ;; + mcf) + tmake_thr_file="mingw/t-mingw-mcfgthread" + ;; esac tmake_file="${tmake_file} ${cpu_type}/t-no-eh ${tmake_thr_file}" tmake_file="${tmake_file} t-dfprules" @@ -904,7 +894,7 @@ i[34567]86-*-mingw*) tmake_thr_file="mingw/t-mingw-pthread" ;; mcf) - tmake_thr_file="i386/t-mingw-mcfgthread" + tmake_thr_file="mingw/t-mingw-mcfgthread" ;; esac # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h @@ -931,7 +921,7 @@ x86_64-*-mingw*) tmake_thr_file="mingw/t-mingw-pthread" ;; mcf) - tmake_thr_file="i386/t-mingw-mcfgthread" + tmake_thr_file="mingw/t-mingw-mcfgthread" ;; esac # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h @@ -1000,16 +990,22 @@ lm32-*-uclinux*) ;; loongarch*-linux*) extra_parts="$extra_parts crtfastmath.o" - tmake_file="${tmake_file} t-crtfm loongarch/t-crtstuff" - case ${host} in - *) - tmake_file="${tmake_file} t-slibgcc-libgcc" - ;; - esac md_unwind_header=loongarch/linux-unwind.h + tmake_file="${tmake_file} loongarch/t-loongarch t-softfp-sfdf loongarch/t-softfp-tf" + if test "${host_address}" = 64; then + tmake_file="${tmake_file} loongarch/t-loongarch64" + fi + tmake_file="${tmake_file} t-softfp" + tmake_file="${tmake_file} t-crtfm loongarch/t-crtstuff" + tmake_file="${tmake_file} t-slibgcc-libgcc" ;; loongarch*-elf*) extra_parts="$extra_parts crtfastmath.o" + tmake_file="${tmake_file} loongarch/t-loongarch t-softfp-sfdf loongarch/t-softfp-tf" + if test "${host_address}" = 64; then + tmake_file="${tmake_file} loongarch/t-loongarch64" + fi + tmake_file="${tmake_file} t-softfp" tmake_file="${tmake_file} t-crtfm loongarch/t-crtstuff" tmake_file="${tmake_file} t-slibgcc-libgcc" ;; @@ -1394,6 +1390,8 @@ s390x-*-linux*) tmake_file="${tmake_file} s390/t-crtstuff s390/t-linux t-stack s390/t-stack-s390" if test "${host_address}" = 32; then tmake_file="${tmake_file} s390/32/t-floattodi" + else + tmake_file="${tmake_file} s390/t-softfp t-softfp" fi md_unwind_header=s390/linux-unwind.h ;; diff --git a/libgcc/config/aarch64/cpuinfo.c b/libgcc/config/aarch64/cpuinfo.c index dda9dc6..f8c10037 100644 --- a/libgcc/config/aarch64/cpuinfo.c +++ b/libgcc/config/aarch64/cpuinfo.c @@ -27,18 +27,18 @@ #if __has_include(<sys/auxv.h>) #include <sys/auxv.h> -#if __has_include(<sys/ifunc.h>) -#include <sys/ifunc.h> -#else +/* The following struct is ABI-correct description of the 2nd argument for an + ifunc resolver as per SYSVABI spec (see link below). It is safe to extend + it with new fields. The ifunc resolver implementations must always check + the runtime size of the buffer using the value in the _size field. + https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst. */ typedef struct __ifunc_arg_t { unsigned long _size; unsigned long _hwcap; unsigned long _hwcap2; + unsigned long _hwcap3; + unsigned long _hwcap4; } __ifunc_arg_t; -#endif - -#if __has_include(<asm/hwcap.h>) -#include <asm/hwcap.h> /* Architecture features used in Function Multi Versioning. */ struct { @@ -46,196 +46,64 @@ struct { /* As features grows new fields could be added. */ } __aarch64_cpu_features __attribute__((visibility("hidden"), nocommon)); -#ifndef _IFUNC_ARG_HWCAP #define _IFUNC_ARG_HWCAP (1ULL << 62) -#endif -#ifndef AT_HWCAP #define AT_HWCAP 16 -#endif -#ifndef HWCAP_FP -#define HWCAP_FP (1 << 0) -#endif -#ifndef HWCAP_ASIMD -#define HWCAP_ASIMD (1 << 1) -#endif -#ifndef HWCAP_EVTSTRM -#define HWCAP_EVTSTRM (1 << 2) -#endif -#ifndef HWCAP_AES -#define HWCAP_AES (1 << 3) -#endif -#ifndef HWCAP_PMULL -#define HWCAP_PMULL (1 << 4) -#endif -#ifndef HWCAP_SHA1 -#define HWCAP_SHA1 (1 << 5) -#endif -#ifndef HWCAP_SHA2 -#define HWCAP_SHA2 (1 << 6) -#endif -#ifndef HWCAP_CRC32 -#define HWCAP_CRC32 (1 << 7) -#endif -#ifndef HWCAP_ATOMICS -#define HWCAP_ATOMICS (1 << 8) -#endif -#ifndef HWCAP_FPHP -#define HWCAP_FPHP (1 << 9) -#endif -#ifndef HWCAP_ASIMDHP -#define HWCAP_ASIMDHP (1 << 10) -#endif -#ifndef HWCAP_CPUID -#define HWCAP_CPUID (1 << 11) -#endif -#ifndef HWCAP_ASIMDRDM -#define HWCAP_ASIMDRDM (1 << 12) -#endif -#ifndef HWCAP_JSCVT -#define HWCAP_JSCVT (1 << 13) -#endif -#ifndef HWCAP_FCMA -#define HWCAP_FCMA (1 << 14) -#endif -#ifndef HWCAP_LRCPC -#define HWCAP_LRCPC (1 << 15) -#endif -#ifndef HWCAP_DCPOP -#define HWCAP_DCPOP (1 << 16) -#endif -#ifndef HWCAP_SHA3 -#define HWCAP_SHA3 (1 << 17) -#endif -#ifndef HWCAP_SM3 -#define HWCAP_SM3 (1 << 18) -#endif -#ifndef HWCAP_SM4 -#define HWCAP_SM4 (1 << 19) -#endif -#ifndef HWCAP_ASIMDDP -#define HWCAP_ASIMDDP (1 << 20) -#endif -#ifndef HWCAP_SHA512 -#define HWCAP_SHA512 (1 << 21) -#endif -#ifndef HWCAP_SVE -#define HWCAP_SVE (1 << 22) -#endif -#ifndef HWCAP_ASIMDFHM -#define HWCAP_ASIMDFHM (1 << 23) -#endif -#ifndef HWCAP_DIT -#define HWCAP_DIT (1 << 24) -#endif -#ifndef HWCAP_ILRCPC -#define HWCAP_ILRCPC (1 << 26) -#endif -#ifndef HWCAP_FLAGM -#define HWCAP_FLAGM (1 << 27) -#endif -#ifndef HWCAP_SSBS -#define HWCAP_SSBS (1 << 28) -#endif -#ifndef HWCAP_SB -#define HWCAP_SB (1 << 29) -#endif -#ifndef HWCAP_PACA -#define HWCAP_PACA (1 << 30) -#endif -#ifndef HWCAP_PACG -#define HWCAP_PACG (1UL << 31) -#endif - -#ifndef AT_HWCAP2 #define AT_HWCAP2 26 -#endif -#ifndef HWCAP2_DCPODP -#define HWCAP2_DCPODP (1 << 0) -#endif -#ifndef HWCAP2_SVE2 -#define HWCAP2_SVE2 (1 << 1) -#endif -#ifndef HWCAP2_SVEAES -#define HWCAP2_SVEAES (1 << 2) -#endif -#ifndef HWCAP2_SVEPMULL -#define HWCAP2_SVEPMULL (1 << 3) -#endif -#ifndef HWCAP2_SVEBITPERM -#define HWCAP2_SVEBITPERM (1 << 4) -#endif -#ifndef HWCAP2_SVESHA3 -#define HWCAP2_SVESHA3 (1 << 5) -#endif -#ifndef HWCAP2_SVESM4 -#define HWCAP2_SVESM4 (1 << 6) -#endif -#ifndef HWCAP2_FLAGM2 -#define HWCAP2_FLAGM2 (1 << 7) -#endif -#ifndef HWCAP2_FRINT -#define HWCAP2_FRINT (1 << 8) -#endif -#ifndef HWCAP2_SVEI8MM -#define HWCAP2_SVEI8MM (1 << 9) -#endif -#ifndef HWCAP2_SVEF32MM -#define HWCAP2_SVEF32MM (1 << 10) -#endif -#ifndef HWCAP2_SVEF64MM -#define HWCAP2_SVEF64MM (1 << 11) -#endif -#ifndef HWCAP2_SVEBF16 -#define HWCAP2_SVEBF16 (1 << 12) -#endif -#ifndef HWCAP2_I8MM -#define HWCAP2_I8MM (1 << 13) -#endif -#ifndef HWCAP2_BF16 -#define HWCAP2_BF16 (1 << 14) -#endif -#ifndef HWCAP2_DGH -#define HWCAP2_DGH (1 << 15) -#endif -#ifndef HWCAP2_RNG -#define HWCAP2_RNG (1 << 16) -#endif -#ifndef HWCAP2_BTI -#define HWCAP2_BTI (1 << 17) -#endif -#ifndef HWCAP2_MTE -#define HWCAP2_MTE (1 << 18) -#endif -#ifndef HWCAP2_RPRES -#define HWCAP2_RPRES (1 << 21) -#endif -#ifndef HWCAP2_MTE3 -#define HWCAP2_MTE3 (1 << 22) -#endif -#ifndef HWCAP2_SME -#define HWCAP2_SME (1 << 23) -#endif -#ifndef HWCAP2_SME_I16I64 -#define HWCAP2_SME_I16I64 (1 << 24) -#endif -#ifndef HWCAP2_SME_F64F64 -#define HWCAP2_SME_F64F64 (1 << 25) -#endif -#ifndef HWCAP2_WFXT -#define HWCAP2_WFXT (1UL << 31) -#endif -#ifndef HWCAP2_EBF16 -#define HWCAP2_EBF16 (1UL << 32) -#endif -#ifndef HWCAP2_SVE_EBF16 -#define HWCAP2_SVE_EBF16 (1UL << 33) -#endif -#ifndef HWCAP2_SME2 -#define HWCAP2_SME2 (1UL << 37) -#endif -#ifndef HWCAP2_LRCPC3 -#define HWCAP2_LRCPC3 (1UL << 46) -#endif +#define AT_HWCAP3 29 +#define AT_HWCAP4 30 + +#define HWCAP_FP (1 << 0) +#define HWCAP_ASIMD (1 << 1) +#define HWCAP_PMULL (1 << 4) +#define HWCAP_SHA2 (1 << 6) +#define HWCAP_CRC32 (1 << 7) +#define HWCAP_ATOMICS (1 << 8) +#define HWCAP_FPHP (1 << 9) +#define HWCAP_ASIMDHP (1 << 10) +#define HWCAP_ASIMDRDM (1 << 12) +#define HWCAP_JSCVT (1 << 13) +#define HWCAP_FCMA (1 << 14) +#define HWCAP_LRCPC (1 << 15) +#define HWCAP_DCPOP (1 << 16) +#define HWCAP_SHA3 (1 << 17) +#define HWCAP_SM3 (1 << 18) +#define HWCAP_SM4 (1 << 19) +#define HWCAP_ASIMDDP (1 << 20) +#define HWCAP_SVE (1 << 22) +#define HWCAP_ASIMDFHM (1 << 23) +#define HWCAP_DIT (1 << 24) +#define HWCAP_ILRCPC (1 << 26) +#define HWCAP_FLAGM (1 << 27) +#define HWCAP_SSBS (1 << 28) +#define HWCAP_SB (1 << 29) + +#define HWCAP2_DCPODP (1 << 0) +#define HWCAP2_SVE2 (1 << 1) +#define HWCAP2_SVEPMULL (1 << 3) +#define HWCAP2_SVEBITPERM (1 << 4) +#define HWCAP2_SVESHA3 (1 << 5) +#define HWCAP2_SVESM4 (1 << 6) +#define HWCAP2_FLAGM2 (1 << 7) +#define HWCAP2_FRINT (1 << 8) +#define HWCAP2_SVEF32MM (1 << 10) +#define HWCAP2_SVEF64MM (1 << 11) +#define HWCAP2_I8MM (1 << 13) +#define HWCAP2_BF16 (1 << 14) +#define HWCAP2_RNG (1 << 16) +#define HWCAP2_BTI (1 << 17) +#define HWCAP2_MTE (1 << 18) +#define HWCAP2_SME (1 << 23) +#define HWCAP2_SME_I16I64 (1 << 24) +#define HWCAP2_SME_F64F64 (1 << 25) +#define HWCAP2_WFXT (1UL << 31) +#define HWCAP2_CSSC (1UL << 34) +#define HWCAP2_SME2 (1UL << 37) +#define HWCAP2_MOPS (1UL << 43) +#define HWCAP2_LRCPC3 (1UL << 46) + +#define __IFUNC_ARG_SIZE_HWCAP2 (sizeof (unsigned long) * 3) +#define __IFUNC_ARG_SIZE_HWCAP3 (sizeof (unsigned long) * 4) +#define __IFUNC_ARG_SIZE_HWCAP4 (sizeof (unsigned long) * 5) static void __init_cpu_features_constructor (unsigned long hwcap, @@ -247,8 +115,14 @@ __init_cpu_features_constructor (unsigned long hwcap, #define extractBits(val, start, number) \ (val & ((1UL << number) - 1UL) << start) >> start unsigned long hwcap2 = 0; - if (hwcap & _IFUNC_ARG_HWCAP) + if ((hwcap & _IFUNC_ARG_HWCAP) && arg->_size >= __IFUNC_ARG_SIZE_HWCAP2) hwcap2 = arg->_hwcap2; + unsigned long hwcap3 __attribute__ ((unused)) = 0; + if ((hwcap & _IFUNC_ARG_HWCAP) && arg->_size >= __IFUNC_ARG_SIZE_HWCAP3) + hwcap3 = arg->_hwcap3; + unsigned long hwcap4 __attribute__ ((unused)) = 0; + if ((hwcap & _IFUNC_ARG_HWCAP) && arg->_size >= __IFUNC_ARG_SIZE_HWCAP4) + hwcap4 = arg->_hwcap4; if (hwcap & HWCAP_CRC32) setCPUFeature(FEAT_CRC); if (hwcap & HWCAP_PMULL) @@ -269,10 +143,6 @@ __init_cpu_features_constructor (unsigned long hwcap, setCPUFeature(FEAT_DIT); if (hwcap & HWCAP_ASIMDRDM) setCPUFeature(FEAT_RDM); - if (hwcap & HWCAP_AES) - setCPUFeature(FEAT_AES); - if (hwcap & HWCAP_SHA1) - setCPUFeature(FEAT_SHA1); if (hwcap & HWCAP_SHA2) setCPUFeature(FEAT_SHA2); if (hwcap & HWCAP_JSCVT) @@ -282,19 +152,9 @@ __init_cpu_features_constructor (unsigned long hwcap, if (hwcap & HWCAP_SB) setCPUFeature(FEAT_SB); if (hwcap & HWCAP_SSBS) - { - setCPUFeature(FEAT_SSBS); - setCPUFeature(FEAT_SSBS2); - } + setCPUFeature(FEAT_SSBS2); if (hwcap2 & HWCAP2_MTE) - { - setCPUFeature(FEAT_MEMTAG); - setCPUFeature(FEAT_MEMTAG2); - } - if (hwcap2 & HWCAP2_MTE3) - setCPUFeature(FEAT_MEMTAG3); - if (hwcap2 & HWCAP2_SVEAES) - setCPUFeature(FEAT_SVE_AES); + setCPUFeature(FEAT_MEMTAG2); if (hwcap2 & HWCAP2_SVEPMULL) setCPUFeature(FEAT_SVE_PMULL128); if (hwcap2 & HWCAP2_SVEBITPERM) @@ -311,24 +171,14 @@ __init_cpu_features_constructor (unsigned long hwcap, setCPUFeature(FEAT_RNG); if (hwcap2 & HWCAP2_I8MM) setCPUFeature(FEAT_I8MM); - if (hwcap2 & HWCAP2_EBF16) - setCPUFeature(FEAT_EBF16); - if (hwcap2 & HWCAP2_SVE_EBF16) - setCPUFeature(FEAT_SVE_EBF16); - if (hwcap2 & HWCAP2_DGH) - setCPUFeature(FEAT_DGH); if (hwcap2 & HWCAP2_FRINT) setCPUFeature(FEAT_FRINTTS); - if (hwcap2 & HWCAP2_SVEI8MM) - setCPUFeature(FEAT_SVE_I8MM); if (hwcap2 & HWCAP2_SVEF32MM) setCPUFeature(FEAT_SVE_F32MM); if (hwcap2 & HWCAP2_SVEF64MM) setCPUFeature(FEAT_SVE_F64MM); if (hwcap2 & HWCAP2_BTI) setCPUFeature(FEAT_BTI); - if (hwcap2 & HWCAP2_RPRES) - setCPUFeature(FEAT_RPRES); if (hwcap2 & HWCAP2_WFXT) setCPUFeature(FEAT_WFXT); if (hwcap2 & HWCAP2_SME) @@ -339,6 +189,10 @@ __init_cpu_features_constructor (unsigned long hwcap, setCPUFeature(FEAT_SME_I64); if (hwcap2 & HWCAP2_SME_F64F64) setCPUFeature(FEAT_SME_F64); + if (hwcap2 & HWCAP2_MOPS) + setCPUFeature(FEAT_MOPS); + if (hwcap2 & HWCAP2_CSSC) + setCPUFeature(FEAT_CSSC); if (hwcap & HWCAP_FP) { setCPUFeature(FEAT_FP); @@ -355,8 +209,6 @@ __init_cpu_features_constructor (unsigned long hwcap, setCPUFeature(FEAT_RCPC3); if (hwcap2 & HWCAP2_BF16) setCPUFeature(FEAT_BF16); - if (hwcap2 & HWCAP2_SVEBF16) - setCPUFeature(FEAT_SVE_BF16); if (hwcap & HWCAP_SVE) setCPUFeature(FEAT_SVE); if (hwcap2 & HWCAP2_SVE2) @@ -383,20 +235,26 @@ __init_cpu_features(void) { unsigned long hwcap; unsigned long hwcap2; + unsigned long hwcap3; + unsigned long hwcap4; /* CPU features already initialized. */ if (__atomic_load_n (&__aarch64_cpu_features.features, __ATOMIC_RELAXED)) return; - hwcap = getauxval(AT_HWCAP); - hwcap2 = getauxval(AT_HWCAP2); + hwcap = getauxval (AT_HWCAP); + hwcap2 = getauxval (AT_HWCAP2); + hwcap3 = getauxval (AT_HWCAP3); + hwcap4 = getauxval (AT_HWCAP4); + __ifunc_arg_t arg; - arg._size = sizeof(__ifunc_arg_t); + arg._size = sizeof (__ifunc_arg_t); arg._hwcap = hwcap; arg._hwcap2 = hwcap2; - __init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg); + arg._hwcap3 = hwcap3; + arg._hwcap4 = hwcap4; + __init_cpu_features_constructor (hwcap | _IFUNC_ARG_HWCAP, &arg); #undef extractBits #undef getCPUFeature #undef setCPUFeature } -#endif /* __has_include(<asm/hwcap.h>) */ #endif /* __has_include(<sys/auxv.h>) */ diff --git a/libgcc/config/aarch64/libgcc-softfp.ver b/libgcc/config/aarch64/libgcc-softfp.ver index c24466c..3b392c9 100644 --- a/libgcc/config/aarch64/libgcc-softfp.ver +++ b/libgcc/config/aarch64/libgcc-softfp.ver @@ -42,8 +42,14 @@ GCC_13.0.0 { %inherit GCC_14.0.0 GCC_13.0.0 GCC_14.0.0 { + __mulbitint3 + __divmodbitint4 + __fixsfbitint + __fixdfbitint __fixtfbitint __floatbitintbf __floatbitinthf + __floatbitintsf + __floatbitintdf __floatbitinttf } diff --git a/libgcc/config/aarch64/linux-unwind.h b/libgcc/config/aarch64/linux-unwind.h index e41ca6a..f5b73a0 100644 --- a/libgcc/config/aarch64/linux-unwind.h +++ b/libgcc/config/aarch64/linux-unwind.h @@ -27,7 +27,7 @@ #include <signal.h> #include <sys/ucontext.h> - +#include <stdint.h> /* Since insns are always stored LE, on a BE system the opcodes will be loaded byte-reversed. Therefore, define two sets of opcodes, @@ -43,6 +43,22 @@ #define MD_FALLBACK_FRAME_STATE_FOR aarch64_fallback_frame_state +#ifndef FPSIMD_MAGIC +#define FPSIMD_MAGIC 0x46508001 +#endif + +#ifndef TPIDR2_MAGIC +#define TPIDR2_MAGIC 0x54504902 +#endif + +#ifndef ZA_MAGIC +#define ZA_MAGIC 0x54366345 +#endif + +#ifndef EXTRA_MAGIC +#define EXTRA_MAGIC 0x45585401 +#endif + static _Unwind_Reason_Code aarch64_fallback_frame_state (struct _Unwind_Context *context, _Unwind_FrameState * fs) @@ -58,6 +74,21 @@ aarch64_fallback_frame_state (struct _Unwind_Context *context, ucontext_t uc; }; + struct tpidr2_block + { + uint64_t za_save_buffer; + uint16_t num_za_save_slices; + uint8_t reserved[6]; + }; + + struct za_block + { + struct _aarch64_ctx head; + uint16_t vl; + uint16_t reserved[3]; + uint64_t data; + }; + struct rt_sigframe *rt_; _Unwind_Ptr new_cfa; unsigned *pc = context->ra; @@ -103,11 +134,15 @@ aarch64_fallback_frame_state (struct _Unwind_Context *context, field can be used to skip over unrecognized context extensions. The end of the context sequence is marked by a context with magic 0 or size 0. */ + struct tpidr2_block *tpidr2 = 0; + struct za_block *za_ctx = 0; + for (extension_marker = (struct _aarch64_ctx *) &sc->__reserved; extension_marker->magic; extension_marker = (struct _aarch64_ctx *) ((unsigned char *) extension_marker + extension_marker->size)) { + restart: if (extension_marker->magic == FPSIMD_MAGIC) { struct fpsimd_context *ctx = @@ -139,12 +174,83 @@ aarch64_fallback_frame_state (struct _Unwind_Context *context, fs->regs.reg[AARCH64_DWARF_V0 + i].loc.offset = offset; } } + else if (extension_marker->magic == TPIDR2_MAGIC) + { + /* A TPIDR2 context. + + All the casting is to support big-endian ILP32. We could read + directly into TPIDR2 otherwise. */ + struct { struct _aarch64_ctx h; uint64_t tpidr2; } *ctx + = (void *)extension_marker; +#if defined (__ILP32__) + tpidr2 = (struct tpidr2_block *) (uintptr_t) ctx->tpidr2; +#else + tpidr2 = (struct tpidr2_block *) ctx->tpidr2; +#endif + } + else if (extension_marker->magic == ZA_MAGIC) + /* A ZA context. We interpret this later. */ + za_ctx = (void *)extension_marker; + else if (extension_marker->magic == EXTRA_MAGIC) + { + /* Extra context. The ABI guarantees that the next _aarch64_ctx + in the current list will be the zero terminator, so we can simply + switch to the new list and continue from there. The new list is + also zero-terminated. + + As above, the casting is to support big-endian ILP32. */ + struct { struct _aarch64_ctx h; uint64_t next; } *ctx + = (void *)extension_marker; +#if defined (__ILP32__) + extension_marker = (struct _aarch64_ctx *) (uintptr_t) ctx->next; +#else + extension_marker = (struct _aarch64_ctx *) ctx->next; +#endif + goto restart; + } else { /* There is context provided that we do not recognize! */ } } + /* Signal handlers are entered with ZA in the off state (TPIDR2_ELO==0 and + PSTATE.ZA==0). The normal process when transitioning from ZA being + dormant to ZA being off is to commit the lazy save; see the AAPCS64 + for details. However, this is not done when entering a signal handler. + Instead, linux saves the old contents of ZA and TPIDR2_EL0 to the + sigcontext without interpreting them further. + + Therefore, if a signal handler throws an exception to code outside the + signal handler, the unwinder must commit the lazy save after the fact. + Committing a lazy save means: + + (1) Storing the contents of ZA into the buffer provided by TPIDR2_EL0. + (2) Setting TPIDR2_EL0 to zero. + (3) Turning ZA off. + + (2) and (3) have already been done by the call to __libgcc_arm_za_disable. + (1) involves copying data from the ZA sigcontext entry to the + corresponding lazy save buffer. */ + if (tpidr2 && za_ctx && tpidr2->za_save_buffer) + { + /* There is a 16-bit vector length (measured in bytes) at ZA_CTX + 8. + The data itself starts at ZA_CTX + 16. + As above, the casting is to support big-endian ILP32. */ + uint16_t vl = za_ctx->vl; +#if defined (__ILP32__) + void *save_buffer = (void *) (uintptr_t) tpidr2->za_save_buffer; + const void *za_buffer = (void *) (uintptr_t) &za_ctx->data; +#else + void *save_buffer = (void *) tpidr2->za_save_buffer; + const void *za_buffer = (void *) &za_ctx->data; +#endif + uint64_t num_slices = tpidr2->num_za_save_slices; + if (num_slices > vl) + num_slices = vl; + memcpy (save_buffer, za_buffer, num_slices * vl); + } + fs->regs.how[31] = REG_SAVED_OFFSET; fs->regs.reg[31].loc.offset = (_Unwind_Ptr) & (sc->sp) - new_cfa; diff --git a/libgcc/config/aarch64/t-aarch64 b/libgcc/config/aarch64/t-aarch64 index d4c5922..c7d83c7 100644 --- a/libgcc/config/aarch64/t-aarch64 +++ b/libgcc/config/aarch64/t-aarch64 @@ -30,4 +30,4 @@ LIB2ADDEH += \ $(srcdir)/config/aarch64/__arm_za_disable.S SHLIB_MAPFILES += $(srcdir)/config/aarch64/libgcc-sme.ver -LIBGCC2_CFLAGS += -Werror -Wno-prio-ctor-dtor +LIBGCC2_CFLAGS += $(WERROR) -Wno-prio-ctor-dtor diff --git a/libgcc/config/avr/lib1funcs-fixed.S b/libgcc/config/avr/lib1funcs-fixed.S index 278ee1b..4115589 100644 --- a/libgcc/config/avr/lib1funcs-fixed.S +++ b/libgcc/config/avr/lib1funcs-fixed.S @@ -31,14 +31,6 @@ ;; Fixed point library routines for AVR ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#if defined __AVR_TINY__ -#define __zero_reg__ r17 -#define __tmp_reg__ r16 -#else -#define __zero_reg__ r1 -#define __tmp_reg__ r0 -#endif - .section .text.libgcc.fixed, "ax", @progbits #ifndef __AVR_TINY__ @@ -251,6 +243,7 @@ DEFUN __fractsfusa ENDF __fractsfusa #endif /* L_fractsfusa */ +#endif /* ! AVR_TINY */ ;; For multiplication the functions here are called directly from ;; avr-fixed.md instead of using the standard libcall mechanisms. @@ -295,8 +288,14 @@ DEFUN __mulhq3 rol r25 brvs 1f ;; Round +#ifndef __AVR_TINY__ sbrc r23, 7 adiw r24, 1 +#else + lsl r23 + adc r24, __zero_reg__ + adc r25, __zero_reg__ +#endif /* AVR_TINY? */ ret 1: ;; Overflow. TR 18037 requires (-1)^2 not to overflow ldi r24, lo8 (0x7fff) @@ -315,8 +314,14 @@ ENDF __mulhq3 DEFUN __muluhq3 XCALL __umulhisi3 ;; Round +#ifndef __AVR_TINY__ sbrc r23, 7 adiw r24, 1 +#else + lsl r23 + adc r24, __zero_reg__ + adc r25, __zero_reg__ +#endif /* AVR_TINY? */ ret ENDF __muluhq3 #endif /* L_muluhq3 */ @@ -361,8 +366,14 @@ DEFUN __muluha3_round mov r25, r24 mov r24, r23 ;; Round +#ifndef __AVR_TINY__ sbrc r22, 7 adiw r24, 1 +#else + lsl r22 + adc r24, __zero_reg__ + adc r25, __zero_reg__ +#endif /* AVR_TINY? */ ret ENDF __muluha3_round #endif /* L_muluha3_round */ @@ -372,6 +383,8 @@ ENDF __muluha3_round Fixed Multiplication 16.16 x 16.16 *******************************************************/ +#ifndef __AVR_TINY__ + ;; Bits outside the result (below LSB), used in the signed version #define GUARD __tmp_reg__ @@ -679,6 +692,8 @@ ENDF __mulusa3_round #undef GUARD +#endif /* ! AVR_TINY */ + /*********************************************************** Fixed unsigned saturated Multiplication 8.8 x 8.8 ***********************************************************/ @@ -762,8 +777,14 @@ DEFUN __ssmulha3 ;; SS = 0 --> 0x7fff ldi C3, 0x7f ldi C2, 0xff +#ifndef __AVR_TINY__ sbrc SS, 7 adiw C2, 1 +#else + lsl SS + adc C2, __zero_reg__ + adc C3, __zero_reg__ +#endif /* AVR_TINY? */ ret ENDF __ssmulha3 #endif /* L_ssmulha3 */ @@ -778,6 +799,8 @@ ENDF __ssmulha3 Fixed unsigned saturated Multiplication 16.16 x 16.16 ***********************************************************/ +#ifndef __AVR_TINY__ + #define C0 18 #define C1 C0+1 #define C2 C0+2 @@ -883,6 +906,8 @@ ENDF __ssmulsa3 #undef C7 #undef SS +#endif /* ! AVR_TINY */ + /******************************************************* Fractional Division 8 / 8 *******************************************************/ @@ -962,8 +987,8 @@ ENDF __divqq_helper #if defined (L_divhq3) DEFUN __divhq3 - mov r0, r_divdH - eor r0, r_divH + mov __tmp_reg__, r_divdH + eor __tmp_reg__, r_divH sbrs r_divH, 7 rjmp 1f NEG2 r_divL @@ -1027,8 +1052,8 @@ ENDF __udivuha3_common *******************************************************/ #if defined (L_divha3) DEFUN __divha3 - mov r0, r_divdH - eor r0, r_divH + mov __tmp_reg__, r_divdH + eor __tmp_reg__, r_divH sbrs r_divH, 7 rjmp 1f NEG2 r_divL @@ -1040,7 +1065,7 @@ DEFUN __divha3 XCALL __udivuha3 lsr r_quoH ; adjust to 7 fractional bits ror r_quoL - sbrs r0, 7 ; negate result if needed + sbrs __tmp_reg__, 7 ; negate result if needed ret NEG2 r_quoL ret @@ -1069,6 +1094,8 @@ ENDF __udivuha3 Fixed Division 16.16 / 16.16 *******************************************************/ +#ifndef __AVR_TINY__ + #define r_arg1L 24 /* arg1 gets passed already in place */ #define r_arg1H 25 #define r_arg1HL 26 @@ -1171,6 +1198,8 @@ ENDF __udivusa3 #undef r_divHH #undef r_cnt +#endif /* ! AVR_TINY */ + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Saturation, 1 Byte @@ -1206,7 +1235,7 @@ ENDF __ssabs_1 DEFUN __ssneg_2 NEG2 A0 brvc 0f - sbiw A0, 1 + wsubi A0, 1 0: ret ENDF __ssneg_2 #endif /* L_ssneg_2 */ @@ -1228,6 +1257,8 @@ ENDF __ssabs_2 ;; Saturation, 4 Bytes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +#ifndef __AVR_TINY__ + ;; First Argument and Return Register #define A0 22 #define A1 A0+1 @@ -1413,6 +1444,8 @@ ENDF __sssub_8 #undef B6 #undef B7 +#endif /* ! AVR_TINY */ + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Rounding Helpers @@ -1613,6 +1646,8 @@ ENDF __round_u2_const ;; Rounding, 4 Bytes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +#ifndef __AVR_TINY__ + #define A0 18 #define A1 A0 + 1 #define A2 A0 + 2 @@ -1915,6 +1950,7 @@ ENDF __round_x8 #undef RP #undef FBITm1 +#endif /* ! AVR_TINY */ ;; Supply implementations / symbols for the bit-banging functions ;; __builtin_avr_bitsfx and __builtin_avr_fxbits @@ -1923,5 +1959,3 @@ DEFUN __ret ret ENDF __ret #endif /* L_ret */ - -#endif /* if not __AVR_TINY__ */ diff --git a/libgcc/config/avr/lib1funcs.S b/libgcc/config/avr/lib1funcs.S index 0120892..dfe99b1 100644 --- a/libgcc/config/avr/lib1funcs.S +++ b/libgcc/config/avr/lib1funcs.S @@ -395,45 +395,57 @@ ENDF __mulhi3 #if defined (L_umulhisi3) DEFUN __umulhisi3 +#ifdef __AVR_TINY__ + ;; Save callee saved regs. + push B0 + push B1 +#endif /* AVR_TINY */ wmov B0, 24 ;; Zero-extend B clr B2 clr B3 ;; Zero-extend A wmov A2, B2 +#ifdef __AVR_TINY__ + ;; Clear hi16 of the result so we can use __mulsi3_helper. + wmov CC2, B2 + XJMP __mulsi3_helper +#else XJMP __mulsi3 +#endif /* AVR_TINY? */ ENDF __umulhisi3 #endif /* L_umulhisi3 */ #if defined (L_mulhisi3) DEFUN __mulhisi3 +#ifdef __AVR_TINY__ + ;; Save callee saved regs. + push B0 + push B1 +#endif /* AVR_TINY */ wmov B0, 24 ;; Sign-extend B lsl r25 sbc B2, B2 mov B3, B2 -#ifdef __AVR_ERRATA_SKIP_JMP_CALL__ - ;; Sign-extend A - clr A2 - sbrc A1, 7 - com A2 - mov A3, A2 - XJMP __mulsi3 -#else /* no __AVR_ERRATA_SKIP_JMP_CALL__ */ ;; Zero-extend A and __mulsi3 will run at least twice as fast ;; compared to a sign-extended A. clr A2 clr A3 + ;; Clear hi16 of the result so we can use __mulsi3_helper. + wmov CC2, A2 sbrs A1, 7 - XJMP __mulsi3 +#ifdef __AVR_ERRATA_SKIP_JMP_CALL__ + rjmp 1f +#else + XJMP __mulsi3_helper +#endif /* ERRATA_SKIP */ ;; If A < 0 then perform the B * 0xffff.... before the ;; very multiplication by initializing the high part of the ;; result CC with -B. - wmov CC2, A2 sub CC2, B0 sbc CC3, B1 - XJMP __mulsi3_helper -#endif /* __AVR_ERRATA_SKIP_JMP_CALL__ */ +1: XJMP __mulsi3_helper ENDF __mulhisi3 #endif /* L_mulhisi3 */ diff --git a/libgcc/config/avr/libf7/ChangeLog b/libgcc/config/avr/libf7/ChangeLog index 1b8a29a..c6e9cc6 100644 --- a/libgcc/config/avr/libf7/ChangeLog +++ b/libgcc/config/avr/libf7/ChangeLog @@ -1,3 +1,67 @@ +2025-10-09 Georg-Johann Lay <avr@gjlay.de> + + PR target/122222 + * libf7-asm.sx (D_floatsidf, D_floatunsidf): New modules. + * libf7-common.mk (F7_ASM_PARTS): Add D_floatsidf, D_floatunsidf. + (F7F, g_dx): Remove floatunsidf, floatsidf. + * libf7.c (f7_set_s32): Don't alias to f7_floatsidf. + (f7_set_u32): Don't alias to f7_floatunsidf. + * f7-renames.h: Rebuild + * f7-wraps.h: Rebuild. + +2025-10-09 Georg-Johann Lay <avr@gjlay.de> + + PR target/122220 + * libf7-asm.sx (to_integer): Return 0x80... on negative overflow. + +2025-10-09 Georg-Johann Lay <avr@gjlay.de> + + PR target/122210 + * libf7-common.mk (F7_ASM_PARTS): Add D2<fx> modules. + * libf7-asm.sx: Implement the D2<fx> modules. + +2025-10-09 Georg-Johann Lay <avr@gjlay.de> + + PR target/122210 + * libf7-common.mk (F7_ASM_PARTS): Add <fx>2D modules. + * libf7-asm.sx: Implement the <fx>2D modules. + +2025-10-06 Georg-Johann Lay <avr@gjlay.de> + + * libf7-common.mk (F7_ASM_PARTS): Add D_sincos. + * libf7-asm.sx: (D_sincos): New module implements sincos / sincosl. + +2025-10-06 Georg-Johann Lay <avr@gjlay.de> + + PR target/122177 + * libf7-common.mk (m_ddd): Remove: fmin, fmax. + (F7_ASM_PARTS): Add: D_fminfmax. + * libf7-asm.sx (D_fmanfmax): New module. + * f7-wraps.h: Rebuild. + +2025-10-06 Georg-Johann Lay <avr@gjlay.de> + + * libf7-common.mk (g_xdd_cmp): Remove le, lt, ge, gt, ne, eq, unord. + (F7_ASM_PARTS): Add D_cmp, D_eq, D_ne, D_ge, D_gt, D_le, D_lt, D_unord. + * libf7-asm.sx (D_cmp, D_eq, D_ne, D_ge, D_gt, D_le, D_lt, D_unord): + New modules. + * f7-wraps.h: Rebuild. + +2025-05-27 Georg-Johann Lay <avr@gjlay.de> + + PR target/120442 + * libf7-common.mk (LIBF_C_PARTS, m_ddd): Add fdim. + * libf7.h (f7_fdim): New proto. + * libf7.c (f7_fdim): New function. + * f7renames.sh (f7_fdim): Add rename. + * f7-wraps.h: Rebuild + * f7-renames.h: Rebuild + +2025-05-27 Georg-Johann Lay <avr@gjlay.de> + + PR target/120441 + * libf7.c (f7_exp): Limit aa->expo to 10 (not to 9). + 2025-03-22 Georg-Johann Lay <avr@gjlay.de> * t-libf7 (libgcc-objects): Only add objects when building diff --git a/libgcc/config/avr/libf7/f7-renames.h b/libgcc/config/avr/libf7/f7-renames.h index bbe571a..dc09851 100644 --- a/libgcc/config/avr/libf7/f7-renames.h +++ b/libgcc/config/avr/libf7/f7-renames.h @@ -97,6 +97,7 @@ #define f7_acos __f7_acos #define f7_atan __f7_atan #define f7_atan2 __f7_atan2 +#define f7_fdim __f7_fdim #define f7_mul_noround __f7_mul_noround #define f7_sqrt16_round __f7_sqrt16_round #define f7_sqrt16_floor __f7_sqrt16_floor @@ -158,8 +159,6 @@ #define f7_min __f7_min #define f7_max __f7_max #define f7_exp10 __f7_exp10 -#define f7_floatunsidf __f7_floatunsidf -#define f7_floatsidf __f7_floatsidf #define f7_extendsfdf2 __f7_extendsfdf2 #define f7_fixdfsi __f7_fixdfsi #define f7_fixdfdi __f7_fixdfdi diff --git a/libgcc/config/avr/libf7/f7-wraps.h b/libgcc/config/avr/libf7/f7-wraps.h index a455b7d..169957f 100644 --- a/libgcc/config/avr/libf7/f7-wraps.h +++ b/libgcc/config/avr/libf7/f7-wraps.h @@ -79,77 +79,7 @@ _ENDF __divdf3 #endif /* F7MOD_D_div_ */ ;; Functions that usually live in libgcc: __<name>df2 for <name> in: -;; le lt ge gt ne eq unord - -;; bool __ledf2 (double, double) ; le -#ifdef F7MOD_D_le_ -_DEFUN __ledf2 - .global F7_NAME(le_impl) - ldi ZH, hi8(gs(F7_NAME(le_impl))) - ldi ZL, lo8(gs(F7_NAME(le_impl))) - F7jmp call_xdd -_ENDF __ledf2 -#endif /* F7MOD_D_le_ */ - -;; bool __ltdf2 (double, double) ; lt -#ifdef F7MOD_D_lt_ -_DEFUN __ltdf2 - .global F7_NAME(lt_impl) - ldi ZH, hi8(gs(F7_NAME(lt_impl))) - ldi ZL, lo8(gs(F7_NAME(lt_impl))) - F7jmp call_xdd -_ENDF __ltdf2 -#endif /* F7MOD_D_lt_ */ - -;; bool __gedf2 (double, double) ; ge -#ifdef F7MOD_D_ge_ -_DEFUN __gedf2 - .global F7_NAME(ge_impl) - ldi ZH, hi8(gs(F7_NAME(ge_impl))) - ldi ZL, lo8(gs(F7_NAME(ge_impl))) - F7jmp call_xdd -_ENDF __gedf2 -#endif /* F7MOD_D_ge_ */ - -;; bool __gtdf2 (double, double) ; gt -#ifdef F7MOD_D_gt_ -_DEFUN __gtdf2 - .global F7_NAME(gt_impl) - ldi ZH, hi8(gs(F7_NAME(gt_impl))) - ldi ZL, lo8(gs(F7_NAME(gt_impl))) - F7jmp call_xdd -_ENDF __gtdf2 -#endif /* F7MOD_D_gt_ */ - -;; bool __nedf2 (double, double) ; ne -#ifdef F7MOD_D_ne_ -_DEFUN __nedf2 - .global F7_NAME(ne_impl) - ldi ZH, hi8(gs(F7_NAME(ne_impl))) - ldi ZL, lo8(gs(F7_NAME(ne_impl))) - F7jmp call_xdd -_ENDF __nedf2 -#endif /* F7MOD_D_ne_ */ - -;; bool __eqdf2 (double, double) ; eq -#ifdef F7MOD_D_eq_ -_DEFUN __eqdf2 - .global F7_NAME(eq_impl) - ldi ZH, hi8(gs(F7_NAME(eq_impl))) - ldi ZL, lo8(gs(F7_NAME(eq_impl))) - F7jmp call_xdd -_ENDF __eqdf2 -#endif /* F7MOD_D_eq_ */ - -;; bool __unorddf2 (double, double) ; unord -#ifdef F7MOD_D_unord_ -_DEFUN __unorddf2 - .global F7_NAME(unord_impl) - ldi ZH, hi8(gs(F7_NAME(unord_impl))) - ldi ZL, lo8(gs(F7_NAME(unord_impl))) - F7jmp call_xdd -_ENDF __unorddf2 -#endif /* F7MOD_D_unord_ */ +;; (none) ;; Functions that usually live in libgcc: __<name> for <name> in: ;; fixdfsi fixdfdi fixunsdfdi fixunsdfsi truncdfsf2 @@ -205,27 +135,7 @@ _ENDF __truncdfsf2 #endif /* F7MOD_D_truncdfsf2_ */ ;; Functions that usually live in libgcc: __<name> for <name> in: -;; floatunsidf floatsidf extendsfdf2 - -;; double __floatunsidf (type_t) ; floatunsidf -#ifdef F7MOD_D_floatunsidf_ -_DEFUN __floatunsidf - .global F7_NAME(floatunsidf) - ldi ZH, hi8(gs(F7_NAME(floatunsidf))) - ldi ZL, lo8(gs(F7_NAME(floatunsidf))) - F7jmp call_dx -_ENDF __floatunsidf -#endif /* F7MOD_D_floatunsidf_ */ - -;; double __floatsidf (type_t) ; floatsidf -#ifdef F7MOD_D_floatsidf_ -_DEFUN __floatsidf - .global F7_NAME(floatsidf) - ldi ZH, hi8(gs(F7_NAME(floatsidf))) - ldi ZL, lo8(gs(F7_NAME(floatsidf))) - F7jmp call_dx -_ENDF __floatsidf -#endif /* F7MOD_D_floatsidf_ */ +;; extendsfdf2 ;; double __extendsfdf2 (type_t) ; extendsfdf2 #ifdef F7MOD_D_extendsfdf2_ @@ -239,7 +149,7 @@ _ENDF __extendsfdf2 ;; Functions that usually live in libm: Depending on [long] double layout, ;; define <name> and <name>l as weak alias(es) of __<name> for <name> in: -;; pow fmin fmax fmod hypot atan2 +;; pow fmod hypot atan2 fdim ;; double __pow (double, double) #ifdef F7MOD_D_pow_ @@ -253,30 +163,6 @@ _DEFUN __pow _ENDF __pow #endif /* F7MOD_D_pow_ */ -;; double __fmin (double, double) -#ifdef F7MOD_D_fmin_ -_DEFUN __fmin - DALIAS fmin - LALIAS fminl - .global F7_NAME(fmin) - ldi ZH, hi8(gs(F7_NAME(fmin))) - ldi ZL, lo8(gs(F7_NAME(fmin))) - F7jmp call_ddd -_ENDF __fmin -#endif /* F7MOD_D_fmin_ */ - -;; double __fmax (double, double) -#ifdef F7MOD_D_fmax_ -_DEFUN __fmax - DALIAS fmax - LALIAS fmaxl - .global F7_NAME(fmax) - ldi ZH, hi8(gs(F7_NAME(fmax))) - ldi ZL, lo8(gs(F7_NAME(fmax))) - F7jmp call_ddd -_ENDF __fmax -#endif /* F7MOD_D_fmax_ */ - ;; double __fmod (double, double) #ifdef F7MOD_D_fmod_ _DEFUN __fmod @@ -313,6 +199,18 @@ _DEFUN __atan2 _ENDF __atan2 #endif /* F7MOD_D_atan2_ */ +;; double __fdim (double, double) +#ifdef F7MOD_D_fdim_ +_DEFUN __fdim + DALIAS fdim + LALIAS fdiml + .global F7_NAME(fdim) + ldi ZH, hi8(gs(F7_NAME(fdim))) + ldi ZL, lo8(gs(F7_NAME(fdim))) + F7jmp call_ddd +_ENDF __fdim +#endif /* F7MOD_D_fdim_ */ + ;; Functions that usually live in libm: Depending on [long] double layout, ;; define <name> and <name>l as weak alias(es) of __<name> for <name> in: ;; ldexp frexp diff --git a/libgcc/config/avr/libf7/f7renames.sh b/libgcc/config/avr/libf7/f7renames.sh index 7ef251e..4ced423 100755 --- a/libgcc/config/avr/libf7/f7renames.sh +++ b/libgcc/config/avr/libf7/f7renames.sh @@ -35,9 +35,9 @@ EOF c) if [ x${PRE} != xf7_ ]; then - echo " " + echo "" echo "/* Renames for libf7.c, libf7.h. */" - echo " " + echo "" for x in $*; do echo "#define f7_$x ${PRE}$x" done @@ -46,9 +46,9 @@ EOF cst) if [ x${PRE} != xf7_ ]; then - echo " " + echo "" echo "/* Renames for libf7.c, libf7.h. */" - echo " " + echo "" for x in $*; do echo "#define f7_const_${x} ${PRE}const_${x}" echo "#define f7_const_${x}_P ${PRE}const_${x}_P" @@ -58,9 +58,9 @@ EOF asm) if [ x${PRE} != xf7_ ]; then - echo " " + echo "" echo "/* Renames for libf7-asm.sx, f7-wraps.h. */" - echo " " + echo "" for x in $*; do echo "#define f7_${x}_asm ${PRE}${x}_asm" done diff --git a/libgcc/config/avr/libf7/libf7-asm.sx b/libgcc/config/avr/libf7/libf7-asm.sx index a06792d..f390eda 100644 --- a/libgcc/config/avr/libf7/libf7-asm.sx +++ b/libgcc/config/avr/libf7/libf7-asm.sx @@ -618,21 +618,7 @@ DEFUN to_integer .Lsaturate.T: #if F7_HAVE_Inf - brtc .Lset_0x7fff - ;; -Inf => return 1 + INTxx_MIN - mov ZL, Flags - .global __clr_8 - XCALL __clr_8 - ldi C6, 0x80 - - ldi CA+0, 0x01 - - sbrs Mask, 5 - ldi CA+4, 0x01 - - sbrs Mask, 4 - ldi CA+6, 0x01 - ret + brts .Lset_0x8000 .Lset_0x7fff: ;; +Inf => return INTxx_MAX @@ -644,7 +630,7 @@ DEFUN to_integer #endif /* F7_HAVE_Inf */ .Lset_0x8000: - ;; NaN => return INTxx_MIN + ;; NaN or -Inf => return INTxx_MIN .global __clr_8 XCALL __clr_8 ldi C6, 0x80 @@ -1727,6 +1713,321 @@ ENDF class_D #endif /* F7MOD_D_class_ */ +#ifdef F7MOD_D_cmp_ + +#define A0 18 +#define A1 A0 + 1 +#define A2 A0 + 2 +#define A3 A0 + 3 +#define A4 A0 + 4 +#define A5 A0 + 5 +#define A6 A0 + 6 +#define A7 A0 + 7 + +#define B0 10 +#define B1 B0 + 1 +#define B2 B0 + 2 +#define B3 B0 + 3 +#define B4 B0 + 4 +#define B5 B0 + 5 +#define B6 B0 + 6 +#define B7 B0 + 7 + +#define AA5 XH +#define AA6 ZL +#define AA7 ZH + +#define BB0 A0 +#define BB1 A1 +#define BB2 A2 +#define BB3 A3 +#define BB4 A4 +#define BB5 A5 +#define BB6 A6 +#define BB7 A7 + +;;; Helper for __<cmp>df2 and __unorddf2. +;;; T = 1: Comparison is unordered. +;;; T = 0: Comparison is ordered, and Z, N, C, S flags are set according +;;; to compare (double A, double B) as if set by a signed int comparison. +;;; Note that f(+0) = f(-0) = 0. +;;; In any case: +;;; - return R24 = 1. +;;; - return R25.0 = isNaN (A) +;;; - return R25.1 = isNaN (B) +DEFUN D_cmp + rcall D_cmp.map_i64 + bld __tmp_reg__, 0 + push __tmp_reg__ + ;; Save A somewhere else... + wmov AA6, A6 + mov AA5, A5 + push A4 + push A3 + push A2 + push A1 + mov r0, A0 + ;; ... so that we can use D_cmp.map_i64 on B. + wmov BB6, B6 + wmov BB4, B4 + wmov BB2, B2 + wmov BB0, B0 + rcall D_cmp.map_i64 + ;; Run the following code even when B is NaN (T=1) so as to pop the regs. + ;; In the non-NaN case, AA and BB can be compared like int64_t for the + ;; sake of comparing A and B as double. + CP r0, BB0 $ pop r0 + cpc r0, BB1 $ pop r0 + cpc r0, BB2 $ pop r0 + cpc r0, BB3 $ pop r0 + cpc r0, BB4 + cpc AA5, BB5 + cpc AA6, BB6 + cpc AA7, BB7 + pop r25 + ;; R25.0 <=> A is NaN + ;; R25.1 <=> B is NaN + ;; T <=> comparison is unordered + bld r25, 1 + sbrc r25, 0 + set + ldi r24, 1 + ret + +;;; A is NaN: Set T=1. +;;; A is not a NaN: Set T=0, and map double A to int64_t such that +;;; f(A) <cmp> f(B) iff A <cmp> B, i.e. we can treat the result +;;; as int64_t for the matter of double comparison. +;;; Clobbers: XL. +D_cmp.map_i64: + bst A7, 7 + cbr A7, 0x80 + ;; If Inf < |A|, then we have a NaN. + CP __zero_reg__, A0 + cpc __zero_reg__, A1 + cpc __zero_reg__, A2 + cpc __zero_reg__, A3 + cpc __zero_reg__, A4 + cpc __zero_reg__, A5 + ldi XL, lo8(0x7ff0) $ cpc XL, A6 + ldi XL, hi8(0x7ff0) $ cpc XL, A7 + brlo .Lunord + brtc 9f + clt + .global __negdi2 + XJMP __negdi2 +.Lunord: + set +9: ret + +ENDF D_cmp +#endif /* F7MOD_D_cmp_ */ + + +;; bool __ledf2 (double, double); +#ifdef F7MOD_D_le_ +_DEFUN __ledf2 + F7call D_cmp + brts 0f + breq 1f + brlt 1f +0: ldi r24, 0 +1: ret +_ENDF __ledf2 +#endif /* F7MOD_D_le_ */ + +;; bool __ltdf2 (double, double); +#ifdef F7MOD_D_lt_ +_DEFUN __ltdf2 + F7call D_cmp + brts 0f + brlt 1f +0: ldi r24, 0 +1: ret +_ENDF __ltdf2 +#endif /* F7MOD_D_lt_ */ + +;; bool __gedf2 (double, double); +#ifdef F7MOD_D_ge_ +_DEFUN __gedf2 + F7call D_cmp + brts 0f + brge 1f +0: ldi r24, 0 +1: ret +_ENDF __gedf2 +#endif /* F7MOD_D_ge_ */ + +;; bool __gtdf2 (double, double); +#ifdef F7MOD_D_gt_ +_DEFUN __gtdf2 + F7call D_cmp + brts 0f + breq 0f + brge 1f +0: ldi r24, 0 +1: ret +_ENDF __gtdf2 +#endif /* F7MOD_D_gt_ */ + +;; bool __nedf2 (double, double); +#ifdef F7MOD_D_ne_ +_DEFUN __nedf2 + F7call D_cmp + brts 0f + brne 1f +0: ldi r24, 0 +1: ret +_ENDF __nedf2 +#endif /* F7MOD_D_ne_ */ + +;; bool __eqdf2 (double, double); +#ifdef F7MOD_D_eq_ +_DEFUN __eqdf2 + F7call D_cmp + brts 0f + breq 1f +0: ldi r24, 0 +1: ret +_ENDF __eqdf2 +#endif /* F7MOD_D_eq_ */ + +;; bool __unorddf2 (double, double); +#ifdef F7MOD_D_unord_ +_DEFUN __unorddf2 + F7call D_cmp + bld r24, 0 + ret +_ENDF __unorddf2 +#endif /* F7MOD_D_unord_ */ + +#ifdef F7MOD_D_fminfmax_ +_DEFUN __fmin +DALIAS fmin +LALIAS fminl + inc __zero_reg__ + +_LABEL __fmax +DALIAS fmax +LALIAS fmaxl + ;; Push A[]. + push r25 + push r24 + push r23 + push r22 + push r21 + push r20 + push r19 + push r18 + ;; fmin or fmax + push __zero_reg__ + clr __zero_reg__ + + XCALL __gedf2 + + pop __tmp_reg__ + andi r25, 0x3 ; NaNs? + brne .Lnan + ;; No NaNs involved. + eor __tmp_reg__, r24 ; (f == fmin) ^ (A >= B) + brne 1f +2: + ;; Return B since the cases are: + ;; fmax && A < B + ;; fmin && A >= B +#ifdef __AVR_XMEGA__ + in XL, __SP_L__ + in XH, __SP_H__ + adiw XL, 8 + out __SP_L__, XL + out __SP_H__, XH +#else + pop r0 $ pop r0 $ pop r0 $ pop r0 + pop r0 $ pop r0 $ pop r0 $ pop r0 +#endif + wmov r24, r16 + wmov r22, r14 + wmov r20, r12 + wmov r18, r10 + ret +1: + ;; Return A since the cases are: + ;; fmax && A >= B + ;; fmin && A < B + pop r18 + pop r19 + pop r20 + pop r21 + pop r22 + pop r23 + pop r24 + pop r25 + ret + +.Lnan: + ;; There are NaNs. + ;; When only the 1st argument is a NaN, then return the 2nd argument + cpi r25, 0x1 + breq 2b + ;; When the 2nd argument is a NaN, then return the 1st argument. + ;; When both arguments are NaNs, then return NaN (e.g. the 1st argument). + rjmp 1b +_ENDF __fmax +#endif /* F7MOD_D_fminfmax_ */ + + +#ifdef F7MOD_D_sincos_ +;;; void sincos (double R18, double *R16, double *R14); +_DEFUN __sincos +DALIAS sincos +LALIAS sincosl + +#define n_pushed 4 +#define n_frame (2 * F7_SIZEOF) + do_prologue_saves n_pushed, n_frame + ;; Y = FramePointer + 1 + adiw Y, 1 + ;; R16 = frame-arg 1 + wmov r16, Y + ;; The double argument is in R18[]. + XCALL F7_NAME (set_double_impl) + ;; void f7_sincos (f7_t *ss, f7_t *cc, const f7_t *aa) + ;; Note that aa may equal ss or cc. + wmov r20, r16 ; aa + wmov r24, r16 ; ss = FP + 1 + subi r16, lo8(-F7_SIZEOF) + sbci r17, hi8(-F7_SIZEOF) + wmov r22, r16 ; cc = FP + 1 + F7_SIZEOF + XCALL F7_NAME (sincos) + + ;; double R18 = get_double (cc) + wmov r24, r16 + XCALL F7_NAME (get_double) + wmov XL, r14 ; double *pcos + rcall store.r18.X ; *pcos = R18 + + ;; double R18 = get_double (ss) + wmov r24, Y + XCALL F7_NAME (get_double) + ldd XL, Y + n_frame + 3 ; Saved R16 + ldd XH, Y + n_frame + 2 ; Saved R17 + rcall store.r18.X ; *psin = R18 + + do_epilogue_restores n_pushed, n_frame + +store.r18.X: + st X+, r18 + st X+, r19 + st X+, r20 + st X+, r21 + st X+, r22 + st X+, r23 + st X+, r24 + st X+, r25 + ret +_ENDF __sincos +#endif /* F7MOD_D_sincos_ */ + #ifdef F7MOD_call_dd_ ;; Provide double wrappers for functions that operate on f7_t and get f7_t*. @@ -1894,4 +2195,277 @@ _DEFUN __powidf2 _ENDF __powidf2 #endif /* F7MOD_D_powi_ */ + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Fixed-point -> double conversions. + +;;; The double exponent starts at bit 52 since the encoded mantissa has 52 bits. +;;; Note that when X is a multiple of 16, then dex_lo(x) evaluates to 0. +#define DEX16(x) (x) << (52 - 48) +#define dex_lo(x) lo8 (DEX16 (x)) +#define dex_hi(x) hi8 (DEX16 (x)) + +#ifdef F7MOD_usa2D_ +_DEFUN __fractusadf + ;; Convert USI to DF. + XCALL __floatunsidf + ;; The MSB indicates a value of 0. + cpse r25, __zero_reg__ + ;; Divide non-zero values by 2^16 in order to adjust for FBIT = 16. + subi r25, dex_hi (16) + ret +_ENDF __fractusadf +#endif /* F7MOD_usa2D_ */ + +#ifdef F7MOD_sa2D_ +_DEFUN __fractsadf + ;; Convert SI to DF. + XCALL __floatsidf + ;; The MSB indicates a value of 0. + tst r25 + breq 0f + ;; Divide non-zero values by 2^15 in order to adjust for FBIT = 15. + subi r24, dex_lo (15) + sbci r25, dex_hi (15) +0: ret +_ENDF __fractsadf +#endif /* F7MOD_sa2D_ */ + +#ifdef F7MOD_uha2D_ +_DEFUN __fractuhadf + ;; Extend UHA to USA. + clr r22 + mov r23, r24 + mov r24, r25 + clr r25 + XJMP __fractusadf +_ENDF __fractuhadf +#endif /* F7MOD_uha2D_ */ + +#ifdef F7MOD_ha2D_ +_DEFUN __fracthadf + ;; Extend HA to SA. + clr r22 + mov r23, r24 + mov r24, r25 + lsl r25 + sbc r25, r25 + XJMP __fractsadf +_ENDF __fracthadf +#endif /* F7MOD_ha2D_ */ + + +#ifdef F7MOD_usq2D_ +_DEFUN __fractusqdf + ;; Convert USI to DF. + XCALL __floatunsidf + ;; The MSB indicates a value of 0. + cpse r25, __zero_reg__ + ;; Divide non-zero values by 2^32 in order to adjust for FBIT = 32. + subi r25, dex_hi (32) + ret +_ENDF __fractusqdf +#endif /* F7MOD_usq2D_ */ + +#ifdef F7MOD_sq2D_ +_DEFUN __fractsqdf + ;; Convert SI to DF. + XCALL __floatsidf + ;; The MSB indicates a value of 0. + tst r25 + breq 0f + ;; Divide non-zero values by 2^31 in order to adjust for FBIT = 31. + subi r24, dex_lo (31) + sbci r25, dex_hi (31) +0: ret +_ENDF __fractsqdf +#endif /* F7MOD_sq2D_ */ + +#ifdef F7MOD_uqq2D_ +_DEFUN __fractuqqdf + ;; Extend UQQ to UHQ. + mov r25, r24 + clr r24 +_LABEL __fractuhqdf + ;; Extend UHQ to USQ. + clr r23 + clr r22 + XJMP __fractusqdf +_ENDF __fractuqqdf +#endif /* F7MOD_uqq2D_ */ + +#ifdef F7MOD_qq2D_ +_DEFUN __fractqqdf + ;; Extend QQ to HQ. + mov r25, r24 + clr r24 +_LABEL __fracthqdf + ;; Extend HQ to SQ. + clr r23 + clr r22 + XJMP __fractsqdf +_ENDF __fractqqdf +#endif /* F7MOD_qq2D_ */ + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Fixed-point -> double conversions. + +#ifdef F7MOD_D2qq_ +_DEFUN __fractdfqq + ;; Multiply with 2^{24+7} to get a QQ result in r25. + subi r24, dex_lo (-31) + sbci r25, dex_hi (-31) + XCALL __fixdfsi + mov r24, r25 + ret +_ENDF __fractdfqq +#endif /* F7MOD_D2qq_ */ + +#ifdef F7MOD_D2uqq_ +_DEFUN __fractdfuqq + ;; Multiply with 2^{24+8} to get a UQQ result in r25. + subi r25, dex_hi (-32) + XCALL __fixunsdfsi + mov r24, r25 + ret +_ENDF __fractdfuqq +#endif /* F7MOD_D2uqq_ */ + +#ifdef F7MOD_D2ha_ +_DEFUN __fractdfha + ;; Multiply with 2^{16+7} to get a HA result in r25:r24 + subi r24, dex_lo (-23) + sbci r25, dex_hi (-23) + XJMP __fixdfsi +_ENDF __fractdfha +#endif /* F7MOD_D2ha_ */ + +#ifdef F7MOD_D2uha_ +_DEFUN __fractdfuha + ;; Multiply with 2^24 to get a UHA result in r25:r24. + subi r24, dex_lo (-24) + sbci r25, dex_hi (-24) + XJMP __fixunsdfsi +_ENDF __fractdfuha +#endif /* F7MOD_D2uha_ */ + +#ifdef F7MOD_D2hq_ +_DEFUN __fractdfhq + ;; Multiply with 2^{16+15} to get a HQ result in r25:r24 + ;; resp. with 2^31 to get a SQ result in r25:r22. +_LABEL __fractdfsq + subi r24, dex_lo (-31) + sbci r25, dex_hi (-31) + XJMP __fixdfsi +_ENDF __fractdfhq +#endif /* F7MOD_D2hq_ */ + +#ifdef F7MOD_D2uhq_ +_DEFUN __fractdfuhq + ;; Multiply with 2^{16+16} to get a UHQ result in r25:r24 + ;; resp. with 2^32 to get a USQ result in r25:r22. +_LABEL __fractdfusq + subi r25, dex_hi (-32) + XJMP __fixunsdfsi +_ENDF __fractdfuhq +#endif /* F7MOD_D2uhq_ */ + +#ifdef F7MOD_D2sa_ +_DEFUN __fractdfsa + ;; Multiply with 2^15 to get a SA result in r25:r22. + subi r24, dex_lo (-15) + sbci r25, dex_hi (-15) + XJMP __fixdfsi +_ENDF __fractdfsa +#endif /* F7MOD_D2sa_ */ + +#ifdef F7MOD_D2usa_ +_DEFUN __fractdfusa + ;; Multiply with 2^16 to get a USA result in r25:r22. + subi r25, dex_hi (-16) + XJMP __fixunsdfsi +_ENDF __fractdfusa +#endif /* F7MOD_D2usa_ */ + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; [u]int32_t -> double conversions. + +;; double __floatsidf (int32_t); +#ifdef F7MOD_D_floatsidf_ +_DEFUN __floatsidf + bst r25, 7 + brtc 0f + XCALL __negsi2 +0: XJMP __floatunsidf.ge0 +_ENDF __floatsidf +#endif /* F7MOD_D_floatsidf_ */ + +;; double __floatunsidf (uint32_t); +#ifdef F7MOD_D_floatunsidf_ +_DEFUN __floatunsidf + clt +_LABEL __floatunsidf.ge0 + ;; Zero-extend SI at the low end. + clr r18 + clr r19 + wmov r20, r18 + ;; Input is zero? + sbiw r24, 0 + sbci r23, 0 + sbci r22, 0 + breq 9f + ;; No: The double exponent of 0x80000000 is 31 plus a bias of 1023. + ;; Align the SI value such that the MSBit is as R25.4. + ;; For each << we have to subtract 1 from the exponent, and for + ;; each >> we have to add 1. Since we want the MSB in R25.4 and + ;; not in R25.7, the initial exponent must be reduced by 3. + ldi Xl, dex_lo (31 + 1023 - 3) + ldi Xh, dex_hi (31 + 1023 - 3) + ;; Move the MSByte to R25. +1: tst r25 + brne 2f + subi Xl, dex_lo (8) + sbci Xh, dex_hi (8) + mov r25, r24 + mov r24, r23 + mov r23, r22 + clr r22 + rjmp 1b +2: ;; Now we have R25 != 0. + cpi r25, 0x20 + brlo 3f + adiw Xl, DEX16 (1) + lsr r25 + ror r24 + ror r23 + ror r22 + ror r21 + rjmp 2b +3: cpi r25, 0x10 + brsh 4f + sbiw Xl, DEX16 (1) + lsl r22 + rol r23 + rol r24 + rol r25 + rjmp 3b +4: ;; Move the mantissa into place and clear the redundant leading 1. + cbr r25, 0x10 + mov r20, r21 + mov r21, r22 + mov r22, r23 + mov r23, r24 + mov r24, r25 + ;; Insert the biased exponent. + or r24, Xl + mov r25, Xh + ;; Insert the sign. + bld r25, 7 +9: ret +_ENDF __floatunsidf +#endif /* F7MOD_D_floatunsidf_ */ + + #endif /* !AVR_TINY */ diff --git a/libgcc/config/avr/libf7/libf7-common.mk b/libgcc/config/avr/libf7/libf7-common.mk index 5d41107..e2b4740 100644 --- a/libgcc/config/avr/libf7/libf7-common.mk +++ b/libgcc/config/avr/libf7/libf7-common.mk @@ -8,7 +8,7 @@ F7_C_PARTS += set_float get_float get_double set_double set_pdouble F7_C_PARTS += fabs neg fmin fmax minmax truncx trunc floor ceil round lround F7_C_PARTS += horner logx log log10 log2 exp pow10 pow powi F7_C_PARTS += sin cos tan cotan sincos sinh cosh tanh sinhcosh -F7_C_PARTS += asinacos asin acos atan atan2 +F7_C_PARTS += asinacos asin acos atan atan2 fdim F7_C_PARTS += abscmp_msb_ge cmp cmp_abs cmp_unordered F7_C_PARTS += const_1 const_1_2 const_1_3 @@ -22,19 +22,31 @@ F7_ASM_PARTS += addsub_mant_scaled store load F7_ASM_PARTS += to_integer to_unsigned clz normalize_with_carry normalize F7_ASM_PARTS += store_expo sqrt16 sqrt_approx div -F7_ASM_PARTS += D_class D_fma D_powi +F7_ASM_PARTS += D_class D_fma D_powi D_sincos F7_ASM_PARTS += D_isnan D_isinf D_isfinite D_signbit D_copysign D_neg D_fabs +F7_ASM_PARTS += D_cmp D_eq D_ne D_ge D_gt D_le D_lt D_unord D_fminfmax F7_ASM_PARTS += call_dd call_ddd +# Fixed-point -> double conversions +F7_ASM_PARTS += qq2D uqq2D sq2D usq2D +F7_ASM_PARTS += ha2D uha2D sa2D usa2D + +# Double -> fixed-point conversions +F7_ASM_PARTS += D2qq D2uqq D2hq D2uhq +F7_ASM_PARTS += D2ha D2uha D2sa D2usa + +# Integer -> double conversions +F7_ASM_PARTS += D_floatsidf D_floatunsidf + # Stuff that will be wrapped in f7-wraps.h (included by libf7-asm.sx) # and give f7_asm_D_*.o modules. g_ddd += add sub mul div -g_xdd_cmp += le lt ge gt ne eq unord -g_dx += floatunsidf floatsidf extendsfdf2 +g_xdd_cmp += +g_dx += extendsfdf2 g_xd += fixdfsi fixdfdi fixunsdfdi fixunsdfsi truncdfsf2 -m_ddd += pow fmin fmax fmod hypot atan2 +m_ddd += pow fmod hypot atan2 fdim m_ddx += ldexp frexp m_dd += sqrt cbrt exp exp10 pow10 log log10 log2 sin cos tan cotan asin acos atan m_dd += ceil floor trunc round sinh cosh tanh @@ -59,7 +71,7 @@ F7F += lrint ldexp frexp exp logx log log10 log2 F7F += minmax fmax fmin floor ceil round lround trunc truncx F7F += horner pow10 exp10 pow powi F7F += sin cos tan cotan sincos sinh cosh tanh sinhcosh -F7F += asinacos asin acos atan atan2 +F7F += asinacos asin acos atan atan2 fdim F7F += mul_noround sqrt16_round sqrt16_floor F7F += clr_mant_lsbs abscmp_msb_ge lshrdi3 ashldi3 F7F += assert @@ -82,7 +94,7 @@ F7F += set_eps set_1pow2 # Renames for ALIASes without own module. F7F += min max exp10 -F7F += floatunsidf floatsidf extendsfdf2 +F7F += extendsfdf2 F7F += fixdfsi fixdfdi fixunsdfdi fixunsdfsi truncdfsf2 # Renames for f7-const.def. diff --git a/libgcc/config/avr/libf7/libf7.c b/libgcc/config/avr/libf7/libf7.c index a64554c..df738b0 100644 --- a/libgcc/config/avr/libf7/libf7.c +++ b/libgcc/config/avr/libf7/libf7.c @@ -207,7 +207,6 @@ f7_t* f7_set_s32 (f7_t *cc, int32_t i32) cc->flags = flags; return cc; } -ALIAS (f7_set_s32, f7_floatsidf) #endif // F7MOD_set_s32_ @@ -219,7 +218,6 @@ f7_t* f7_set_u32 (f7_t *cc, uint32_t u32) cc->expo = 31; return f7_normalize_asm (cc); } -ALIAS (f7_set_u32, f7_floatunsidf) #endif // F7MOD_set_u32_ @@ -928,6 +926,21 @@ void f7_sub (f7_t *cc, const f7_t *aa, const f7_t *bb) #endif // F7MOD_sub_ +#ifdef F7MOD_fdim_ +F7_WEAK +void f7_fdim (f7_t *cc, const f7_t *aa, const f7_t *bb) +{ + int8_t cmp = f7_cmp_unordered (aa, bb, true /*with_sign*/); + if (cmp == INT8_MIN) + return f7_set_nan (cc); + if (cmp < 0) + return f7_clr (cc); + + f7_sub (cc, aa, bb); +} +#endif // F7MOD_fdim_ + + #ifdef F7MOD_addsub_ static void return_with_sign (f7_t *cc, const f7_t *aa, int8_t c_sign) { @@ -1649,10 +1662,10 @@ void f7_exp (f7_t *cc, const f7_t *aa) return f7_set_nan (cc); /* The maximal exponent of 2 for a double is 1023, hence we may limit - to |A| < 1023 * ln2 ~ 709. We limit to 1024 ~ 1.99 * 2^9 */ + to |A| < 1023 * ln2 ~ 709. We limit to 1024 = 2^10 */ if (f7_class_inf (a_class) - || (f7_class_nonzero (a_class) && aa->expo >= 9)) + || (f7_class_nonzero (a_class) && aa->expo >= 10)) { if (f7_class_sign (a_class)) return f7_clr (cc); diff --git a/libgcc/config/avr/libf7/libf7.h b/libgcc/config/avr/libf7/libf7.h index 8aa91c7..786e141 100644 --- a/libgcc/config/avr/libf7/libf7.h +++ b/libgcc/config/avr/libf7/libf7.h @@ -612,6 +612,7 @@ extern void f7_cos (f7_t*, const f7_t*); extern void f7_tan (f7_t*, const f7_t*); extern void f7_atan (f7_t*, const f7_t*); extern void f7_atan2 (f7_t*, const f7_t*, const f7_t*); +extern void f7_fdim (f7_t*, const f7_t*, const f7_t*); extern void f7_asin (f7_t*, const f7_t*); extern void f7_acos (f7_t*, const f7_t*); extern void f7_tanh (f7_t*, const f7_t*); diff --git a/libgcc/config/avr/t-avr b/libgcc/config/avr/t-avr index b10542c..d181784 100644 --- a/libgcc/config/avr/t-avr +++ b/libgcc/config/avr/t-avr @@ -4,6 +4,7 @@ LIB1ASMFUNCS = \ _mulhi3 \ _mulqihi3 _umulqihi3 \ _mulpsi3 \ + _mulhisi3 _umulhisi3 \ _mulsi3 \ _udivmodqi4 \ _divmodqi4 \ @@ -33,12 +34,23 @@ LIB1ASMFUNCS = \ _popcountsi2 \ _popcountqi2 \ _bswapsi2 \ - _fmul _fmuls _fmulsu + _fmul _fmuls _fmulsu \ + _mulqq3 \ + _mulhq3 _muluhq3 \ + _mulha3 _muluha3 _muluha3_round \ + _usmuluha3 _ssmulha3 \ + _divqq3 _udivuqq3 _divqq_helper \ + _divhq3 _udivuhq3 \ + _divha3 _udivuha3 \ + _ssneg_2 \ + _ssabs_1 _ssabs_2 \ + _mask1 _ret \ + _roundqq3 _rounduqq3 \ + _round_s2 _round_u2 _round_2_const _addmask_2 \ # The below functions either use registers that are not present # in tiny core, or use a different register convention (don't save # callee saved regs, for example) -# _mulhisi3 and variations - clobber R18, R19 # All *di funcs - use regs < R16 or expect args in regs < R20 # _prologue and _epilogue save registers < R16 # _load, __fload and _xload variations - expect lpm and elpm support @@ -46,8 +58,6 @@ LIB1ASMFUNCS = \ FUNCS_notiny = \ _mulsqipsi3 \ - _mulhisi3 \ - _umulhisi3 \ _usmulhisi3 \ _muluhisi3 \ _mulshisi3 \ @@ -81,24 +91,14 @@ FUNCS_notiny += \ _fractsfqq _fractsfuqq \ _fractsfhq _fractsfuhq _fractsfha _fractsfuha \ _fractsfsq _fractsfusq _fractsfsa _fractsfusa \ - _mulqq3 \ - _mulhq3 _muluhq3 \ - _mulha3 _muluha3 _muluha3_round \ _mulsa3 _mulusa3 \ - _usmuluha3 _ssmulha3 \ _usmulusa3 _ssmulsa3 \ - _divqq3 _udivuqq3 _divqq_helper \ - _divhq3 _udivuhq3 \ - _divha3 _udivuha3 \ _divsa3 _udivusa3 \ _clr_8 \ - _ssneg_2 _ssneg_4 _ssneg_8 \ - _ssabs_1 _ssabs_2 _ssabs_4 _ssabs_8 \ + _ssneg_4 _ssneg_8 \ + _ssabs_4 _ssabs_8 \ _ssadd_8 _sssub_8 \ _usadd_8 _ussub_8 \ - _mask1 _ret \ - _roundqq3 _rounduqq3 \ - _round_s2 _round_u2 _round_2_const _addmask_2 \ _round_s4 _round_u4 _round_4_const _addmask_4 \ _round_x8 \ _rounddq3 _roundudq3 \ diff --git a/libgcc/config/gcn/crt0.c b/libgcc/config/gcn/crt0.c index dbd6749..cc23e21 100644 --- a/libgcc/config/gcn/crt0.c +++ b/libgcc/config/gcn/crt0.c @@ -24,6 +24,28 @@ typedef long long size_t; /* Provide an entry point symbol to silence a linker warning. */ void _start() {} + +#define PR119369_fixed 0 + + +/* Host/device compatibility: '__cxa_finalize'. Dummy; if necessary, + overridden via libgomp 'target-cxa-dso-dtor.c'. */ + +#if PR119369_fixed +extern void __GCC_offload___cxa_finalize (void *) __attribute__((weak)); +#else +void __GCC_offload___cxa_finalize (void *) __attribute__((weak)); + +void __attribute__((weak)) +__GCC_offload___cxa_finalize (void *dso_handle __attribute__((unused))) +{ +} +#endif + +/* There are no DSOs; this is the main program. */ +static void * const __dso_handle = 0; + + #ifdef USE_NEWLIB_INITFINI extern void __libc_init_array (void) __attribute__((weak)); @@ -38,6 +60,11 @@ void _init_array() __attribute__((amdgpu_hsa_kernel ())) void _fini_array() { +#if PR119369_fixed + if (__GCC_offload___cxa_finalize) +#endif + __GCC_offload___cxa_finalize (__dso_handle); + __libc_fini_array (); } @@ -70,6 +97,11 @@ void _init_array() __attribute__((amdgpu_hsa_kernel ())) void _fini_array() { +#if PR119369_fixed + if (__GCC_offload___cxa_finalize) +#endif + __GCC_offload___cxa_finalize (__dso_handle); + size_t count; size_t i; diff --git a/libgcc/config/gcn/unwind-gcn.c b/libgcc/config/gcn/unwind-gcn.c index 44657ae..97e22c0 100644 --- a/libgcc/config/gcn/unwind-gcn.c +++ b/libgcc/config/gcn/unwind-gcn.c @@ -25,6 +25,33 @@ #include "unwind.h" _Unwind_Reason_Code +_Unwind_RaiseException(struct _Unwind_Exception *exc __attribute__ ((__unused__))) +{ + __builtin_abort (); + return 0; +} + +void +_Unwind_DeleteException (struct _Unwind_Exception *exc) +{ + if (exc->exception_cleanup) + (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc); +} + +void +_Unwind_Resume (struct _Unwind_Exception *exc __attribute__ ((__unused__))) +{ + __builtin_abort (); +} + +_Unwind_Reason_Code +_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc __attribute__ ((__unused__))) +{ + __builtin_abort (); + return 0; +} + +_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument) { return 0; diff --git a/libgcc/config/gthr-vxworks-thread.c b/libgcc/config/gthr-vxworks-thread.c index 17c60fa..1d630e9 100644 --- a/libgcc/config/gthr-vxworks-thread.c +++ b/libgcc/config/gthr-vxworks-thread.c @@ -29,10 +29,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "gthr.h" +typedef STATUS (* ENTRYPTR) (int); + #if __GTHREADS_CXX0X #include <taskLib.h> #include <stdlib.h> +#include <string.h> #define __TIMESPEC_TO_NSEC(timespec) \ ((long long)timespec.tv_sec * 1000000000 + (long long)timespec.tv_nsec) @@ -188,7 +191,7 @@ __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *mutex, /* Task control block initialization and destruction functions. */ -int +static int __init_gthread_tcb (__gthread_t __tcb) { if (!__tcb) @@ -221,7 +224,7 @@ return_sem_delete: /* Here, we pass a pointer to a tcb to allow calls from cleanup attributes. */ -void +static void __delete_gthread_tcb (__gthread_t* __tcb) { semDelete ((*__tcb)->return_value_available); @@ -255,8 +258,8 @@ __gthread_self (void) return __local_tcb; } -int -__task_wrapper (__gthread_t tcb, FUNCPTR __func, _Vx_usr_arg_t __args) +static int +__task_wrapper (__gthread_t tcb, ENTRYPTR __func, _Vx_usr_arg_t __args) { if (!tcb) return ERROR; @@ -321,7 +324,7 @@ __gthread_create (__gthread_t * __threadid, void *(*__func) (void *), TASK_ID task_id = taskCreate (NULL, priority, options, stacksize, - (FUNCPTR) & __task_wrapper, + (FUNCPTR) (void *) __task_wrapper, (_Vx_usr_arg_t) tcb, (_Vx_usr_arg_t) __func, (_Vx_usr_arg_t) __args, diff --git a/libgcc/config/gthr-vxworks-tls.c b/libgcc/config/gthr-vxworks-tls.c index 8ff9f2f..336d8cb 100644 --- a/libgcc/config/gthr-vxworks-tls.c +++ b/libgcc/config/gthr-vxworks-tls.c @@ -168,7 +168,22 @@ static __gthread_once_t tls_init_guard = __GTHREAD_ONCE_INIT; /* Internal routines. */ -/* The task TCB has just been deleted. Call the destructor +/* The task deletion hooks for TLS handling have different prototypes + for kernel or rtp modes. The RTP variant expects a TCB argument, which, + fortunately, we don't need to use. */ + +#ifdef __RTP__ +#define TLS_DELETE_HOOK_ARG_DECL TASK_ID tcb ATTRIBUTE_UNUSED +#define TLS_DELETE_HOOK_ARG NULL +#else +#define TLS_DELETE_HOOK_ARG_DECL void +#define TLS_DELETE_HOOK_ARG +#endif + +STATUS tls_delete_hook (TLS_DELETE_HOOK_ARG_DECL); + + +/* A task has just been deleted. Call the destructor function for each TLS key that has both a destructor and a non-NULL specific value in this thread. @@ -176,8 +191,8 @@ static __gthread_once_t tls_init_guard = __GTHREAD_ONCE_INIT; count protects us from calling a stale destructor. It does need to read tls_keys.dtor[key] atomically. */ -void -tls_delete_hook (void *tcb ATTRIBUTE_UNUSED) +STATUS +tls_delete_hook (TLS_DELETE_HOOK_ARG_DECL) { struct tls_data *data; __gthread_key_t key; @@ -202,6 +217,8 @@ tls_delete_hook (void *tcb ATTRIBUTE_UNUSED) VX_LEAVE_TLS_DTOR(); VX_SET_TLS_DATA(NULL); } + + return OK; } /* Initialize global data used by the TLS system. */ @@ -217,11 +234,11 @@ tls_destructor (void) { #ifdef __RTP__ /* All threads but this one should have exited by now. */ - tls_delete_hook (NULL); + tls_delete_hook (TLS_DELETE_HOOK_ARG); #endif /* Unregister the hook. */ if (delete_hook_installed) - taskDeleteHookDelete ((FUNCPTR)tls_delete_hook); + taskDeleteHookDelete (tls_delete_hook); if (tls_init_guard.done && __gthread_mutex_lock (&tls_lock) != ERROR) semDelete (tls_lock); @@ -343,7 +360,7 @@ __gthread_setspecific (__gthread_key_t key, void *value) return ENOMEM; if (!delete_hook_installed) { - taskDeleteHookAdd ((FUNCPTR)tls_delete_hook); + taskDeleteHookAdd (tls_delete_hook); delete_hook_installed = 1; } __gthread_mutex_unlock (&tls_lock); diff --git a/libgcc/config/gthr-vxworks.h b/libgcc/config/gthr-vxworks.h index 2f5a2ca..3918790 100644 --- a/libgcc/config/gthr-vxworks.h +++ b/libgcc/config/gthr-vxworks.h @@ -34,6 +34,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #else +/* VxWorks provides its own version of the standard stdatomic.h, possibly + relying on non-gcc builtins, and our implementation of the gthr API resorts + to VxWorks specific functions for atomicity features. + + When compiling libgcc (with gcc), make sure gcc's version of stdatomic.h + is used: #include it here, first, then define the macro used to guard the + system version so it doesn't get expanded when included indirectly by + other system headers. */ +#if defined(IN_LIBGCC2) +#include <../include/stdatomic.h> +#define __INCstdatomich +#endif + #include <vxWorks.h> #include <_vxworks-versions.h> diff --git a/libgcc/config/i386/32/dfp-machine.h b/libgcc/config/i386/32/dfp-machine.h new file mode 100644 index 0000000..9b008ee --- /dev/null +++ b/libgcc/config/i386/32/dfp-machine.h @@ -0,0 +1,31 @@ +#ifndef _SOFT_FLOAT +/* Get the rounding mode. */ +#define DFP_GET_ROUNDMODE \ + unsigned short _frnd_orig; \ + do \ + { \ + __asm__ __volatile__ ("fnstcw\t%0" : "=m" (_frnd_orig)); \ + _frnd_orig &= FP_RND_MASK; \ + } \ + while (0); + +/* Set the rounding mode. */ +#define DFP_SET_ROUNDMODE(round) \ + do \ + { \ + unsigned short _fcw; \ + __asm__ __volatile__ ("fnstcw\t%0" : "=m" (_fcw)); \ + _fcw &= ~FP_RND_MASK; \ + _fcw |= round; \ + __asm__ __volatile__ ("fldcw\t%0" :: "m" (_fcw)); \ + if (__builtin_cpu_supports ("sse")) \ + { \ + unsigned int _xcw; \ + __asm__ __volatile__ ("%vstmxcsr\t%0" : "=m" (_xcw)); \ + _xcw &= ~0x6000; \ + _xcw |= round << 3; \ + __asm__ __volatile__ ("%vldmxcsr\t%0" :: "m" (_xcw)); \ + } \ + } \ + while (0); +#endif diff --git a/libgcc/config/i386/64/dfp-machine.h b/libgcc/config/i386/64/dfp-machine.h new file mode 100644 index 0000000..19cc16a --- /dev/null +++ b/libgcc/config/i386/64/dfp-machine.h @@ -0,0 +1,21 @@ +/* Get the rounding mode. */ +#define DFP_GET_ROUNDMODE \ + unsigned int _frnd_orig; \ + do \ + { \ + __asm__ __volatile__ ("%vstmxcsr\t%0" : "=m" (_frnd_orig)); \ + _frnd_orig &= FP_RND_MASK; \ + } \ + while (0); + +/* Set the rounding mode. */ +#define DFP_SET_ROUNDMODE(round) \ + do \ + { \ + unsigned int _cw; \ + __asm__ __volatile__ ("%vstmxcsr\t%0" : "=m" (_cw)); \ + _cw &= ~FP_RND_MASK; \ + _cw |= round; \ + __asm__ __volatile__ ("%vldmxcsr\t%0" :: "m" (_cw)); \ + } \ + while (0); diff --git a/libgcc/config/i386/dfp-machine.h b/libgcc/config/i386/dfp-machine.h new file mode 100644 index 0000000..f6efacc --- /dev/null +++ b/libgcc/config/i386/dfp-machine.h @@ -0,0 +1,59 @@ +/* Rounding mode macros for DFP libbid. x86 version. + Copyright (C) 2025 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GCC 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 General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _X86_DFP_MACHINE_H +#define _X86_DFP_MACHINE_H + +#ifdef _SOFT_FLOAT +#include_next <dfp-machine.h> +#else +#include "config/i386/sfp-machine.h" + +#ifdef __x86_64__ +#include "config/i386/64/dfp-machine.h" +#else +#include "config/i386/32/dfp-machine.h" +#endif + +/* Initialize the rounding mode to round-to-nearest if needed. */ +#define DFP_INIT_ROUNDMODE \ + DFP_GET_ROUNDMODE; \ + do \ + { \ + if (_frnd_orig != FP_RND_NEAREST) \ + DFP_SET_ROUNDMODE (FP_RND_NEAREST); \ + } \ + while (0); + +/* Restore the rounding mode to round-to-nearest if changed. */ +#define DFP_RESTORE_ROUNDMODE \ + do \ + { \ + if (_frnd_orig != FP_RND_NEAREST) \ + DFP_SET_ROUNDMODE (_frnd_orig); \ + } \ + while (0); +#endif + +#endif /* _X86_DFP_MACHINE_H */ diff --git a/libgcc/config/i386/gthr-win32.h b/libgcc/config/i386/gthr-win32.h index 98e11b4..34988d4 100644 --- a/libgcc/config/i386/gthr-win32.h +++ b/libgcc/config/i386/gthr-win32.h @@ -71,6 +71,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #error Timed lock primitives are not supported on Windows targets #endif +#ifdef __has_attribute +# if __has_attribute(__always_inline__) +# define __GTHREAD_ALWAYS_INLINE __attribute__((__always_inline__)) +# endif +#endif +#ifndef __GTHREAD_ALWAYS_INLINE +# define __GTHREAD_ALWAYS_INLINE +#endif + +#ifdef __cplusplus +# define __GTHREAD_INLINE inline __GTHREAD_ALWAYS_INLINE +#else +# define __GTHREAD_INLINE static inline +#endif + /* Make sure CONST_CAST2 (origin in system.h) is declared. */ #ifndef CONST_CAST2 #ifdef __cplusplus @@ -398,11 +413,7 @@ extern int _CRT_MT; extern int __mingwthr_key_dtor (unsigned long, void (*) (void *)); #endif /* _WIN32 && !__CYGWIN__ */ -/* __GTHR_W32_InterlockedCompareExchange is left over from win95, - which did not support InterlockedCompareExchange. */ -#define __GTHR_W32_InterlockedCompareExchange InterlockedCompareExchange - -static inline int +__GTHREAD_INLINE int __gthread_active_p (void) { #ifdef MINGW32_SUPPORTS_MT_EH @@ -438,20 +449,20 @@ extern int __gthr_win32_cond_timedwait (__gthread_cond_t *, __gthread_mutex_t *, const __gthread_time_t *); #endif -static inline int +__GTHREAD_INLINE int __gthread_create (__gthread_t *__thr, void *(*__func) (void*), void *__args) { return __gthr_win32_create (__thr, __func, __args); } -static inline int +__GTHREAD_INLINE int __gthread_join (__gthread_t __thr, void **__value_ptr) { return __gthr_win32_join (__thr, __value_ptr); } -static inline __gthread_t +__GTHREAD_INLINE __gthread_t __gthread_self (void) { return __gthr_win32_self (); @@ -463,25 +474,25 @@ __gthread_self (void) Only stubs are exposed to avoid polluting the C++ namespace with Win32 API definitions. */ -static inline int +__GTHREAD_INLINE int __gthread_detach (__gthread_t __thr) { return __gthr_win32_detach (__thr); } -static inline int +__GTHREAD_INLINE int __gthread_equal (__gthread_t __thr1, __gthread_t __thr2) { return __gthr_win32_equal (__thr1, __thr2); } -static inline int +__GTHREAD_INLINE int __gthread_yield (void) { return __gthr_win32_yield (); } -static inline int +__GTHREAD_INLINE int __gthread_once (__gthread_once_t *__once, void (*__func) (void)) { if (__gthread_active_p ()) @@ -490,43 +501,43 @@ __gthread_once (__gthread_once_t *__once, void (*__func) (void)) return -1; } -static inline int +__GTHREAD_INLINE int __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *)) { return __gthr_win32_key_create (__key, __dtor); } -static inline int +__GTHREAD_INLINE int __gthread_key_delete (__gthread_key_t __key) { return __gthr_win32_key_delete (__key); } -static inline void * +__GTHREAD_INLINE void * __gthread_getspecific (__gthread_key_t __key) { return __gthr_win32_getspecific (__key); } -static inline int +__GTHREAD_INLINE int __gthread_setspecific (__gthread_key_t __key, const void *__ptr) { return __gthr_win32_setspecific (__key, __ptr); } -static inline void +__GTHREAD_INLINE void __gthread_mutex_init_function (__gthread_mutex_t *__mutex) { __gthr_win32_mutex_init_function (__mutex); } -static inline void +__GTHREAD_INLINE void __gthread_mutex_destroy (__gthread_mutex_t *__mutex) { __gthr_win32_mutex_destroy (__mutex); } -static inline int +__GTHREAD_INLINE int __gthread_mutex_lock (__gthread_mutex_t *__mutex) { if (__gthread_active_p ()) @@ -535,7 +546,7 @@ __gthread_mutex_lock (__gthread_mutex_t *__mutex) return 0; } -static inline int +__GTHREAD_INLINE int __gthread_mutex_trylock (__gthread_mutex_t *__mutex) { if (__gthread_active_p ()) @@ -544,7 +555,7 @@ __gthread_mutex_trylock (__gthread_mutex_t *__mutex) return 0; } -static inline int +__GTHREAD_INLINE int __gthread_mutex_unlock (__gthread_mutex_t *__mutex) { if (__gthread_active_p ()) @@ -553,7 +564,7 @@ __gthread_mutex_unlock (__gthread_mutex_t *__mutex) return 0; } -static inline int +__GTHREAD_INLINE int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) { if (__gthread_active_p ()) @@ -564,31 +575,31 @@ __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) #if __GTHREAD_HAS_COND -static inline void +__GTHREAD_INLINE void __gthread_cond_init_function (__gthread_cond_t *__cond) { __gthr_win32_cond_init_function (__cond); } -static inline int +__GTHREAD_INLINE int __gthread_cond_broadcast (__gthread_cond_t *__cond) { return __gthr_win32_cond_broadcast (__cond); } -static inline int +__GTHREAD_INLINE int __gthread_cond_signal (__gthread_cond_t *__cond) { return __gthr_win32_cond_signal (__cond); } -static inline int +__GTHREAD_INLINE int __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex) { return __gthr_win32_cond_wait (__cond, __mutex); } -static inline int +__GTHREAD_INLINE int __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex, const __gthread_time_t *__abs_time) { @@ -600,11 +611,11 @@ __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex, #else /* ! __GTHREAD_HIDE_WIN32API */ #ifndef __GTHREAD_WIN32_INLINE -#define __GTHREAD_WIN32_INLINE static inline +#define __GTHREAD_WIN32_INLINE __GTHREAD_INLINE #endif #ifndef __GTHREAD_WIN32_COND_INLINE -#define __GTHREAD_WIN32_COND_INLINE static inline +#define __GTHREAD_WIN32_COND_INLINE __GTHREAD_INLINE #endif #ifndef __GTHREAD_WIN32_ACTIVE_P @@ -828,25 +839,25 @@ __gthread_cond_timedwait (__gthread_cond_t *__cond, #endif /* __GTHREAD_HIDE_WIN32API */ -static inline void +__GTHREAD_INLINE void __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex) { __gthread_mutex_init_function (__mutex); } -static inline void +__GTHREAD_INLINE void __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) { __gthread_mutex_destroy (__mutex); } -static inline int +__GTHREAD_INLINE int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex) { return __gthread_mutex_lock (__mutex); } -static inline int +__GTHREAD_INLINE int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) { return __gthread_mutex_unlock (__mutex); @@ -854,13 +865,13 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) #if __GTHREAD_HAS_COND -static inline int +__GTHREAD_INLINE int __gthread_cond_destroy (__gthread_cond_t *__cond ATTRIBUTE_UNUSED) { return 0; } -static inline int +__GTHREAD_INLINE int __gthread_cond_wait_recursive (__gthread_cond_t *__cond, __gthread_recursive_mutex_t *__mutex) { diff --git a/libgcc/config/i386/libgcc-darwin.ver b/libgcc/config/i386/libgcc-darwin.ver index 06560d6..fd609ea 100644 --- a/libgcc/config/i386/libgcc-darwin.ver +++ b/libgcc/config/i386/libgcc-darwin.ver @@ -37,10 +37,16 @@ GCC_14.0.0 { __truncxfbf2 __trunchfbf2 # Added to GCC_14.0.0 in i386/libgcc-glibc.ver. + __mulbitint3 + __divmodbitint4 + __fixsfbitint + __fixdfbitint __fixxfbitint __fixtfbitint __floatbitintbf __floatbitinthf + __floatbitintsf + __floatbitintdf __floatbitintxf __floatbitinttf } diff --git a/libgcc/config/i386/libgcc-glibc.ver b/libgcc/config/i386/libgcc-glibc.ver index e71cc22..9e47b9a 100644 --- a/libgcc/config/i386/libgcc-glibc.ver +++ b/libgcc/config/i386/libgcc-glibc.ver @@ -229,10 +229,16 @@ GCC_13.0.0 { %inherit GCC_14.0.0 GCC_13.0.0 GCC_14.0.0 { + __mulbitint3 + __divmodbitint4 + __fixsfbitint + __fixdfbitint __fixxfbitint __fixtfbitint __floatbitintbf __floatbitinthf + __floatbitintsf + __floatbitintdf __floatbitintxf __floatbitinttf } diff --git a/libgcc/config/i386/libgcc-sol2.ver b/libgcc/config/i386/libgcc-sol2.ver index d2d6265..538bb69 100644 --- a/libgcc/config/i386/libgcc-sol2.ver +++ b/libgcc/config/i386/libgcc-sol2.ver @@ -144,10 +144,16 @@ GCC_14.0.0 { __truncxfbf2 __trunchfbf2 # Added to GCC_14.0.0 in i386/libgcc-glibc.ver. + __mulbitint3 + __divmodbitint4 + __fixsfbitint + __fixdfbitint __fixxfbitint __fixtfbitint __floatbitintbf __floatbitinthf + __floatbitintsf + __floatbitintdf __floatbitintxf __floatbitinttf } diff --git a/libgcc/config/libbid/ChangeLog b/libgcc/config/libbid/ChangeLog index dbdeb4e..031c7a8 100644 --- a/libgcc/config/libbid/ChangeLog +++ b/libgcc/config/libbid/ChangeLog @@ -1,3 +1,49 @@ +2025-10-07 H.J. Lu <hjl.tools@gmail.com> + + PR target/120691 + * bid128_div.c: Run DFP_INIT_ROUNDMODE at function entrace and + DFP_RESTORE_ROUNDMODE at function exit. + * bid128_rem.c: Likewise. + * bid128_sqrt.c: Likewise. + * bid64_div.c (bid64_div): Likewise. + * bid64_sqrt.c (bid64_sqrt): Likewise. + * bid_conf.h: Include <dfp-machine.h>. + * dfp-machine.h: New file. + +2025-08-30 liuhongt <hongtao.liu@intel.com> + + Revert: + 2025-08-29 liuhongt <hongtao.liu@intel.com> + + PR target/120691 + * bid128_div.c: Fix _Decimal128 arithmetic error under + FE_UPWARD. + * bid128_rem.c: Ditto. + * bid128_sqrt.c: Ditto. + * bid64_div.c (bid64_div): Ditto. + * bid64_sqrt.c (bid64_sqrt): Ditto. + +2025-08-29 liuhongt <hongtao.liu@intel.com> + + PR target/120691 + * bid128_div.c: Fix _Decimal128 arithmetic error under + FE_UPWARD. + * bid128_rem.c: Ditto. + * bid128_sqrt.c: Ditto. + * bid64_div.c (bid64_div): Ditto. + * bid64_sqrt.c (bid64_sqrt): Ditto. + +2025-07-15 Andrew Pinski <quic_apinski@quicinc.com> + + * bid_binarydecimal.c (__mul_10x256_to_256): Mark c3 as being + used. + +2025-05-15 liuhongt <hongtao.liu@intel.com> + + * bid128_string.c (MIN_DIGITS): New macro. + (bid128_from_string): Bug fix. Conversion from very long input + string to decimal. + 2024-11-14 Christophe Lyon <christophe.lyon@linaro.org> PR libgcc/117537 diff --git a/libgcc/config/libbid/bid128_div.c b/libgcc/config/libbid/bid128_div.c index 925bf14..f05f9f4 100644 --- a/libgcc/config/libbid/bid128_div.c +++ b/libgcc/config/libbid/bid128_div.c @@ -49,6 +49,9 @@ BID128_FUNCTION_ARG2 (bid128_div, x, y) fexcept_t binaryflags = 0; #endif + // Set the rounding mode to round-to-nearest (if different). + DFP_INIT_ROUNDMODE; + valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y); // unpack arguments, check for NaN or Infinity @@ -62,6 +65,8 @@ if ((x.w[1] & 0x7c00000000000000ull) == 0x7c00000000000000ull) { #endif res.w[1] = (CX.w[1]) & QUIET_MASK64; res.w[0] = CX.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -75,6 +80,8 @@ if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { #endif res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is NaN? @@ -85,6 +92,8 @@ if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { res.w[1] = ((x.w[1] ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -97,6 +106,8 @@ if ((y.w[1] & 0x7800000000000000ull) < 0x7800000000000000ull) { // x=y=0, return NaN res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // return 0 @@ -108,6 +119,8 @@ if ((y.w[1] & 0x7800000000000000ull) < 0x7800000000000000ull) { exponent_x = 0; res.w[1] |= (((UINT64) exponent_x) << 49); res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -122,6 +135,8 @@ if (!valid_y) { #endif res.w[1] = CY.w[1] & QUIET_MASK64; res.w[0] = CY.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is Infinity? @@ -129,6 +144,8 @@ if (!valid_y) { // return +/-0 res.w[1] = sign_x ^ sign_y; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0, return +/-Inf @@ -138,6 +155,8 @@ if (!valid_y) { res.w[1] = ((x.w[1] ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -186,6 +205,8 @@ if (__unsigned_compare_gt_128 (CY, CX)) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // get number of decimal digits in CQ @@ -379,6 +400,8 @@ if (!CA4.w[0] && !CA4.w[1]) #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #endif @@ -469,6 +492,8 @@ if (diff_expon >= 0) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -477,6 +502,8 @@ get_BID128 (&res, sign_x ^ sign_y, diff_expon, CQ, &rnd_mode, pfpsf); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -500,6 +527,9 @@ TYPE0_FUNCTION_ARGTYPE1_ARGTYPE2 (UINT128, bid128dd_div, UINT64, x, fexcept_t binaryflags = 0; #endif + // Set the rounding mode to round-to-nearest (if different). + DFP_INIT_ROUNDMODE; + valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], y); // unpack arguments, check for NaN or Infinity @@ -519,6 +549,8 @@ if ((x & NAN_MASK64) == NAN_MASK64) { res.w[0] = (CX.w[0] & 0x0003ffffffffffffull); __mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]); res.w[1] |= ((CX.w[0]) & 0xfc00000000000000ull); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -532,6 +564,8 @@ if (((x) & 0x7800000000000000ull) == 0x7800000000000000ull) { #endif res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if ((((y) & 0x7c00000000000000ull) != 0x7c00000000000000ull)) { @@ -539,6 +573,8 @@ if (((x) & 0x7800000000000000ull) == 0x7800000000000000ull) { res.w[1] = (((x) ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -551,6 +587,8 @@ if ((((y) & 0x7800000000000000ull) != 0x7800000000000000ull)) { // x=y=0, return NaN res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // return 0 @@ -566,6 +604,8 @@ else if (exponent_x < 0) exponent_x = 0; res.w[1] |= (((UINT64) exponent_x) << 49); res.w[0] = 0; +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -583,6 +623,8 @@ if (!valid_y) { res.w[0] = (CY.w[0] & 0x0003ffffffffffffull); __mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]); res.w[1] |= ((CY.w[0]) & 0xfc00000000000000ull); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is Infinity? @@ -590,6 +632,8 @@ if (!valid_y) { // return +/-0 res.w[1] = sign_x ^ sign_y; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0, return +/-Inf @@ -599,6 +643,8 @@ if (!valid_y) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -647,6 +693,8 @@ if (__unsigned_compare_gt_128 (CY, CX)) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // get number of decimal digits in CQ @@ -843,6 +891,8 @@ __div_256_by_128 (&CQ, &CA4, CY); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #endif @@ -932,6 +982,8 @@ if (diff_expon >= 0) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -940,6 +992,8 @@ get_BID128 (&res, sign_x ^ sign_y, diff_expon, CQ, &rnd_mode, pfpsf); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -959,6 +1013,9 @@ BID128_FUNCTION_ARGTYPE1_ARG128 (bid128dq_div, UINT64, x, y) fexcept_t binaryflags = 0; #endif + // Set the rounding mode to round-to-nearest (if different) + DFP_INIT_ROUNDMODE; + valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y); // unpack arguments, check for NaN or Infinity @@ -978,6 +1035,8 @@ if ((x & NAN_MASK64) == NAN_MASK64) { res.w[0] = (CX.w[0] & 0x0003ffffffffffffull); __mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]); res.w[1] |= ((CX.w[0]) & 0xfc00000000000000ull); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -991,6 +1050,8 @@ if ((x & 0x7800000000000000ull) == 0x7800000000000000ull) { #endif res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) { @@ -998,6 +1059,8 @@ if ((x & 0x7800000000000000ull) == 0x7800000000000000ull) { res.w[1] = ((x ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1010,6 +1073,8 @@ if ((y.w[1] & INFINITY_MASK64) != INFINITY_MASK64) { // x=y=0, return NaN res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // return 0 @@ -1021,6 +1086,8 @@ if ((y.w[1] & INFINITY_MASK64) != INFINITY_MASK64) { exponent_x = 0; res.w[1] |= (((UINT64) exponent_x) << 49); res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1037,6 +1104,8 @@ if (!valid_y) { #endif res.w[1] = CY.w[1] & QUIET_MASK64; res.w[0] = CY.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is Infinity? @@ -1044,6 +1113,8 @@ if (!valid_y) { // return +/-0 res.w[1] = sign_x ^ sign_y; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0, return +/-Inf @@ -1053,6 +1124,8 @@ if (!valid_y) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -1101,6 +1174,8 @@ if (__unsigned_compare_gt_128 (CY, CX)) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // get number of decimal digits in CQ @@ -1300,6 +1375,8 @@ __div_256_by_128 (&CQ, &CA4, CY); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #endif @@ -1389,6 +1466,8 @@ if (diff_expon >= 0) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -1396,6 +1475,8 @@ get_BID128 (&res, sign_x ^ sign_y, diff_expon, CQ, &rnd_mode, pfpsf); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -1415,6 +1496,8 @@ BID128_FUNCTION_ARG128_ARGTYPE2 (bid128qd_div, x, UINT64, y) fexcept_t binaryflags = 0; #endif + // Set the rounding mode to round-to-nearest (if different) + DFP_INIT_ROUNDMODE; valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], y); // unpack arguments, check for NaN or Infinity @@ -1428,6 +1511,8 @@ if ((x.w[1] & 0x7c00000000000000ull) == 0x7c00000000000000ull) { #endif res.w[1] = (CX.w[1]) & QUIET_MASK64; res.w[0] = CX.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -1441,6 +1526,8 @@ if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { #endif res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is NaN? @@ -1451,6 +1538,8 @@ if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { res.w[1] = ((x.w[1] ^ y) & 0x8000000000000000ull) | 0x7800000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1463,6 +1552,8 @@ if ((y & 0x7800000000000000ull) < 0x7800000000000000ull) { // x=y=0, return NaN res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // return 0 @@ -1474,6 +1565,8 @@ if ((y & 0x7800000000000000ull) < 0x7800000000000000ull) { exponent_x = 0; res.w[1] |= (((UINT64) exponent_x) << 49); res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1490,6 +1583,8 @@ if (!valid_y) { res.w[0] = (CY.w[0] & 0x0003ffffffffffffull); __mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]); res.w[1] |= ((CY.w[0]) & 0xfc00000000000000ull); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is Infinity? @@ -1497,6 +1592,8 @@ if (!valid_y) { // return +/-0 res.w[1] = ((x.w[1] ^ y) & 0x8000000000000000ull); res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0 @@ -1505,6 +1602,8 @@ if (!valid_y) { #endif res.w[1] = (sign_x ^ sign_y) | INFINITY_MASK64; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -1553,6 +1652,8 @@ if (__unsigned_compare_gt_128 (CY, CX)) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // get number of decimal digits in CQ @@ -1749,6 +1850,8 @@ __div_256_by_128 (&CQ, &CA4, CY); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #endif @@ -1838,6 +1941,8 @@ if (diff_expon >= 0) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -1846,6 +1951,8 @@ get_BID128 (&res, sign_x ^ sign_y, diff_expon, CQ, &rnd_mode, pfpsf); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } diff --git a/libgcc/config/libbid/bid128_rem.c b/libgcc/config/libbid/bid128_rem.c index f229b28..1c6da70 100644 --- a/libgcc/config/libbid/bid128_rem.c +++ b/libgcc/config/libbid/bid128_rem.c @@ -35,6 +35,9 @@ BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (UINT128, bid128_rem, x, y) int exponent_x, exponent_y, diff_expon, bin_expon_cx, scale, scale0; + // Set the rounding mode to round-to-nearest (if different) + DFP_INIT_ROUNDMODE; + // unpack arguments, check for NaN or Infinity valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y); @@ -52,6 +55,8 @@ if ((x.w[1] & 0x7c00000000000000ull) == 0x7c00000000000000ull) { #endif res.w[1] = CX.w[1] & QUIET_MASK64; res.w[0] = CX.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -66,6 +71,8 @@ if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { #endif res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -79,6 +86,8 @@ if ((!CY.w[1]) && (!CY.w[0])) { // x=y=0, return NaN res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (valid_y || ((y.w[1] & NAN_MASK64) == INFINITY_MASK64)) { @@ -89,6 +98,8 @@ if (valid_y || ((y.w[1] & NAN_MASK64) == INFINITY_MASK64)) { res.w[1] = sign_x | (((UINT64) exponent_x) << 49); res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -103,6 +114,8 @@ if (!valid_y) { #endif res.w[1] = CY.w[1] & QUIET_MASK64; res.w[0] = CY.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is Infinity? @@ -110,6 +123,8 @@ if (!valid_y) { // return x res.w[1] = x.w[1]; res.w[0] = x.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0 @@ -119,6 +134,8 @@ if (!valid_y) { #endif res.w[1] = 0x7c00000000000000ull; res.w[0] = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -130,6 +147,8 @@ if (diff_expon <= 0) { if (diff_expon > 34) { // |x|<|y| in this case res = x; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // set exponent of y to exponent_x, scale coefficient_y @@ -139,6 +158,8 @@ if (diff_expon <= 0) { if (P256.w[2] || P256.w[3]) { // |x|<|y| in this case res = x; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -147,6 +168,8 @@ if (diff_expon <= 0) { if (__unsigned_compare_ge_128 (P256, CX2)) { // |x|<|y| in this case res = x; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -164,6 +187,8 @@ if (diff_expon <= 0) { } get_BID128_very_fast (&res, sign_x, exponent_x, CR); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // 2^64 @@ -200,6 +225,8 @@ while (diff_expon > 0) { // check for remainder == 0 if (!CX.w[1] && !CX.w[0]) { get_BID128_very_fast (&res, sign_x, exponent_y, CX); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -213,5 +240,7 @@ if ((__unsigned_compare_gt_128 (CX2, CY)) } get_BID128_very_fast (&res, sign_x, exponent_y, CX); +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } diff --git a/libgcc/config/libbid/bid128_sqrt.c b/libgcc/config/libbid/bid128_sqrt.c index b280383..71a033f 100644 --- a/libgcc/config/libbid/bid128_sqrt.c +++ b/libgcc/config/libbid/bid128_sqrt.c @@ -43,6 +43,9 @@ BID128_FUNCTION_ARG1 (bid128_sqrt, x) fexcept_t binaryflags = 0; #endif + // Set the rounding mode to round-to-nearest (if different) + DFP_INIT_ROUNDMODE; + // unpack arguments, check for NaN or Infinity if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { res.w[1] = CX.w[1]; @@ -54,6 +57,8 @@ if ((x.w[1] & 0x7c00000000000000ull) == 0x7c00000000000000ull) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif res.w[1] = CX.w[1] & QUIET_MASK64; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -66,6 +71,8 @@ if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif } + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is 0 otherwise @@ -74,6 +81,8 @@ res.w[1] = sign_x | ((((UINT64) (exponent_x + DECIMAL_EXPONENT_BIAS_128)) >> 1) << 49); res.w[0] = 0; +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (sign_x) { @@ -82,6 +91,8 @@ if (sign_x) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -117,6 +128,8 @@ if (CS.w[0] * CS.w[0] == A10.w[0]) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -288,6 +301,8 @@ get_BID128_fast (&res, 0, #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -302,10 +317,14 @@ BID128_FUNCTION_ARGTYPE1 (bid128d_sqrt, UINT64, x) int_float fx, f64; int exponent_x, bin_expon_cx; int digits, scale, exponent_q; + #ifdef UNCHANGED_BINARY_STATUS_FLAGS fexcept_t binaryflags = 0; #endif + // Set the rounding mode to round-to-nearest (if different) + DFP_INIT_ROUNDMODE; + // unpack arguments, check for NaN or Infinity // unpack arguments, check for NaN or Infinity CX.w[1] = 0; @@ -321,6 +340,8 @@ if ((x & 0x7c00000000000000ull) == 0x7c00000000000000ull) { res.w[0] = (CX.w[0] & 0x0003ffffffffffffull); __mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]); res.w[1] |= ((CX.w[0]) & 0xfc00000000000000ull); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -332,6 +353,8 @@ if ((x & 0x7800000000000000ull) == 0x7800000000000000ull) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif } + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is 0 otherwise @@ -342,6 +365,8 @@ res.w[1] = sign_x | ((((UINT64) (exponent_x + DECIMAL_EXPONENT_BIAS_128)) >> 1) << 49); res.w[0] = 0; +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (sign_x) { @@ -350,6 +375,8 @@ if (sign_x) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -387,6 +414,8 @@ if (CS.w[0] * CS.w[0] == A10.w[0]) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -558,6 +587,8 @@ get_BID128_fast (&res, 0, (exponent_q + DECIMAL_EXPONENT_BIAS_128) >> 1, #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); diff --git a/libgcc/config/libbid/bid128_string.c b/libgcc/config/libbid/bid128_string.c index fce036a..49ad179 100644..100755 --- a/libgcc/config/libbid/bid128_string.c +++ b/libgcc/config/libbid/bid128_string.c @@ -31,6 +31,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bid128_2_str.h" #include "bid128_2_str_macros.h" +#define MIN_DIGITS(a,b) ((a) < (b) ? (a) : (b)) + extern int bid128_coeff_2_string (UINT64 X_hi, UINT64 X_lo, char *char_ptr); @@ -283,6 +285,7 @@ bid128_from_string (char *ps _RND_MODE_PARAM _EXC_FLAGS_PARAM int ndigits_before, ndigits_after, ndigits_total, dec_expon, sgn_exp, i, d2, rdx_pt_enc; char c, buffer[MAX_STRING_DIGITS_128]; + int min_digits, sticky_bit=0; int save_rnd_mode; int save_fpsf; @@ -443,8 +446,10 @@ bid128_from_string (char *ps _RND_MODE_PARAM _EXC_FLAGS_PARAM if (!rdx_pt_enc) { // investigate string (before radix point) while ((unsigned) (c - '0') <= 9 - && ndigits_before < MAX_STRING_DIGITS_128) { - buffer[ndigits_before] = c; + /*&& ndigits_before < MAX_STRING_DIGITS_128*/) { + if(ndigits_before < MAX_FORMAT_DIGITS_128) buffer[ndigits_before] = c; + else if(ndigits_before < MAX_STRING_DIGITS_128) { buffer[ndigits_before] = c; } + else if(c>'0') { sticky_bit = 1; } ps++; c = *ps; ndigits_before++; @@ -457,8 +462,10 @@ bid128_from_string (char *ps _RND_MODE_PARAM _EXC_FLAGS_PARAM // investigate string (after radix point) while ((unsigned) (c - '0') <= 9 - && ndigits_total < MAX_STRING_DIGITS_128) { - buffer[ndigits_total] = c; + /*&& ndigits_total < MAX_STRING_DIGITS_128*/) { + if(ndigits_total < MAX_FORMAT_DIGITS_128) buffer[ndigits_total] = c; + else if(ndigits_total < MAX_STRING_DIGITS_128) { buffer[ndigits_total] = c; } + else if(c>'0') { sticky_bit = 1; } ps++; c = *ps; ndigits_total++; @@ -474,8 +481,10 @@ bid128_from_string (char *ps _RND_MODE_PARAM _EXC_FLAGS_PARAM ndigits_total = 0; // investigate string (after radix point) while ((unsigned) (c - '0') <= 9 - && ndigits_total < MAX_STRING_DIGITS_128) { - buffer[ndigits_total] = c; + /*&& ndigits_total < MAX_STRING_DIGITS_128*/) { + if(ndigits_total < MAX_FORMAT_DIGITS_128) buffer[ndigits_total] = c; + else if(ndigits_total < MAX_STRING_DIGITS_128) { buffer[ndigits_total] = c; } + else if(c>'0') { sticky_bit = 1; } ps++; c = *ps; ndigits_total++; @@ -594,57 +603,63 @@ bid128_from_string (char *ps _RND_MODE_PARAM _EXC_FLAGS_PARAM coeff_l2 = coeff_low + coeff_low; coeff_low = (coeff_l2 << 2) + coeff_l2 + buffer[i] - '0'; } - switch(rnd_mode) { - case ROUNDING_TO_NEAREST: - carry = ((unsigned) ('4' - buffer[i])) >> 31; - if ((buffer[i] == '5' && !(coeff_low & 1)) || dec_expon < 0) { - if (dec_expon >= 0) { - carry = 0; - i++; - } - for (; i < ndigits_total; i++) { - if (buffer[i] > '0') { - carry = 1; - break; - } + switch(rnd_mode) { + case ROUNDING_TO_NEAREST: + carry = ((unsigned) ('4' - buffer[i])) >> 31; + if ((buffer[i] == '5' && !(coeff_low & 1) && !sticky_bit) || dec_expon < 0) { + if (dec_expon >= 0) { + carry = 0; + i++; + } + min_digits = MIN_DIGITS(ndigits_total, MAX_STRING_DIGITS_128); + for (carry=sticky_bit; (!carry) && (i < min_digits); i++) { + if (buffer[i] > '0') { + carry = 1; + break; + } + } } - } - break; - - case ROUNDING_DOWN: - if(sign_x) - for (; i < ndigits_total; i++) { - if (buffer[i] > '0') { - carry = 1; - break; - } + break; + + case ROUNDING_DOWN: + if(sign_x) { + min_digits = MIN_DIGITS(ndigits_total, MAX_STRING_DIGITS_128); + for (carry=sticky_bit; (!carry) && (i < min_digits); i++) { + if (buffer[i] > '0') { + carry = 1; + break; + } + } } - break; - case ROUNDING_UP: - if(!sign_x) - for (; i < ndigits_total; i++) { - if (buffer[i] > '0') { - carry = 1; - break; - } + break; + case ROUNDING_UP: + if(!sign_x) { + min_digits = MIN_DIGITS(ndigits_total, MAX_STRING_DIGITS_128); + for (carry=sticky_bit; (!carry) && (i < min_digits); i++) { + if (buffer[i] > '0') { + carry = 1; + break; + } + } } - break; - case ROUNDING_TO_ZERO: - carry=0; - break; - case ROUNDING_TIES_AWAY: - carry = ((unsigned) ('4' - buffer[i])) >> 31; - if (dec_expon < 0) { - for (; i < ndigits_total; i++) { - if (buffer[i] > '0') { - carry = 1; - break; - } + break; + case ROUNDING_TO_ZERO: + carry=0; + break; + case ROUNDING_TIES_AWAY: + carry = ((unsigned) ('4' - buffer[i])) >> 31; + if (dec_expon < 0) { + min_digits = MIN_DIGITS(ndigits_total, MAX_STRING_DIGITS_128); + for (carry=sticky_bit; (!carry) && (i < min_digits); i++) { + if (buffer[i] > '0') { + carry = 1; + break; + } + } } - } - break; - - default: break; // default added to avoid compiler warning + break; + + default: break; // default added to avoid compiler warning } // now form the coefficient as coeff_high*10^17+coeff_low+carry scale_high = 100000000000000000ull; diff --git a/libgcc/config/libbid/bid64_div.c b/libgcc/config/libbid/bid64_div.c index 6975848..5de1a45 100644 --- a/libgcc/config/libbid/bid64_div.c +++ b/libgcc/config/libbid/bid64_div.c @@ -106,6 +106,9 @@ bid64_div (UINT64 x, y = *py; #endif + // Set the rounding mode to round-to-nearest (if different) + DFP_INIT_ROUNDMODE; + valid_x = unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x); valid_y = unpack_BID64 (&sign_y, &exponent_y, &coefficient_y, y); @@ -123,6 +126,8 @@ bid64_div (UINT64 x, if ((x & SNAN_MASK64) == SNAN_MASK64) // sNaN __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (coefficient_x & QUIET_MASK64); } // x is Infinity? @@ -134,9 +139,13 @@ bid64_div (UINT64 x, #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (NAN_MASK64); } } else { + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; // otherwise return +/-Inf BID_RETURN (((x ^ y) & 0x8000000000000000ull) | INFINITY_MASK64); @@ -149,6 +158,8 @@ bid64_div (UINT64 x, #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (NAN_MASK64); } if (((y & INFINITY_MASK64) != INFINITY_MASK64)) { @@ -163,6 +174,8 @@ bid64_div (UINT64 x, exponent_x = DECIMAL_MAX_EXPON_64; else if (exponent_x < 0) exponent_x = 0; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN ((sign_x ^ sign_y) | (((UINT64) exponent_x) << 53)); } @@ -176,10 +189,14 @@ bid64_div (UINT64 x, if ((y & SNAN_MASK64) == SNAN_MASK64) // sNaN __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (coefficient_y & QUIET_MASK64); } // y is Infinity? if ((y & INFINITY_MASK64) == INFINITY_MASK64) { + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; // return +/-0 BID_RETURN (((x ^ y) & 0x8000000000000000ull)); } @@ -187,6 +204,8 @@ bid64_div (UINT64 x, #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN ((sign_x ^ sign_y) | INFINITY_MASK64); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -255,6 +274,8 @@ bid64_div (UINT64 x, #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // get decimal digits of Q @@ -424,6 +445,8 @@ bid64_div (UINT64 x, #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -494,6 +517,8 @@ bid64_div (UINT64 x, #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } else { // UF occurs @@ -510,6 +535,8 @@ bid64_div (UINT64 x, #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -532,6 +559,9 @@ unsigned rmode; fexcept_t binaryflags = 0; #endif +// Set the rounding mode to round-to-nearest (if different) +DFP_INIT_ROUNDMODE; + valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y); // unpack arguments, check for NaN or Infinity @@ -545,6 +575,8 @@ if (!unpack_BID64 (&sign_x, &exponent_x, &CX.w[0], (x))) { // test if x is NaN if (((x) & 0x7c00000000000000ull) == 0x7c00000000000000ull) { res = CX.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res & QUIET_MASK64); } // x is Infinity? @@ -557,12 +589,16 @@ if (!unpack_BID64 (&sign_x, &exponent_x, &CX.w[0], (x))) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif res = 0x7c00000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) { // otherwise return +/-Inf res = (((x) ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -574,6 +610,8 @@ if (!unpack_BID64 (&sign_x, &exponent_x, &CX.w[0], (x))) { #endif // x=y=0, return NaN res = 0x7c00000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // return 0 @@ -584,6 +622,8 @@ if (!unpack_BID64 (&sign_x, &exponent_x, &CX.w[0], (x))) { else if (exponent_x < 0) exponent_x = 0; res |= (((UINT64) exponent_x) << 53); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -604,12 +644,16 @@ if (!valid_y) { amount = recip_scale[18]; __shr_128 (Tmp, Qh, amount); res = (CY.w[1] & 0xfc00000000000000ull) | Tmp.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is Infinity? if ((y.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { // return +/-0 res = sign_x ^ sign_y; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0, return +/-Inf @@ -618,6 +662,8 @@ if (!valid_y) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -680,6 +726,8 @@ if (__unsigned_compare_gt_128 (CY, CX)) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -823,6 +871,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -905,6 +955,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } else { // UF occurs @@ -921,6 +973,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -946,6 +1000,9 @@ unsigned rmode; fexcept_t binaryflags = 0; #endif +// Set the rounding mode to round-to-nearest (if different) +DFP_INIT_ROUNDMODE; + valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], (y)); // unpack arguments, check for NaN or Infinity @@ -964,6 +1021,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { amount = recip_scale[18]; __shr_128 (Tmp, Qh, amount); res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -976,12 +1035,16 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif res = 0x7c00000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (((y & 0x7c00000000000000ull) != 0x7c00000000000000ull)) { // otherwise return +/-Inf res = ((x.w[1] ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -993,6 +1056,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { #endif // x=y=0, return NaN res = 0x7c00000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // return 0 @@ -1002,6 +1067,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif res = 0x7c00000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } exponent_x = @@ -1012,6 +1079,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { else if (exponent_x < 0) exponent_x = 0; res = (sign_x ^ sign_y) | (((UINT64) exponent_x) << 53); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1025,12 +1094,16 @@ if (!valid_y) { if ((y & SNAN_MASK64) == SNAN_MASK64) // sNaN __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (CY.w[0] & QUIET_MASK64); } // y is Infinity? if (((y) & 0x7800000000000000ull) == 0x7800000000000000ull) { // return +/-0 res = sign_x ^ sign_y; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0, return +/-Inf @@ -1039,6 +1112,8 @@ if (!valid_y) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -1103,6 +1178,8 @@ if (__unsigned_compare_gt_128 (CY, CX)) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -1252,6 +1329,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1337,6 +1416,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } else { // UF occurs @@ -1353,6 +1434,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -1383,6 +1466,9 @@ unsigned rmode; fexcept_t binaryflags = 0; #endif +// Set the rounding mode to round-to-nearest (if different) +DFP_INIT_ROUNDMODE; + valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y); // unpack arguments, check for NaN or Infinity @@ -1401,6 +1487,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { amount = recip_scale[18]; __shr_128 (Tmp, Qh, amount); res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -1413,6 +1501,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif res = 0x7c00000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) { @@ -1420,6 +1510,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { res = ((x.w[1] ^ y. w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1431,6 +1523,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { #endif // x=y=0, return NaN res = 0x7c00000000000000ull; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // return 0 @@ -1441,6 +1535,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { else if (exponent_x < 0) exponent_x = 0; res |= (((UINT64) exponent_x) << 53); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1460,12 +1556,16 @@ if (!valid_y) { amount = recip_scale[18]; __shr_128 (Tmp, Qh, amount); res = (CY.w[1] & 0xfc00000000000000ull) | Tmp.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is Infinity? if ((y.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) { // return +/-0 res = sign_x ^ sign_y; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // y is 0, return +/-Inf @@ -1474,6 +1574,8 @@ if (!valid_y) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -1536,6 +1638,8 @@ if (__unsigned_compare_gt_128 (CY, CX)) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -1686,6 +1790,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -1772,6 +1878,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } else { // UF occurs @@ -1788,6 +1896,8 @@ if (!done) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } diff --git a/libgcc/config/libbid/bid64_sqrt.c b/libgcc/config/libbid/bid64_sqrt.c index 29f4cf1..dbd06ea 100644 --- a/libgcc/config/libbid/bid64_sqrt.c +++ b/libgcc/config/libbid/bid64_sqrt.c @@ -73,6 +73,7 @@ bid64_sqrt (UINT64 x _RND_MODE_PARAM _EXC_FLAGS_PARAM int exponent_x, exponent_q, bin_expon_cx; int digits_x; int scale; + #ifdef UNCHANGED_BINARY_STATUS_FLAGS fexcept_t binaryflags = 0; #endif @@ -84,6 +85,9 @@ bid64_sqrt (UINT64 x _RND_MODE_PARAM _EXC_FLAGS_PARAM x = *px; #endif + // Set the rounding mode to round-to-nearest (if different) + DFP_INIT_ROUNDMODE; + // unpack arguments, check for NaN or Infinity if (!unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x)) { // x is Inf. or NaN or 0 @@ -100,11 +104,15 @@ bid64_sqrt (UINT64 x _RND_MODE_PARAM _EXC_FLAGS_PARAM if ((x & SNAN_MASK64) == SNAN_MASK64) // sNaN __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res & QUIET_MASK64); } // x is 0 exponent_x = (exponent_x + DECIMAL_EXPONENT_BIAS) >> 1; res = sign_x | (((UINT64) exponent_x) << 53); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x<0? @@ -113,6 +121,8 @@ bid64_sqrt (UINT64 x _RND_MODE_PARAM _EXC_FLAGS_PARAM #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -141,6 +151,8 @@ bid64_sqrt (UINT64 x _RND_MODE_PARAM _EXC_FLAGS_PARAM #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // if exponent is odd, scale coefficient by 10 @@ -206,6 +218,8 @@ bid64_sqrt (UINT64 x _RND_MODE_PARAM _EXC_FLAGS_PARAM #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } @@ -224,6 +238,9 @@ int digits, scale, exponent_q = 0, exact = 1, amount, extra_digits; fexcept_t binaryflags = 0; #endif +// Set the rounding mode to round-to-nearest (if different) +DFP_INIT_ROUNDMODE; + // unpack arguments, check for NaN or Infinity if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { res = CX.w[1]; @@ -240,6 +257,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { amount = recip_scale[18]; __shr_128 (Tmp, Qh, amount); res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0]; + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is Infinity? @@ -251,6 +270,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif } + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } // x is 0 otherwise @@ -264,6 +285,8 @@ if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) { exponent_x = DECIMAL_MAX_EXPON_64; //res= sign_x | (((UINT64)exponent_x)<<53); res = get_BID64 (sign_x, exponent_x, 0, rnd_mode, pfpsf); + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } if (sign_x) { @@ -271,6 +294,8 @@ if (sign_x) { #ifdef SET_STATUS_FLAGS __set_status_flags (pfpsf, INVALID_EXCEPTION); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } #ifdef UNCHANGED_BINARY_STATUS_FLAGS @@ -312,6 +337,8 @@ if (CS.w[0] < 10000000000000000ull) { #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif + // restore the rounding mode back if it has been changed + DFP_RESTORE_ROUNDMODE; BID_RETURN (res); } } @@ -546,6 +573,8 @@ res = get_BID64 (0, exponent_q, CS.w[0], rnd_mode, pfpsf); #ifdef UNCHANGED_BINARY_STATUS_FLAGS (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS); #endif +// restore the rounding mode back if it has been changed +DFP_RESTORE_ROUNDMODE; BID_RETURN (res); diff --git a/libgcc/config/libbid/bid_binarydecimal.c b/libgcc/config/libbid/bid_binarydecimal.c index daca2ff..12e32b9 100644 --- a/libgcc/config/libbid/bid_binarydecimal.c +++ b/libgcc/config/libbid/bid_binarydecimal.c @@ -132,6 +132,7 @@ UINT64 CY; \ __mul_10x64(p1,c1,a1,c0); \ __mul_10x64(p2,c2,a2,c1); \ __mul_10x64(p3,c3,a3,c2); \ + (void)c3; \ } // Set up indices for low and high parts, depending on the endian-ness. diff --git a/libgcc/config/libbid/bid_conf.h b/libgcc/config/libbid/bid_conf.h index 0f39d58..56f2b34 100644 --- a/libgcc/config/libbid/bid_conf.h +++ b/libgcc/config/libbid/bid_conf.h @@ -559,6 +559,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif // #define HPUX_OS +#include <dfp-machine.h> + // If DECIMAL_CALL_BY_REFERENCE is defined then numerical arguments and results // are passed by reference otherwise they are passed by value (except that // a pointer is always passed to the status flags) diff --git a/libgcc/config/libbid/dfp-machine.h b/libgcc/config/libbid/dfp-machine.h new file mode 100644 index 0000000..ae96115 --- /dev/null +++ b/libgcc/config/libbid/dfp-machine.h @@ -0,0 +1,34 @@ +/* Rounding mode macros for DFP libbid. Dummy version. + Copyright (C) 2025 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GCC 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 General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _DFP_MACHINE_H +#define _DFP_MACHINE_H + +/* Initialize the rounding mode to round-to-nearest if needed. */ +#define DFP_INIT_ROUNDMODE + +/* Restore the rounding mode to round-to-nearest if changed. */ +#define DFP_RESTORE_ROUNDMODE + +#endif /* _DFP_MACHINE_H */ diff --git a/libgcc/config/loongarch/cpuinfo.c b/libgcc/config/loongarch/cpuinfo.c new file mode 100644 index 0000000..a398bcb --- /dev/null +++ b/libgcc/config/loongarch/cpuinfo.c @@ -0,0 +1,101 @@ +/* CPU feature detection for LoongArch architecture. + Copyright (C) 2025 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC 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 General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#include "common/config/loongarch/cpu-features.h" + +#if __has_include(<sys/auxv.h>) +#include <sys/auxv.h> + +#define CPUCFG1_LA64 2ULL << 0 +#define CPUCFG1_UAL 1ULL << 20 +#define CPUCFG2_LSX 1ULL << 6 +#define CPUCFG2_LASX 1ULL << 7 +#define CPUCFG2_FRECIPE 1ULL << 25 +#define CPUCFG2_DIV32 1ULL << 26 +#define CPUCFG2_LAM_BH 1ULL << 27 +#define CPUCFG2_LAMCAS 1ULL << 28 +#define CPUCFG2_SCQ 1ULL << 30 +#define CPUCFG3_LD_SEQ_SA 1ULL << 23 + +struct { + loongarch_fmv_feature_mask features; +} __loongarch_feature_bits __attribute__ ((visibility ("hidden"), nocommon)); + +void __init_loongarch_features_resolver (void); +void +__init_loongarch_features_resolver (void) +{ + if (__atomic_load_n (&__loongarch_feature_bits.features, __ATOMIC_RELAXED)) + return; + + loongarch_fmv_feature_mask feat = 0ULL; +#define setCPUFeature(F) feat |= 1ULL << F; + unsigned int CPUCFG1 = __builtin_loongarch_cpucfg (1); + unsigned int CPUCFG2 = __builtin_loongarch_cpucfg (2); + unsigned int CPUCFG3 = __builtin_loongarch_cpucfg (3); + unsigned long hwcap = getauxval (AT_HWCAP); + + if (CPUCFG1 & CPUCFG1_LA64) + setCPUFeature (FEAT_LA64); + if (CPUCFG1 & CPUCFG1_UAL) + setCPUFeature (FEAT_UAL); + if (CPUCFG2 & CPUCFG2_FRECIPE) + setCPUFeature (FEAT_FRECIPE); + if (CPUCFG2 & CPUCFG2_DIV32) + setCPUFeature (FEAT_DIV32); + if (CPUCFG2 & CPUCFG2_LAM_BH) + setCPUFeature (FEAT_LAM_BH); + if (CPUCFG2 & CPUCFG2_LAMCAS) + setCPUFeature (FEAT_LAMCAS); + if (CPUCFG2 & CPUCFG2_SCQ) + setCPUFeature (FEAT_SCQ); + if (CPUCFG3 & CPUCFG3_LD_SEQ_SA) + setCPUFeature (FEAT_LD_SEQ_SA); + +/* The macros HWCAP_LOONGARCH_LSX and HWCAP_LOONGARCH_LASX are not defined + in glibc versions earlier than 2.38. If these two macros are not defined, + define them with reference to asm/hwcap.h. */ +#ifndef HWCAP_LOONGARCH_LSX +#define HWCAP_LOONGARCH_LSX (1 << 4) +#endif + +#ifndef HWCAP_LOONGARCH_LASX +#define HWCAP_LOONGARCH_LASX (1 << 5) +#endif + + /* LSX and LASX can be disabled/enabled by kernel: on some old kernel + versions the vector context switch wasn't implemented and so they are + always disabled, and on Linux >= 6.18-rc1 the user can pass simd= + parameter via kernel cmdline to disable LSX or LASX for debug or + powersave purpose: + https://git.kernel.org/torvalds/c/5dcddd268a8d + Thus for LSX and LASX HWCAP must be used.*/ + if (hwcap & HWCAP_LOONGARCH_LSX) + setCPUFeature (FEAT_LSX); + if (hwcap & HWCAP_LOONGARCH_LASX) + setCPUFeature (FEAT_LASX); +#undef setCPUFeature + __atomic_store_n (&__loongarch_feature_bits.features, feat, __ATOMIC_RELAXED); +} +#endif /* __has_include(<sys/auxv.h>) */ diff --git a/libgcc/config/loongarch/libgcc-loongarch.ver b/libgcc/config/loongarch/libgcc-loongarch.ver new file mode 100644 index 0000000..0a71f2e --- /dev/null +++ b/libgcc/config/loongarch/libgcc-loongarch.ver @@ -0,0 +1,28 @@ +# Copyright (C) 2025 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +GCC_16.0.0 { + __mulbitint3 + __divmodbitint4 + __fixsfbitint + __fixdfbitint + __fixtfbitint + __floatbitintsf + __floatbitintdf + __floatbitinttf +} diff --git a/libgcc/config/loongarch/t-loongarch b/libgcc/config/loongarch/t-loongarch index 2a7dbf6..b9374fc 100644 --- a/libgcc/config/loongarch/t-loongarch +++ b/libgcc/config/loongarch/t-loongarch @@ -5,3 +5,5 @@ softfp_int_modes := si di softfp_extensions := softfp_truncations := softfp_exclude_libgcc2 := n + +SHLIB_MAPFILES += $(srcdir)/config/loongarch/libgcc-loongarch.ver diff --git a/libgcc/config/loongarch/t-loongarch64 b/libgcc/config/loongarch/t-loongarch64 index a1e3513..20d1520 100644 --- a/libgcc/config/loongarch/t-loongarch64 +++ b/libgcc/config/loongarch/t-loongarch64 @@ -1 +1,3 @@ +LIB2ADD += $(srcdir)/config/loongarch/cpuinfo.c + softfp_int_modes += ti diff --git a/libgcc/config/loongarch/t-softfp-tf b/libgcc/config/loongarch/t-softfp-tf index 306677b..be2b730 100644 --- a/libgcc/config/loongarch/t-softfp-tf +++ b/libgcc/config/loongarch/t-softfp-tf @@ -1,3 +1,4 @@ softfp_float_modes += tf softfp_extensions += sftf dftf softfp_truncations += tfsf tfdf +softfp_extras += floatbitinttf fixtfbitint diff --git a/libgcc/config/i386/t-mingw-mcfgthread b/libgcc/config/mingw/t-mingw-mcfgthread index c5b817f..c5b817f 100644 --- a/libgcc/config/i386/t-mingw-mcfgthread +++ b/libgcc/config/mingw/t-mingw-mcfgthread diff --git a/libgcc/config/nvptx/alloca.c b/libgcc/config/nvptx/alloca.c new file mode 100644 index 0000000..09bdeb6 --- /dev/null +++ b/libgcc/config/nvptx/alloca.c @@ -0,0 +1,38 @@ +/* Fake 'alloca' implementation. + + Copyright (C) 2025 Free Software Foundation, Inc. + + This file is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. + + This file 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 + General Public License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +/* For '-mfake-ptx-alloca', in case real PTX 'alloca' is not available. + With this function defined, we don't get a link-time failure + (unresolved symbol '__GCC_nvptx__PTX_alloca_not_supported'), but rather: + successful execution, in case that 'alloca' is not attempted (if only used + in error code paths, for example), and a run-time failure only in case that + 'alloca' is actually attempted. */ + +void * +__GCC_nvptx__PTX_alloca_not_supported (__SIZE_TYPE__ size __attribute__ ((unused))) +{ + __builtin_printf ("GCC/nvptx: sorry, unimplemented:" + " dynamic stack allocation not supported\n"); + __builtin_abort (); + return 0; +} diff --git a/libgcc/config/nvptx/gbl-ctors.c b/libgcc/config/nvptx/gbl-ctors.c index 2626811..10954ee 100644 --- a/libgcc/config/nvptx/gbl-ctors.c +++ b/libgcc/config/nvptx/gbl-ctors.c @@ -31,6 +31,20 @@ extern int atexit (void (*function) (void)); +/* Host/device compatibility: '__cxa_finalize'. Dummy; if necessary, + overridden via libgomp 'target-cxa-dso-dtor.c'. */ + +extern void __GCC_offload___cxa_finalize (void *); + +void __attribute__((weak)) +__GCC_offload___cxa_finalize (void *dso_handle __attribute__((unused))) +{ +} + +/* There are no DSOs; this is the main program. */ +static void * const __dso_handle = 0; + + /* Handler functions ('static', in contrast to the 'gbl-ctors.h' prototypes). */ @@ -49,6 +63,8 @@ static void __static_do_global_dtors (void); static void __static_do_global_dtors (void) { + __GCC_offload___cxa_finalize (__dso_handle); + func_ptr *p = __DTOR_LIST__; ++p; for (; *p; ++p) diff --git a/libgcc/config/nvptx/t-nvptx b/libgcc/config/nvptx/t-nvptx index f295898..5e2e278 100644 --- a/libgcc/config/nvptx/t-nvptx +++ b/libgcc/config/nvptx/t-nvptx @@ -1,7 +1,8 @@ LIB2ADD=$(srcdir)/config/nvptx/reduction.c \ $(srcdir)/config/nvptx/mgomp.c \ $(srcdir)/config/nvptx/atomic.c \ - $(srcdir)/config/nvptx/unwind-nvptx.c + $(srcdir)/config/nvptx/unwind-nvptx.c \ + $(srcdir)/config/nvptx/alloca.c LIB2ADDEH= LIB2FUNCS_EXCLUDE= diff --git a/libgcc/config/nvptx/unwind-nvptx.c b/libgcc/config/nvptx/unwind-nvptx.c index 44657ae..97e22c0 100644 --- a/libgcc/config/nvptx/unwind-nvptx.c +++ b/libgcc/config/nvptx/unwind-nvptx.c @@ -25,6 +25,33 @@ #include "unwind.h" _Unwind_Reason_Code +_Unwind_RaiseException(struct _Unwind_Exception *exc __attribute__ ((__unused__))) +{ + __builtin_abort (); + return 0; +} + +void +_Unwind_DeleteException (struct _Unwind_Exception *exc) +{ + if (exc->exception_cleanup) + (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc); +} + +void +_Unwind_Resume (struct _Unwind_Exception *exc __attribute__ ((__unused__))) +{ + __builtin_abort (); +} + +_Unwind_Reason_Code +_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc __attribute__ ((__unused__))) +{ + __builtin_abort (); + return 0; +} + +_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument) { return 0; diff --git a/libgcc/config/pa/sync-libfuncs.c b/libgcc/config/pa/sync-libfuncs.c index 774c160..28d08ca 100644 --- a/libgcc/config/pa/sync-libfuncs.c +++ b/libgcc/config/pa/sync-libfuncs.c @@ -133,11 +133,11 @@ atomic_store_8 (volatile void *ptr, u64 value) { double tmp; - asm volatile ("stws|stw} %2,-16(%%sp)\n\t" - "{stws|stw} %R2,-12(%%sp)\n\t" - "{fldds|fldd} -16(%%sp),%1\n\t" - "{fstds|fstd} %1,0(%0)" - : "=m" (ptr), "=&f" (tmp) : "r" (value): "memory"); + asm volatile ("{stws|stw} %1,-16(%%sp)\n\t" + "{stws|stw} %R1,-12(%%sp)\n\t" + "{fldds|fldd} -16(%%sp),%0\n\t" + : "=f" (tmp) : "r" (value): "memory"); + *(volatile double *)ptr = tmp; } #endif diff --git a/libgcc/config/pru/libgcc-eabi.ver b/libgcc/config/pru/libgcc-eabi.ver index e8f7fe2..ded8e73 100644 --- a/libgcc/config/pru/libgcc-eabi.ver +++ b/libgcc/config/pru/libgcc-eabi.ver @@ -86,3 +86,9 @@ GCC_9.0.0 { __gnu_eqsf2 __gnu_eqdf2 } + +%inherit GCC_16.0.0 GCC_9.0.0 +GCC_16.0.0 { + __pruabi_softmpyi + __pruabi_softmpyll +} diff --git a/libgcc/config/pru/pru-softmpy.h b/libgcc/config/pru/pru-softmpy.h new file mode 100644 index 0000000..9f46e6c --- /dev/null +++ b/libgcc/config/pru/pru-softmpy.h @@ -0,0 +1,42 @@ +/* libgcc routines for PRU. + Copyright (C) 2025 Free Software Foundation, Inc. + Based on rl78/rl78-mul.h. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC 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 General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +UINT_TYPE C2(__pruabi_softmpy,NAME_MODE) (UINT_TYPE, UINT_TYPE); +UINT_TYPE +C2(__pruabi_softmpy,NAME_MODE) (UINT_TYPE a, UINT_TYPE b) +{ + UINT_TYPE rv = 0; + + unsigned char bit; + + for (bit=0; b && bit<sizeof(UINT_TYPE)*8; bit++) + { + if (b & 1) + rv += a; + a <<= 1; + b >>= 1; + } + return rv; +} diff --git a/libgcc/config/pru/softmpyi.c b/libgcc/config/pru/softmpyi.c new file mode 100644 index 0000000..fa9f0db --- /dev/null +++ b/libgcc/config/pru/softmpyi.c @@ -0,0 +1,37 @@ +/* libgcc routines for PRU + Copyright (C) 2025 Free Software Foundation, Inc. + Based on rl78/lib2mul.c + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC 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 General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +typedef unsigned int uint32_type __attribute__ ((mode (SI))); + +#define C2B(a,b) a##b +#define C2(a,b) C2B(a,b) + +#undef UINT_TYPE +#undef NAME_MODE + +#define UINT_TYPE uint32_type +#define NAME_MODE i + +#include "pru-softmpy.h" diff --git a/libgcc/config/pru/softmpyll.c b/libgcc/config/pru/softmpyll.c new file mode 100644 index 0000000..8eedc25 --- /dev/null +++ b/libgcc/config/pru/softmpyll.c @@ -0,0 +1,37 @@ +/* libgcc routines for PRU + Copyright (C) 2025 Free Software Foundation, Inc. + Based on rl78/lib2mul.c + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC 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 General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +typedef unsigned int uint64_type __attribute__ ((mode (DI))); + +#define C2B(a,b) a##b +#define C2(a,b) C2B(a,b) + +#undef UINT_TYPE +#undef NAME_MODE + +#define UINT_TYPE uint64_type +#define NAME_MODE ll + +#include "pru-softmpy.h" diff --git a/libgcc/config/pru/t-pru b/libgcc/config/pru/t-pru index e844e79..7554411 100644 --- a/libgcc/config/pru/t-pru +++ b/libgcc/config/pru/t-pru @@ -28,6 +28,8 @@ LIB2ADD += \ $(srcdir)/config/pru/lib2divSI.c \ $(srcdir)/config/pru/lib2bitcountHI.c \ $(srcdir)/config/pru/mpyll.S \ + $(srcdir)/config/pru/softmpyll.c \ + $(srcdir)/config/pru/softmpyi.c \ $(srcdir)/config/pru/gef.c \ $(srcdir)/config/pru/gtf.c \ $(srcdir)/config/pru/lef.c \ diff --git a/libgcc/config/riscv/save-restore.S b/libgcc/config/riscv/save-restore.S index fc65447..f6519e3 100644 --- a/libgcc/config/riscv/save-restore.S +++ b/libgcc/config/riscv/save-restore.S @@ -298,9 +298,8 @@ FUNC_END (__riscv_restore_0) #else #ifdef __riscv_abi_rve + FUNC_BEGIN(__riscv_save_2) -FUNC_BEGIN(__riscv_save_1) -FUNC_BEGIN(__riscv_save_0) .cfi_startproc # __riscv_save_* routine use t0/x5 as return address .cfi_return_column 5 @@ -316,21 +315,56 @@ FUNC_BEGIN(__riscv_save_0) jr t0 .cfi_endproc FUNC_END(__riscv_save_2) + +FUNC_BEGIN(__riscv_save_1) + .cfi_startproc + # __riscv_save_* routine use t0/x5 as return address + .cfi_return_column 5 + addi sp, sp, -8 + .cfi_def_cfa_offset 8 + sw s0, 0(sp) + .cfi_offset 8, -8 + sw ra, 4(sp) + .cfi_offset 1, -4 + SET_LPAD + jr t0 + .cfi_endproc FUNC_END(__riscv_save_1) + +FUNC_BEGIN(__riscv_save_0) + .cfi_startproc + # __riscv_save_* routine use t0/x5 as return address + .cfi_return_column 5 + addi sp, sp, -4 + .cfi_def_cfa_offset 4 + sw ra, 0(sp) + .cfi_offset 1, -4 + SET_LPAD + jr t0 + .cfi_endproc FUNC_END(__riscv_save_0) FUNC_BEGIN(__riscv_restore_2) -FUNC_BEGIN(__riscv_restore_1) -FUNC_BEGIN(__riscv_restore_0) .cfi_startproc - .cfi_def_cfa_offset 14 + .cfi_def_cfa_offset 12 lw s1, 0(sp) .cfi_restore 9 - lw s0, 4(sp) + addi sp, sp, 4 + +FUNC_BEGIN(__riscv_restore_1) + .cfi_restore 9 + .cfi_def_cfa_offset 8 + lw s0, 0(sp) .cfi_restore 8 - lw ra, 8(sp) + addi sp, sp, 4 + +FUNC_BEGIN(__riscv_restore_0) + .cfi_restore 8 + .cfi_restore 9 + .cfi_def_cfa_offset 4 + lw ra, 0(sp) .cfi_restore 1 - addi sp, sp, 12 + addi sp, sp, 4 .cfi_def_cfa_offset 0 ret .cfi_endproc diff --git a/libgcc/config/rs6000/t-slibgcc-aix b/libgcc/config/rs6000/t-slibgcc-aix index 6333687..4a3d624 100644 --- a/libgcc/config/rs6000/t-slibgcc-aix +++ b/libgcc/config/rs6000/t-slibgcc-aix @@ -40,7 +40,9 @@ SHLIB_LINK = \ -Wl,-bE:@shlib_map_file@ -o shr.o \ @multilib_flags@ @shlib_objs@ -lc \ `case @multilib_dir@ in \ - *pthread*) echo -L$(TARGET_SYSTEM_ROOT)/usr/lib/threads -lpthreads -lc_r $(TARGET_SYSTEM_ROOT)/usr/lib/libc.a ;; \ + *pthread*) \ + TARGET_SYSTEM_ROOT=\`$(CC) -print-sysroot\`; \ + echo -L$$TARGET_SYSTEM_ROOT/usr/lib/threads -lpthreads -lc_r $$TARGET_SYSTEM_ROOT/usr/lib/libc.a ;; \ *) echo -lc ;; esac` ; \ rm -f tmp-@shlib_base_name@.a ; \ $(AR_CREATE_FOR_TARGET) tmp-@shlib_base_name@.a shr.o ; \ @@ -53,7 +55,9 @@ SHLIB_LINK = \ -Wl,-bE:@shlib_map_file@ -o $$shr.o \ @multilib_flags@ @shlib_objs@ -lc \ `case @multilib_dir@ in \ - *pthread*) echo -L$(TARGET_SYSTEM_ROOT)/usr/lib/threads -lpthreads -lc_r $(TARGET_SYSTEM_ROOT)/usr/lib/libc.a ;; \ + *pthread*) \ + TARGET_SYSTEM_ROOT=\`$(CC) -print-sysroot\`; \ + echo -L$$TARGET_SYSTEM_ROOT/usr/lib/threads -lpthreads -lc_r $$TARGET_SYSTEM_ROOT/usr/lib/libc.a ;; \ *) echo -lc ;; esac` ; \ $(STRIP_FOR_TARGET) -X32_64 -e $$shr.o ; \ { echo "\#! $(SHLIB_SONAME)($$shr.o)" ; \ diff --git a/libgcc/config/s390/libgcc-glibc.ver b/libgcc/config/s390/libgcc-glibc.ver index 86c55a0..00375b3 100644 --- a/libgcc/config/s390/libgcc-glibc.ver +++ b/libgcc/config/s390/libgcc-glibc.ver @@ -114,3 +114,17 @@ GCC_4.1.0 { __floatditf %endif } + +%ifdef __s390x__ +%inherit GCC_16.0.0 GCC_4.1.0 +GCC_16.0.0 { + __mulbitint3 + __divmodbitint4 + __fixsfbitint + __fixdfbitint + __fixtfbitint + __floatbitintsf + __floatbitintdf + __floatbitinttf +} +%endif diff --git a/libgcc/config/s390/sfp-exceptions.c b/libgcc/config/s390/sfp-exceptions.c new file mode 100644 index 0000000..a2fc5dd --- /dev/null +++ b/libgcc/config/s390/sfp-exceptions.c @@ -0,0 +1,61 @@ +/* Copyright (C) 2001-2025 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GCC 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 General Public License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sfp-machine.h" + +#define __math_force_eval_div(x, y) \ + do { asm ("" : "+f" (x)); asm volatile ("" : : "f" (x / y)); } while (0) + +void +__sfp_handle_exceptions (int _fex) +{ + if (_fex & FP_EX_INVALID) + { + float x = 0.0f; + __math_force_eval_div (x, x); + } + if (_fex & FP_EX_DIVZERO) + { + float x = 1.0f; + float y = 0.0f; + __math_force_eval_div (x, y); + } + if (_fex & FP_EX_OVERFLOW) + { + float x = __FLT_MAX__; + asm ("" : "+f" (x)); + asm volatile ("" : : "f" (x + x)); + } + if (_fex & FP_EX_UNDERFLOW) + { + float x = __FLT_MIN__; + asm ("" : "+f" (x)); + asm volatile ("" : : "f" (x * x)); + } + if (_fex & FP_EX_INEXACT) + { + float x = 1.0f; + float y = 3.0f; + __math_force_eval_div (x, y); + } +} diff --git a/libgcc/config/s390/sfp-machine.h b/libgcc/config/s390/sfp-machine.h new file mode 100644 index 0000000..960bad7 --- /dev/null +++ b/libgcc/config/s390/sfp-machine.h @@ -0,0 +1,89 @@ +/* Copyright (C) 2001-2025 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GCC 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 General Public License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +#if ! __s390x__ +# error "soft-fp implemented for s390x only" +#endif + +#define _FP_W_TYPE_SIZE 64 +#define _FP_W_TYPE unsigned long long +#define _FP_WS_TYPE signed long long +#define _FP_I_TYPE long long + +typedef int TItype __attribute__ ((mode (TI))); +typedef unsigned int UTItype __attribute__ ((mode (TI))); +#define TI_BITS (__CHAR_BIT__ * (int) sizeof (TItype)) + +#define _FP_NANFRAC_H ((_FP_QNANBIT_H << 1) - 1) +#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1) +#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1) +#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1 + +#define _FP_NANSIGN_H 0 +#define _FP_NANSIGN_S 0 +#define _FP_NANSIGN_D 0 +#define _FP_NANSIGN_Q 0 + +#define _FP_KEEPNANFRACP 1 +#define _FP_QNANNEGATEDP 0 + +#define FP_EX_INVALID 0x01 +#define FP_EX_DIVZERO 0x02 +#define FP_EX_OVERFLOW 0x04 +#define FP_EX_UNDERFLOW 0x08 +#define FP_EX_INEXACT 0x10 +#define FP_EX_ALL \ + (FP_EX_INVALID | FP_EX_DIVZERO | FP_EX_OVERFLOW \ + | FP_EX_UNDERFLOW | FP_EX_INEXACT) + +void __sfp_handle_exceptions (int); + +#define FP_HANDLE_EXCEPTIONS \ + do { \ + if (__builtin_expect (_fex, 0)) \ + __sfp_handle_exceptions (_fex); \ + } while (0) + +#define _FP_TININESS_AFTER_ROUNDING 0 + +#define FP_RND_NEAREST 0x0 +#define FP_RND_ZERO 0x1 +#define FP_RND_PINF 0x2 +#define FP_RND_MINF 0x3 +#define FP_RND_MASK 0x3 + +#define _FP_DECL_EX \ + unsigned int _fpcr __attribute__ ((unused)) = FP_RND_NEAREST + +#define FP_INIT_ROUNDMODE \ + do { \ + __asm__ __volatile__ ("stfpc %0" \ + : "=m" (_fpcr)); \ + } while (0) + +#define FP_ROUNDMODE (_fpcr & FP_RND_MASK) + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 + +#define __BYTE_ORDER __BIG_ENDIAN diff --git a/libgcc/config/s390/t-softfp b/libgcc/config/s390/t-softfp new file mode 100644 index 0000000..724b15e --- /dev/null +++ b/libgcc/config/s390/t-softfp @@ -0,0 +1,2 @@ +LIB2ADD += $(srcdir)/config/s390/sfp-exceptions.c +softfp_extras := fixtfbitint floatbitinttf diff --git a/libgcc/config/sh/lib1funcs.S b/libgcc/config/sh/lib1funcs.S index eda4806..11acfd5 100644 --- a/libgcc/config/sh/lib1funcs.S +++ b/libgcc/config/sh/lib1funcs.S @@ -115,7 +115,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see HIDDEN_FUNC(GLOBAL(ashiftrt_r4_31)) HIDDEN_FUNC(GLOBAL(ashiftrt_r4_32)) - .align 1 + .align 4 GLOBAL(ashiftrt_r4_32): GLOBAL(ashiftrt_r4_31): rotcl r4 @@ -764,6 +764,7 @@ LOCAL(movmem_loop): /* Reached with rts */ bt GLOBAL(movmemSI52) ! done all the large groups, do the remainder ! jump to movmem+ + .balign 4 mova GLOBAL(movmemSI4)+4,r0 add r6,r0 jmp @r0 diff --git a/libgcc/config/sh/sfp-machine.h b/libgcc/config/sh/sfp-machine.h index 66984d4..8030c80 100644 --- a/libgcc/config/sh/sfp-machine.h +++ b/libgcc/config/sh/sfp-machine.h @@ -39,11 +39,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y) #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y) -#define _FP_NANFRAC_B _FP_QNANBIT_B -#define _FP_NANFRAC_H _FP_QNANBIT_H -#define _FP_NANFRAC_S _FP_QNANBIT_S -#define _FP_NANFRAC_D _FP_QNANBIT_D, 0 -#define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0, 0, 0 +#define _FP_NANFRAC_B (_FP_QNANBIT_B - 1) +#define _FP_NANFRAC_H (_FP_QNANBIT_H - 1) +#define _FP_NANFRAC_S (_FP_QNANBIT_S - 1) +#define _FP_NANFRAC_D (_FP_QNANBIT_D - 1), -1 +#define _FP_NANFRAC_Q (_FP_QNANBIT_Q - 1), -1, -1, -1 /* The type of the result of a floating point comparison. This must match __libgcc_cmp_return__ in GCC for the target. */ @@ -56,15 +56,71 @@ typedef int __gcc_CMPtype __attribute__ ((mode (__libgcc_cmp_return__))); #define _FP_NANSIGN_D 0 #define _FP_NANSIGN_Q 0 -#define _FP_KEEPNANFRACP 0 -#define _FP_QNANNEGATEDP 0 +#define _FP_KEEPNANFRACP 1 +#define _FP_QNANNEGATEDP 1 + +/* X is chosen unless one of the NaNs is sNaN. */ +# define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \ + do { \ + if ((_FP_FRAC_HIGH_RAW_##fs(X) | \ + _FP_FRAC_HIGH_RAW_##fs(Y)) & _FP_QNANBIT_##fs) \ + { \ + R##_s = _FP_NANSIGN_##fs; \ + _FP_FRAC_SET_##wc(R,_FP_NANFRAC_##fs); \ + } \ + else \ + { \ + R##_s = X##_s; \ + _FP_FRAC_COPY_##wc(R,X); \ + } \ + R##_c = FP_CLS_NAN; \ + } while (0) + +#ifdef __SH_FPU_ANY__ +#define _FPU_GETCW(fpscr) fpscr = __builtin_sh_get_fpscr () +#define _FPU_SETCW(fpscr) __builtin_sh_set_fpscr (fpscr) +#define FP_EX_ENABLE_SHIFT 5 +#define FP_EX_CAUSE_SHIFT 10 -#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \ - do { \ - R##_s = _FP_NANSIGN_##fs; \ - _FP_FRAC_SET_##wc(R,_FP_NANFRAC_##fs); \ - R##_c = FP_CLS_NAN; \ +#define FP_EX_INVALID 0x0040 +#define FP_EX_DIVZERO 0x0020 +#if defined (__SH2E__) +#define FP_EX_ALL (FP_EX_DIVZERO | FP_EX_INVALID) +#else +#define FP_EX_OVERFLOW 0x0010 +#define FP_EX_UNDERFLOW 0x0008 +#define FP_EX_INEXACT 0x0004 +#define FP_EX_ALL (FP_EX_DIVZERO | FP_EX_INEXACT | \ + FP_EX_INVALID | FP_EX_OVERFLOW | FP_EX_UNDERFLOW) +#endif +#define _FP_DECL_EX \ + unsigned int _fcsr __attribute__ ((unused)) = FP_RND_NEAREST +/* Rounding modes. */ +#define FP_RND_NEAREST 0x0 +#define FP_RND_ZERO 0x1 +/* Placeholder, hardware does not have PINF/MINF modes. */ +#define FP_RND_PINF 0x2 +#define FP_RND_MINF 0x3 +#define FP_RND_MASK 3 + +#define FP_INIT_ROUNDMODE _FPU_GETCW (_fcsr) +#define FP_ROUNDMODE (_fcsr & FP_RND_MASK) +#define FP_TRAPPING_EXCEPTIONS ((_fcsr >> FP_EX_ENABLE_SHIFT) & FP_EX_ALL) +#define FP_HANDLE_EXCEPTIONS \ + do { \ + _fcsr &= ~(FP_EX_ALL << FP_EX_CAUSE_SHIFT); \ + _fcsr |= _fex | (_fex << FP_EX_CAUSE_SHIFT); \ + _FPU_SETCW (_fcsr); \ } while (0) +#else +#define FP_EX_INVALID (1 << 4) +#define FP_EX_DIVZERO (1 << 3) +#if !defined (__SH2E__) +#define FP_EX_OVERFLOW (1 << 2) +#define FP_EX_UNDERFLOW (1 << 1) +#define FP_EX_INEXACT (1 << 0) +#endif +#endif #define _FP_TININESS_AFTER_ROUNDING 1 diff --git a/libgcc/config/t-softfp b/libgcc/config/t-softfp index 94297ad..c08b681 100644 --- a/libgcc/config/t-softfp +++ b/libgcc/config/t-softfp @@ -67,20 +67,21 @@ softfp_floatint_funcs = fix$(m)$(i) fixuns$(m)$(i) \ softfp_floatbitint_funcs = fix$(m)bitint floatbitint$(m) softfp_bid_list := ifeq ($(decimal_float),yes) -ifeq ($(enable_decimal_float),bid) softfp_bid_list += bitintpow10 \ $(foreach m,sd dd td,fix$(m)bitint floatbitint$(m) \ fix$(m)ti fixuns$(m)ti \ floatti$(m) floatunti$(m)) endif -endif + +softfp_bitint_func_list := \ + $(foreach m,sf df,$(softfp_floatbitint_funcs)) \ + $(bitint_extras) softfp_func_list := \ $(foreach m,$(softfp_float_modes), \ $(softfp_float_funcs) \ $(foreach i,$(softfp_int_modes), \ $(softfp_floatint_funcs))) \ - $(foreach m,sf df,$(softfp_floatbitint_funcs)) \ $(foreach e,$(softfp_extensions),extend$(e)2) \ $(foreach t,$(softfp_truncations),trunc$(t)2) \ $(softfp_extras) @@ -95,7 +96,8 @@ softfp_func_list := $(filter-out floatdidf floatdisf fixunsdfsi fixunssfsi \ endif ifeq ($(softfp_compat),y) -softfp_file_list := $(addsuffix .c,$(softfp_func_list)) +softfp_file_list := $(addsuffix .c,$(softfp_func_list)) \ + $(addsuffix .c,$(softfp_bitint_func_list)) ifeq ($(enable_shared),yes) softfp_map_dep := libgcc.map.in @@ -126,6 +128,8 @@ else softfp_file_list := \ $(addsuffix .c,$(addprefix $(srcdir)/soft-fp/,$(softfp_func_list))) endif +softfp_file_list += \ + $(addsuffix .c,$(addprefix $(srcdir)/soft-fp/,$(softfp_bitint_func_list))) endif softfp_bid_file_list := \ $(addsuffix .c,$(addprefix $(srcdir)/soft-fp/,$(softfp_bid_list))) @@ -139,7 +143,7 @@ soft-fp-objects-base = $(basename $(notdir $(softfp_file_list))) soft-fp-objects = $(addsuffix $(objext), $(soft-fp-objects-base)) \ $(addsuffix _s$(objext), $(soft-fp-objects-base)) -$(soft-fp-objects) : INTERNAL_CFLAGS += -Wno-missing-prototypes -Wno-type-limits +$(soft-fp-objects) : INTERNAL_CFLAGS += -Wno-missing-prototypes -Wno-type-limits $(softfp_cflags) LIB2ADD += $(softfp_file_list) LIB2ADD_ST += $(softfp_bid_file_list) diff --git a/libgcc/config/t-vxworks b/libgcc/config/t-vxworks index 81a4dea..ca0d0cf 100644 --- a/libgcc/config/t-vxworks +++ b/libgcc/config/t-vxworks @@ -30,9 +30,9 @@ LIB2FUNCS_EXCLUDE += _clear_cache # paths differs between Windows and Linux hosts as the latter can perform # inode based checks while the former may only rely on name comparisons. -LIBGCC2_INCLUDES = -nostdinc -I. \ +LIBGCC2_INCLUDES = -nostdinc -include vxworks-predef.h -I. \ $(if $(findstring vxworks7, $(target_noncanonical)), \ - -I$(VSB_DIR)/h -I$(VSB_DIR)/share/h -I=/system -I=/public, \ + -I=/../../h -I=/../../share/h -I=/system -I=/public, \ -I=/ -I=/wrn/coreip) \ -isystem $(MULTIBUILDTOP)../../gcc/include-fixed$(MULTISUBDIR) \ -isystem $(MULTIBUILDTOP)../../gcc/include diff --git a/libgcc/configure b/libgcc/configure index 1841833..fe7a21c2 100755 --- a/libgcc/configure +++ b/libgcc/configure @@ -586,6 +586,7 @@ ac_unique_file="static-object.mk" ac_includes_default='/* none */' ac_subst_vars='LTLIBOBJS LIBOBJS +WERROR md_unwind_header md_unwind_def_header unwind_header @@ -609,6 +610,7 @@ accel_dir_suffix use_tm_clone_registry force_explicit_eh_registry CET_FLAGS +NO_PIE_CFLAGS fixed_point enable_decimal_float decimal_float @@ -720,6 +722,7 @@ enable_tm_clone_registry with_glibc_version enable_tls with_gcc_major_version_only +enable_werror ' ac_precious_vars='build_alias host_alias @@ -1362,6 +1365,7 @@ Optional Features: installations without PT_GNU_EH_FRAME support --disable-tm-clone-registry disable TM clone registry --enable-tls Use thread-local storage [default=yes] + --enable-werror build with -Werror for selected targets Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -4833,6 +4837,40 @@ $as_echo "$libgcc_cv_fixed_point" >&6; } fixed_point=$libgcc_cv_fixed_point +# Check whether the compiler defines __PIE__ by default, so -fno-PIE is needed. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler defines __PIE__" >&5 +$as_echo_n "checking whether the compiler defines __PIE__... " >&6; } +if ${libgcc_cv_no_pie_cflags+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#ifdef __PIE__ +#error __PIE__ defined +#endif + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + libgcc_cv_no_pie_cflags='' +else + libgcc_cv_no_pie_cflags='-fno-PIE' +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_no_pie_cflags" >&5 +$as_echo "$libgcc_cv_no_pie_cflags" >&6; } + +NO_PIE_CFLAGS=$libgcc_cv_no_pie_cflags + + # For platforms with the unwind ABI which includes an unwind library, # libunwind, we can choose to use the system libunwind. # config.gcc also contains tests of with_system_libunwind. @@ -5043,11 +5081,28 @@ $as_echo "$acl_cv_prog_gnu_ld" >&6; } with_gnu_ld=$acl_cv_prog_gnu_ld -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread model used by GCC" >&5 -$as_echo_n "checking for thread model used by GCC... " >&6; } -target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'` -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5 -$as_echo "$target_thread_file" >&6; } + +# Specify the threading model for this GCC runtime library +# Pass with no value to take from compiler's metadata +# Pass with a value to specify a thread package +# 'single' means single threaded -- without threads. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the threading model used by GCC" >&5 +$as_echo_n "checking for the threading model used by GCC... " >&6; } +if ${gcc_cv_target_thread_file+:} false; then : + $as_echo_n "(cached) " >&6 +else + + # Set new cache variable + gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'` + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_target_thread_file" >&5 +$as_echo "$gcc_cv_target_thread_file" >&6; } +# Set variable name (not prefixed enough to be a good cache variable +# name) traditionally used for this purpose, to avoid having to change +# a bunch of configure scripts. +target_thread_file="$gcc_cv_target_thread_file" + # Check for assembler CFI support. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether assembler supports CFI directives" >&5 @@ -5734,6 +5789,9 @@ case $target_thread_file in vxworks) thread_header=config/gthr-vxworks.h ;; win32) thread_header=config/i386/gthr-win32.h ;; mcf) thread_header=config/i386/gthr-mcf.h ;; + *) + as_fn_error $? "No known header for threading model '$target_thread_file'." "$LINENO" 5 + ;; esac @@ -5789,6 +5847,22 @@ fi +# Check whether --enable-werror was given. +if test "${enable_werror+set}" = set; then : + enableval=$enable_werror; +case ${enable_werror} in + no) WERROR="" ;; + *) WERROR="-Werror" ;; +esac + +else + +WERROR="-Werror" + +fi + + + # We need multilib support. ac_config_files="$ac_config_files Makefile" diff --git a/libgcc/configure.ac b/libgcc/configure.ac index 85e4f1b..5945243 100644 --- a/libgcc/configure.ac +++ b/libgcc/configure.ac @@ -258,6 +258,20 @@ AC_CACHE_CHECK([whether fixed-point is supported], [libgcc_cv_fixed_point], fixed_point=$libgcc_cv_fixed_point AC_SUBST(fixed_point) +# Check whether the compiler defines __PIE__ by default, so -fno-PIE is needed. +AC_CACHE_CHECK([whether the compiler defines __PIE__], [libgcc_cv_no_pie_cflags], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ +#ifdef __PIE__ +#error __PIE__ defined +#endif + ]], [[]])], + [libgcc_cv_no_pie_cflags=''], + [libgcc_cv_no_pie_cflags='-fno-PIE'])]) + +NO_PIE_CFLAGS=$libgcc_cv_no_pie_cflags +AC_SUBST([NO_PIE_CFLAGS]) + # For platforms with the unwind ABI which includes an unwind library, # libunwind, we can choose to use the system libunwind. # config.gcc also contains tests of with_system_libunwind. @@ -305,9 +319,7 @@ AC_SUBST([use_tm_clone_registry]) AC_LIB_PROG_LD_GNU -AC_MSG_CHECKING([for thread model used by GCC]) -target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'` -AC_MSG_RESULT([$target_thread_file]) +GCC_AC_THREAD_MODEL # Check for assembler CFI support. AC_CACHE_CHECK([whether assembler supports CFI directives], [libgcc_cv_cfi], @@ -733,6 +745,20 @@ AC_SUBST(md_unwind_header) AC_SUBST(sfp_machine_header) AC_SUBST(thread_header) +AC_ARG_ENABLE(werror, +[AS_HELP_STRING([--enable-werror], + [build with -Werror for selected targets])], +[ +case ${enable_werror} in + no) WERROR="" ;; + *) WERROR="-Werror" ;; +esac +], +[ +WERROR="-Werror" +]) +AC_SUBST(WERROR) + # We need multilib support. AC_CONFIG_FILES([Makefile]) AC_CONFIG_COMMANDS([default], diff --git a/libgcc/enable-execute-stack-mprotect.c b/libgcc/enable-execute-stack-mprotect.c index 08a0d72..7971efb 100644 --- a/libgcc/enable-execute-stack-mprotect.c +++ b/libgcc/enable-execute-stack-mprotect.c @@ -30,7 +30,6 @@ static int need_enable_exec_stack; -static void check_enabling (void) __attribute__ ((unused)); extern void __enable_execute_stack (void *); #if defined __sun__ && defined __svr4__ diff --git a/libgcc/libgcc-std.ver.in b/libgcc/libgcc-std.ver.in index 1e372d7..3b3b5e6 100644 --- a/libgcc/libgcc-std.ver.in +++ b/libgcc/libgcc-std.ver.in @@ -1947,12 +1947,6 @@ GCC_7.0.0 { %inherit GCC_14.0.0 GCC_7.0.0 GCC_14.0.0 { - __PFX__mulbitint3 - __PFX__divmodbitint4 - __PFX__fixsfbitint - __PFX__fixdfbitint - __PFX__floatbitintsf - __PFX__floatbitintdf __PFX__hardcfr_check __PFX__strub_enter __PFX__strub_update diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c index 92cb79d..df99c78 100644 --- a/libgcc/libgcc2.c +++ b/libgcc/libgcc2.c @@ -1333,7 +1333,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec >= -1) return -2; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -1347,7 +1347,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec >= -1) return -2; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -1358,7 +1358,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if ((Wtype) mslimb >= 0) { #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - --p; + --*p; #endif return prec - 1; } @@ -1387,7 +1387,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec == 0) return 1; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -1400,7 +1400,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec == 0) return 1; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -2187,36 +2187,21 @@ __fixunssfDI (SFtype a) if (a < 1) return 0; if (a < Wtype_MAXp1_F) - return (UWtype)a; + return (UWtype) a; if (a < Wtype_MAXp1_F * Wtype_MAXp1_F) { - /* Since we know that there are fewer significant bits in the SFmode - quantity than in a word, we know that we can convert out all the - significant bits in one step, and thus avoid losing bits. */ - - /* ??? This following loop essentially performs frexpf. If we could - use the real libm function, or poke at the actual bits of the fp - format, it would be significantly faster. */ - - UWtype shift = 0, counter; - SFtype msb; - - a /= Wtype_MAXp1_F; - for (counter = W_TYPE_SIZE / 2; counter != 0; counter >>= 1) - { - SFtype counterf = (UWtype)1 << counter; - if (a >= counterf) - { - shift |= counter; - a /= counterf; - } - } - - /* Rescale into the range of one word, extract the bits of that - one word, and shift the result into position. */ - a *= Wtype_MAXp1_F; - counter = a; - return (DWtype)counter << shift; + /* We assume that SFtype -> UWtype and UWtype -> UDWtype casts work + properly. Obviously, we *cannot* assume that SFtype -> UDWtype + works as expected. */ + SFtype a_hi, a_lo; + + a_hi = a / Wtype_MAXp1_F; + a_lo = a - a_hi * Wtype_MAXp1_F; + + /* A lot of parentheses. This is to make it very clear what is + the sequence of operations. */ + return ((UDWtype) ((UWtype) a_hi)) << W_TYPE_SIZE + | (UDWtype) ((UWtype) a_lo); } return -1; #else diff --git a/libgcc/soft-fp/bitint.h b/libgcc/soft-fp/bitint.h index 07a7bcb..457fc8f3 100644 --- a/libgcc/soft-fp/bitint.h +++ b/libgcc/soft-fp/bitint.h @@ -1,7 +1,7 @@ /* Software floating-point emulation. Definitions for _BitInt implementation details. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -76,7 +76,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec >= -1) return -2; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -90,7 +90,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec >= -1) return -2; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -101,7 +101,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if ((BILtype) mslimb >= 0) { #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - --p; + --*p; #endif return prec - 1; } @@ -130,7 +130,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec == 0) return 1; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -143,7 +143,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec) if (prec == 0) return 1; #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ - ++p; + ++*p; #else --i; #endif @@ -352,6 +352,10 @@ extern void __divmodbitint4 (UBILtype *, SItype, UBILtype *, SItype, const UBILtype *, SItype, const UBILtype *, SItype); +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_pow10bitint __dpd_pow10bitint +extern const unsigned short __dpd_d2bbitint[1024], __dpd_b2dbitint[1000]; +#endif extern USItype __bid_pow10bitint (UBILtype *, SItype, USItype); #endif /* __BITINT_MAXWIDTH__ */ diff --git a/libgcc/soft-fp/bitintpow10.c b/libgcc/soft-fp/bitintpow10.c index 06a470f0..15b288c 100644 --- a/libgcc/soft-fp/bitintpow10.c +++ b/libgcc/soft-fp/bitintpow10.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Compute powers of 10 into _BitInt. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -130,3 +130,341 @@ __bid_pow10bitint (UBILtype *r, SItype rprec, USItype n) } } #endif + +#ifndef ENABLE_DECIMAL_BID_FORMAT +/* DPD encoded 10-bit number to decimal table. */ +const unsigned short __dpd_d2bbitint[1024] = { + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 80, 81, 800, 801, 880, 881, + 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 90, 91, 810, 811, 890, 891, + 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 82, 83, 820, 821, 808, 809, + 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 92, 93, 830, 831, 818, 819, + 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 84, 85, 840, 841, 88, 89, + 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 94, 95, 850, 851, 98, 99, + 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 86, 87, 860, 861, 888, 889, + 70, 71, 72, 73, 74, 75, 76, 77, + 78, 79, 96, 97, 870, 871, 898, 899, + 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 180, 181, 900, 901, 980, 981, + 110, 111, 112, 113, 114, 115, 116, 117, + 118, 119, 190, 191, 910, 911, 990, 991, + 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 182, 183, 920, 921, 908, 909, + 130, 131, 132, 133, 134, 135, 136, 137, + 138, 139, 192, 193, 930, 931, 918, 919, + 140, 141, 142, 143, 144, 145, 146, 147, + 148, 149, 184, 185, 940, 941, 188, 189, + 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, 194, 195, 950, 951, 198, 199, + 160, 161, 162, 163, 164, 165, 166, 167, + 168, 169, 186, 187, 960, 961, 988, 989, + 170, 171, 172, 173, 174, 175, 176, 177, + 178, 179, 196, 197, 970, 971, 998, 999, + 200, 201, 202, 203, 204, 205, 206, 207, + 208, 209, 280, 281, 802, 803, 882, 883, + 210, 211, 212, 213, 214, 215, 216, 217, + 218, 219, 290, 291, 812, 813, 892, 893, + 220, 221, 222, 223, 224, 225, 226, 227, + 228, 229, 282, 283, 822, 823, 828, 829, + 230, 231, 232, 233, 234, 235, 236, 237, + 238, 239, 292, 293, 832, 833, 838, 839, + 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 284, 285, 842, 843, 288, 289, + 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 294, 295, 852, 853, 298, 299, + 260, 261, 262, 263, 264, 265, 266, 267, + 268, 269, 286, 287, 862, 863, 888, 889, + 270, 271, 272, 273, 274, 275, 276, 277, + 278, 279, 296, 297, 872, 873, 898, 899, + 300, 301, 302, 303, 304, 305, 306, 307, + 308, 309, 380, 381, 902, 903, 982, 983, + 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 390, 391, 912, 913, 992, 993, + 320, 321, 322, 323, 324, 325, 326, 327, + 328, 329, 382, 383, 922, 923, 928, 929, + 330, 331, 332, 333, 334, 335, 336, 337, + 338, 339, 392, 393, 932, 933, 938, 939, + 340, 341, 342, 343, 344, 345, 346, 347, + 348, 349, 384, 385, 942, 943, 388, 389, + 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 394, 395, 952, 953, 398, 399, + 360, 361, 362, 363, 364, 365, 366, 367, + 368, 369, 386, 387, 962, 963, 988, 989, + 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 396, 397, 972, 973, 998, 999, + 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 480, 481, 804, 805, 884, 885, + 410, 411, 412, 413, 414, 415, 416, 417, + 418, 419, 490, 491, 814, 815, 894, 895, + 420, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 482, 483, 824, 825, 848, 849, + 430, 431, 432, 433, 434, 435, 436, 437, + 438, 439, 492, 493, 834, 835, 858, 859, + 440, 441, 442, 443, 444, 445, 446, 447, + 448, 449, 484, 485, 844, 845, 488, 489, + 450, 451, 452, 453, 454, 455, 456, 457, + 458, 459, 494, 495, 854, 855, 498, 499, + 460, 461, 462, 463, 464, 465, 466, 467, + 468, 469, 486, 487, 864, 865, 888, 889, + 470, 471, 472, 473, 474, 475, 476, 477, + 478, 479, 496, 497, 874, 875, 898, 899, + 500, 501, 502, 503, 504, 505, 506, 507, + 508, 509, 580, 581, 904, 905, 984, 985, + 510, 511, 512, 513, 514, 515, 516, 517, + 518, 519, 590, 591, 914, 915, 994, 995, + 520, 521, 522, 523, 524, 525, 526, 527, + 528, 529, 582, 583, 924, 925, 948, 949, + 530, 531, 532, 533, 534, 535, 536, 537, + 538, 539, 592, 593, 934, 935, 958, 959, + 540, 541, 542, 543, 544, 545, 546, 547, + 548, 549, 584, 585, 944, 945, 588, 589, + 550, 551, 552, 553, 554, 555, 556, 557, + 558, 559, 594, 595, 954, 955, 598, 599, + 560, 561, 562, 563, 564, 565, 566, 567, + 568, 569, 586, 587, 964, 965, 988, 989, + 570, 571, 572, 573, 574, 575, 576, 577, + 578, 579, 596, 597, 974, 975, 998, 999, + 600, 601, 602, 603, 604, 605, 606, 607, + 608, 609, 680, 681, 806, 807, 886, 887, + 610, 611, 612, 613, 614, 615, 616, 617, + 618, 619, 690, 691, 816, 817, 896, 897, + 620, 621, 622, 623, 624, 625, 626, 627, + 628, 629, 682, 683, 826, 827, 868, 869, + 630, 631, 632, 633, 634, 635, 636, 637, + 638, 639, 692, 693, 836, 837, 878, 879, + 640, 641, 642, 643, 644, 645, 646, 647, + 648, 649, 684, 685, 846, 847, 688, 689, + 650, 651, 652, 653, 654, 655, 656, 657, + 658, 659, 694, 695, 856, 857, 698, 699, + 660, 661, 662, 663, 664, 665, 666, 667, + 668, 669, 686, 687, 866, 867, 888, 889, + 670, 671, 672, 673, 674, 675, 676, 677, + 678, 679, 696, 697, 876, 877, 898, 899, + 700, 701, 702, 703, 704, 705, 706, 707, + 708, 709, 780, 781, 906, 907, 986, 987, + 710, 711, 712, 713, 714, 715, 716, 717, + 718, 719, 790, 791, 916, 917, 996, 997, + 720, 721, 722, 723, 724, 725, 726, 727, + 728, 729, 782, 783, 926, 927, 968, 969, + 730, 731, 732, 733, 734, 735, 736, 737, + 738, 739, 792, 793, 936, 937, 978, 979, + 740, 741, 742, 743, 744, 745, 746, 747, + 748, 749, 784, 785, 946, 947, 788, 789, + 750, 751, 752, 753, 754, 755, 756, 757, + 758, 759, 794, 795, 956, 957, 798, 799, + 760, 761, 762, 763, 764, 765, 766, 767, + 768, 769, 786, 787, 966, 967, 988, 989, + 770, 771, 772, 773, 774, 775, 776, 777, + 778, 779, 796, 797, 976, 977, 998, 999 +}; + +/* Decimal to DPD encoded 10-bit number table. */ +const unsigned short __dpd_b2dbitint[1000] = { + 0x000, 0x001, 0x002, 0x003, 0x004, + 0x005, 0x006, 0x007, 0x008, 0x009, + 0x010, 0x011, 0x012, 0x013, 0x014, + 0x015, 0x016, 0x017, 0x018, 0x019, + 0x020, 0x021, 0x022, 0x023, 0x024, + 0x025, 0x026, 0x027, 0x028, 0x029, + 0x030, 0x031, 0x032, 0x033, 0x034, + 0x035, 0x036, 0x037, 0x038, 0x039, + 0x040, 0x041, 0x042, 0x043, 0x044, + 0x045, 0x046, 0x047, 0x048, 0x049, + 0x050, 0x051, 0x052, 0x053, 0x054, + 0x055, 0x056, 0x057, 0x058, 0x059, + 0x060, 0x061, 0x062, 0x063, 0x064, + 0x065, 0x066, 0x067, 0x068, 0x069, + 0x070, 0x071, 0x072, 0x073, 0x074, + 0x075, 0x076, 0x077, 0x078, 0x079, + 0x00a, 0x00b, 0x02a, 0x02b, 0x04a, + 0x04b, 0x06a, 0x06b, 0x04e, 0x04f, + 0x01a, 0x01b, 0x03a, 0x03b, 0x05a, + 0x05b, 0x07a, 0x07b, 0x05e, 0x05f, + 0x080, 0x081, 0x082, 0x083, 0x084, + 0x085, 0x086, 0x087, 0x088, 0x089, + 0x090, 0x091, 0x092, 0x093, 0x094, + 0x095, 0x096, 0x097, 0x098, 0x099, + 0x0a0, 0x0a1, 0x0a2, 0x0a3, 0x0a4, + 0x0a5, 0x0a6, 0x0a7, 0x0a8, 0x0a9, + 0x0b0, 0x0b1, 0x0b2, 0x0b3, 0x0b4, + 0x0b5, 0x0b6, 0x0b7, 0x0b8, 0x0b9, + 0x0c0, 0x0c1, 0x0c2, 0x0c3, 0x0c4, + 0x0c5, 0x0c6, 0x0c7, 0x0c8, 0x0c9, + 0x0d0, 0x0d1, 0x0d2, 0x0d3, 0x0d4, + 0x0d5, 0x0d6, 0x0d7, 0x0d8, 0x0d9, + 0x0e0, 0x0e1, 0x0e2, 0x0e3, 0x0e4, + 0x0e5, 0x0e6, 0x0e7, 0x0e8, 0x0e9, + 0x0f0, 0x0f1, 0x0f2, 0x0f3, 0x0f4, + 0x0f5, 0x0f6, 0x0f7, 0x0f8, 0x0f9, + 0x08a, 0x08b, 0x0aa, 0x0ab, 0x0ca, + 0x0cb, 0x0ea, 0x0eb, 0x0ce, 0x0cf, + 0x09a, 0x09b, 0x0ba, 0x0bb, 0x0da, + 0x0db, 0x0fa, 0x0fb, 0x0de, 0x0df, + 0x100, 0x101, 0x102, 0x103, 0x104, + 0x105, 0x106, 0x107, 0x108, 0x109, + 0x110, 0x111, 0x112, 0x113, 0x114, + 0x115, 0x116, 0x117, 0x118, 0x119, + 0x120, 0x121, 0x122, 0x123, 0x124, + 0x125, 0x126, 0x127, 0x128, 0x129, + 0x130, 0x131, 0x132, 0x133, 0x134, + 0x135, 0x136, 0x137, 0x138, 0x139, + 0x140, 0x141, 0x142, 0x143, 0x144, + 0x145, 0x146, 0x147, 0x148, 0x149, + 0x150, 0x151, 0x152, 0x153, 0x154, + 0x155, 0x156, 0x157, 0x158, 0x159, + 0x160, 0x161, 0x162, 0x163, 0x164, + 0x165, 0x166, 0x167, 0x168, 0x169, + 0x170, 0x171, 0x172, 0x173, 0x174, + 0x175, 0x176, 0x177, 0x178, 0x179, + 0x10a, 0x10b, 0x12a, 0x12b, 0x14a, + 0x14b, 0x16a, 0x16b, 0x14e, 0x14f, + 0x11a, 0x11b, 0x13a, 0x13b, 0x15a, + 0x15b, 0x17a, 0x17b, 0x15e, 0x15f, + 0x180, 0x181, 0x182, 0x183, 0x184, + 0x185, 0x186, 0x187, 0x188, 0x189, + 0x190, 0x191, 0x192, 0x193, 0x194, + 0x195, 0x196, 0x197, 0x198, 0x199, + 0x1a0, 0x1a1, 0x1a2, 0x1a3, 0x1a4, + 0x1a5, 0x1a6, 0x1a7, 0x1a8, 0x1a9, + 0x1b0, 0x1b1, 0x1b2, 0x1b3, 0x1b4, + 0x1b5, 0x1b6, 0x1b7, 0x1b8, 0x1b9, + 0x1c0, 0x1c1, 0x1c2, 0x1c3, 0x1c4, + 0x1c5, 0x1c6, 0x1c7, 0x1c8, 0x1c9, + 0x1d0, 0x1d1, 0x1d2, 0x1d3, 0x1d4, + 0x1d5, 0x1d6, 0x1d7, 0x1d8, 0x1d9, + 0x1e0, 0x1e1, 0x1e2, 0x1e3, 0x1e4, + 0x1e5, 0x1e6, 0x1e7, 0x1e8, 0x1e9, + 0x1f0, 0x1f1, 0x1f2, 0x1f3, 0x1f4, + 0x1f5, 0x1f6, 0x1f7, 0x1f8, 0x1f9, + 0x18a, 0x18b, 0x1aa, 0x1ab, 0x1ca, + 0x1cb, 0x1ea, 0x1eb, 0x1ce, 0x1cf, + 0x19a, 0x19b, 0x1ba, 0x1bb, 0x1da, + 0x1db, 0x1fa, 0x1fb, 0x1de, 0x1df, + 0x200, 0x201, 0x202, 0x203, 0x204, + 0x205, 0x206, 0x207, 0x208, 0x209, + 0x210, 0x211, 0x212, 0x213, 0x214, + 0x215, 0x216, 0x217, 0x218, 0x219, + 0x220, 0x221, 0x222, 0x223, 0x224, + 0x225, 0x226, 0x227, 0x228, 0x229, + 0x230, 0x231, 0x232, 0x233, 0x234, + 0x235, 0x236, 0x237, 0x238, 0x239, + 0x240, 0x241, 0x242, 0x243, 0x244, + 0x245, 0x246, 0x247, 0x248, 0x249, + 0x250, 0x251, 0x252, 0x253, 0x254, + 0x255, 0x256, 0x257, 0x258, 0x259, + 0x260, 0x261, 0x262, 0x263, 0x264, + 0x265, 0x266, 0x267, 0x268, 0x269, + 0x270, 0x271, 0x272, 0x273, 0x274, + 0x275, 0x276, 0x277, 0x278, 0x279, + 0x20a, 0x20b, 0x22a, 0x22b, 0x24a, + 0x24b, 0x26a, 0x26b, 0x24e, 0x24f, + 0x21a, 0x21b, 0x23a, 0x23b, 0x25a, + 0x25b, 0x27a, 0x27b, 0x25e, 0x25f, + 0x280, 0x281, 0x282, 0x283, 0x284, + 0x285, 0x286, 0x287, 0x288, 0x289, + 0x290, 0x291, 0x292, 0x293, 0x294, + 0x295, 0x296, 0x297, 0x298, 0x299, + 0x2a0, 0x2a1, 0x2a2, 0x2a3, 0x2a4, + 0x2a5, 0x2a6, 0x2a7, 0x2a8, 0x2a9, + 0x2b0, 0x2b1, 0x2b2, 0x2b3, 0x2b4, + 0x2b5, 0x2b6, 0x2b7, 0x2b8, 0x2b9, + 0x2c0, 0x2c1, 0x2c2, 0x2c3, 0x2c4, + 0x2c5, 0x2c6, 0x2c7, 0x2c8, 0x2c9, + 0x2d0, 0x2d1, 0x2d2, 0x2d3, 0x2d4, + 0x2d5, 0x2d6, 0x2d7, 0x2d8, 0x2d9, + 0x2e0, 0x2e1, 0x2e2, 0x2e3, 0x2e4, + 0x2e5, 0x2e6, 0x2e7, 0x2e8, 0x2e9, + 0x2f0, 0x2f1, 0x2f2, 0x2f3, 0x2f4, + 0x2f5, 0x2f6, 0x2f7, 0x2f8, 0x2f9, + 0x28a, 0x28b, 0x2aa, 0x2ab, 0x2ca, + 0x2cb, 0x2ea, 0x2eb, 0x2ce, 0x2cf, + 0x29a, 0x29b, 0x2ba, 0x2bb, 0x2da, + 0x2db, 0x2fa, 0x2fb, 0x2de, 0x2df, + 0x300, 0x301, 0x302, 0x303, 0x304, + 0x305, 0x306, 0x307, 0x308, 0x309, + 0x310, 0x311, 0x312, 0x313, 0x314, + 0x315, 0x316, 0x317, 0x318, 0x319, + 0x320, 0x321, 0x322, 0x323, 0x324, + 0x325, 0x326, 0x327, 0x328, 0x329, + 0x330, 0x331, 0x332, 0x333, 0x334, + 0x335, 0x336, 0x337, 0x338, 0x339, + 0x340, 0x341, 0x342, 0x343, 0x344, + 0x345, 0x346, 0x347, 0x348, 0x349, + 0x350, 0x351, 0x352, 0x353, 0x354, + 0x355, 0x356, 0x357, 0x358, 0x359, + 0x360, 0x361, 0x362, 0x363, 0x364, + 0x365, 0x366, 0x367, 0x368, 0x369, + 0x370, 0x371, 0x372, 0x373, 0x374, + 0x375, 0x376, 0x377, 0x378, 0x379, + 0x30a, 0x30b, 0x32a, 0x32b, 0x34a, + 0x34b, 0x36a, 0x36b, 0x34e, 0x34f, + 0x31a, 0x31b, 0x33a, 0x33b, 0x35a, + 0x35b, 0x37a, 0x37b, 0x35e, 0x35f, + 0x380, 0x381, 0x382, 0x383, 0x384, + 0x385, 0x386, 0x387, 0x388, 0x389, + 0x390, 0x391, 0x392, 0x393, 0x394, + 0x395, 0x396, 0x397, 0x398, 0x399, + 0x3a0, 0x3a1, 0x3a2, 0x3a3, 0x3a4, + 0x3a5, 0x3a6, 0x3a7, 0x3a8, 0x3a9, + 0x3b0, 0x3b1, 0x3b2, 0x3b3, 0x3b4, + 0x3b5, 0x3b6, 0x3b7, 0x3b8, 0x3b9, + 0x3c0, 0x3c1, 0x3c2, 0x3c3, 0x3c4, + 0x3c5, 0x3c6, 0x3c7, 0x3c8, 0x3c9, + 0x3d0, 0x3d1, 0x3d2, 0x3d3, 0x3d4, + 0x3d5, 0x3d6, 0x3d7, 0x3d8, 0x3d9, + 0x3e0, 0x3e1, 0x3e2, 0x3e3, 0x3e4, + 0x3e5, 0x3e6, 0x3e7, 0x3e8, 0x3e9, + 0x3f0, 0x3f1, 0x3f2, 0x3f3, 0x3f4, + 0x3f5, 0x3f6, 0x3f7, 0x3f8, 0x3f9, + 0x38a, 0x38b, 0x3aa, 0x3ab, 0x3ca, + 0x3cb, 0x3ea, 0x3eb, 0x3ce, 0x3cf, + 0x39a, 0x39b, 0x3ba, 0x3bb, 0x3da, + 0x3db, 0x3fa, 0x3fb, 0x3de, 0x3df, + 0x00c, 0x00d, 0x10c, 0x10d, 0x20c, + 0x20d, 0x30c, 0x30d, 0x02e, 0x02f, + 0x01c, 0x01d, 0x11c, 0x11d, 0x21c, + 0x21d, 0x31c, 0x31d, 0x03e, 0x03f, + 0x02c, 0x02d, 0x12c, 0x12d, 0x22c, + 0x22d, 0x32c, 0x32d, 0x12e, 0x12f, + 0x03c, 0x03d, 0x13c, 0x13d, 0x23c, + 0x23d, 0x33c, 0x33d, 0x13e, 0x13f, + 0x04c, 0x04d, 0x14c, 0x14d, 0x24c, + 0x24d, 0x34c, 0x34d, 0x22e, 0x22f, + 0x05c, 0x05d, 0x15c, 0x15d, 0x25c, + 0x25d, 0x35c, 0x35d, 0x23e, 0x23f, + 0x06c, 0x06d, 0x16c, 0x16d, 0x26c, + 0x26d, 0x36c, 0x36d, 0x32e, 0x32f, + 0x07c, 0x07d, 0x17c, 0x17d, 0x27c, + 0x27d, 0x37c, 0x37d, 0x33e, 0x33f, + 0x00e, 0x00f, 0x10e, 0x10f, 0x20e, + 0x20f, 0x30e, 0x30f, 0x06e, 0x06f, + 0x01e, 0x01f, 0x11e, 0x11f, 0x21e, + 0x21f, 0x31e, 0x31f, 0x07e, 0x07f, + 0x08c, 0x08d, 0x18c, 0x18d, 0x28c, + 0x28d, 0x38c, 0x38d, 0x0ae, 0x0af, + 0x09c, 0x09d, 0x19c, 0x19d, 0x29c, + 0x29d, 0x39c, 0x39d, 0x0be, 0x0bf, + 0x0ac, 0x0ad, 0x1ac, 0x1ad, 0x2ac, + 0x2ad, 0x3ac, 0x3ad, 0x1ae, 0x1af, + 0x0bc, 0x0bd, 0x1bc, 0x1bd, 0x2bc, + 0x2bd, 0x3bc, 0x3bd, 0x1be, 0x1bf, + 0x0cc, 0x0cd, 0x1cc, 0x1cd, 0x2cc, + 0x2cd, 0x3cc, 0x3cd, 0x2ae, 0x2af, + 0x0dc, 0x0dd, 0x1dc, 0x1dd, 0x2dc, + 0x2dd, 0x3dc, 0x3dd, 0x2be, 0x2bf, + 0x0ec, 0x0ed, 0x1ec, 0x1ed, 0x2ec, + 0x2ed, 0x3ec, 0x3ed, 0x3ae, 0x3af, + 0x0fc, 0x0fd, 0x1fc, 0x1fd, 0x2fc, + 0x2fd, 0x3fc, 0x3fd, 0x3be, 0x3bf, + 0x08e, 0x08f, 0x18e, 0x18f, 0x28e, + 0x28f, 0x38e, 0x38f, 0x0ee, 0x0ef, + 0x09e, 0x09f, 0x19e, 0x19f, 0x29e, + 0x29f, 0x39e, 0x39f, 0x0fe, 0x0ff +}; +#endif diff --git a/libgcc/soft-fp/fixddbitint.c b/libgcc/soft-fp/fixddbitint.c index 7b0162e..067a9a6 100644 --- a/libgcc/soft-fp/fixddbitint.c +++ b/libgcc/soft-fp/fixddbitint.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal64 to signed or unsigned _BitInt. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #ifdef __BITINT_MAXWIDTH__ +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixddbitint __dpd_fixddbitint +#endif extern void __bid_fixddbitint (UBILtype *, SItype, _Decimal64); void @@ -48,6 +51,7 @@ __bid_fixddbitint (UBILtype *r, SItype rprec, _Decimal64 a) u.d = a; t = u.u >> 51; sgn = (DItype) u.u < 0; +#ifdef ENABLE_DECIMAL_BID_FORMAT if ((t & (3 << 10)) != (3 << 10)) { mantissa = u.u & ((((UDItype) 1) << 53) - 1); @@ -61,6 +65,31 @@ __bid_fixddbitint (UBILtype *r, SItype rprec, _Decimal64 a) if (mantissa > (UDItype) 9999999999999999) mantissa = 0; } +#else + if ((t & (15 << 8)) != (15 << 8)) + { + exponent = (u.u >> 50) & 255; + if ((t & (3 << 10)) != (3 << 10)) + { + mantissa = ((t >> 7) & 7) * 1000; + exponent += (t >> 2) & (3 << 8); + } + else + { + mantissa = ((t >> 7) & 1) ? 9000 : 8000; + exponent += t & (3 << 8); + } + mantissa += __dpd_d2bbitint[(u.u >> 40) & 1023]; + mantissa *= 1000; + mantissa += __dpd_d2bbitint[(u.u >> 30) & 1023]; + mantissa *= 1000; + mantissa += __dpd_d2bbitint[(u.u >> 20) & 1023]; + mantissa *= 1000; + mantissa += __dpd_d2bbitint[(u.u >> 10) & 1023]; + mantissa *= 1000; + mantissa += __dpd_d2bbitint[u.u & 1023]; + } +#endif else { FP_SET_EXCEPTION (FP_EX_INVALID @@ -162,7 +191,7 @@ __bid_fixddbitint (UBILtype *r, SItype rprec, _Decimal64 a) if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)]) goto ovf_ex; if ((arprec % BIL_TYPE_SIZE) != 0 - && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros] + && (resv[BITINT_END (res_limbs + low_zeros - rn, rn - 1 - low_zeros)] & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0) goto ovf_ex; min_limbs = rn - low_zeros; diff --git a/libgcc/soft-fp/fixddti.c b/libgcc/soft-fp/fixddti.c index c27ae8b..c7b4ad7 100644 --- a/libgcc/soft-fp/fixddti.c +++ b/libgcc/soft-fp/fixddti.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal64 to 128bit signed integer. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixddbitint __dpd_fixddbitint +#define __bid_fixddti __dpd_fixddti +#endif extern void __bid_fixddbitint (UBILtype *, SItype, _Decimal64); extern TItype __bid_fixddti (_Decimal64); diff --git a/libgcc/soft-fp/fixsdbitint.c b/libgcc/soft-fp/fixsdbitint.c index 2ba550f..fc117d9 100644 --- a/libgcc/soft-fp/fixsdbitint.c +++ b/libgcc/soft-fp/fixsdbitint.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal32 to signed or unsigned _BitInt. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #ifdef __BITINT_MAXWIDTH__ +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixsdbitint __dpd_fixsdbitint +#endif extern void __bid_fixsdbitint (UBILtype *, SItype, _Decimal32); void @@ -48,6 +51,7 @@ __bid_fixsdbitint (UBILtype *r, SItype rprec, _Decimal32 a) u.d = a; t = u.u >> 21; sgn = (SItype) u.u < 0; +#ifdef ENABLE_DECIMAL_BID_FORMAT if ((t & (3 << 8)) != (3 << 8)) { mantissa = u.u & ((((USItype) 1) << 23) - 1); @@ -61,6 +65,25 @@ __bid_fixsdbitint (UBILtype *r, SItype rprec, _Decimal32 a) if (mantissa > (USItype) 9999999) mantissa = 0; } +#else + if ((t & (15 << 6)) != (15 << 6)) + { + exponent = (u.u >> 20) & 63; + if ((t & (3 << 8)) != (3 << 8)) + { + mantissa = ((t >> 5) & 7) * 1000; + exponent += (t >> 2) & (3 << 6); + } + else + { + mantissa = ((t >> 5) & 1) ? 9000 : 8000; + exponent += t & (3 << 6); + } + mantissa += __dpd_d2bbitint[(u.u >> 10) & 1023]; + mantissa *= 1000; + mantissa += __dpd_d2bbitint[u.u & 1023]; + } +#endif else { FP_SET_EXCEPTION (FP_EX_INVALID @@ -153,7 +176,7 @@ __bid_fixsdbitint (UBILtype *r, SItype rprec, _Decimal32 a) if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)]) goto ovf_ex; if ((arprec % BIL_TYPE_SIZE) != 0 - && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros] + && (resv[BITINT_END (res_limbs + low_zeros - rn, rn - 1 - low_zeros)] & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0) goto ovf_ex; min_limbs = rn - low_zeros; diff --git a/libgcc/soft-fp/fixsdti.c b/libgcc/soft-fp/fixsdti.c index 8477ace..9a53508 100644 --- a/libgcc/soft-fp/fixsdti.c +++ b/libgcc/soft-fp/fixsdti.c @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixsdbitint __dpd_fixsdbitint +#define __bid_fixsdti __dpd_fixsdti +#endif extern void __bid_fixsdbitint (UBILtype *, SItype, _Decimal32); extern TItype __bid_fixsdti (_Decimal32); diff --git a/libgcc/soft-fp/fixtdbitint.c b/libgcc/soft-fp/fixtdbitint.c index 66aca1c..a16aaab 100644 --- a/libgcc/soft-fp/fixtdbitint.c +++ b/libgcc/soft-fp/fixtdbitint.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal128 to signed or unsigned _BitInt. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #ifdef __BITINT_MAXWIDTH__ +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixtdbitint __dpd_fixtdbitint +#endif extern void __bid_fixtdbitint (UBILtype *, SItype, _Decimal128); void @@ -50,6 +53,7 @@ __bid_fixtdbitint (UBILtype *r, SItype rprec, _Decimal128 a) mantissalo = u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__]; t = mantissahi >> 47; sgn = (DItype) mantissahi < 0; +#ifdef ENABLE_DECIMAL_BID_FORMAT if ((t & (3 << 14)) != (3 << 14)) { mantissahi &= ((((UDItype) 1) << 49) - 1); @@ -68,6 +72,52 @@ __bid_fixtdbitint (UBILtype *r, SItype rprec, _Decimal128 a) mantissalo = 0; exponent = t & 0x3fff; } +#else + if ((t & (15 << 12)) != (15 << 12)) + { + exponent = (mantissahi >> 46) & 4095; + if ((t & (3 << 14)) != (3 << 14)) + { + exponent += (t >> 2) & (3 << 12); + t = ((t >> 11) & 7) * 1000; + } + else + { + exponent += t & (3 << 12); + t = ((t >> 11) & 1) ? 9000 : 8000; + } + t += __dpd_d2bbitint[(mantissahi >> (100 - 64)) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[(mantissahi >> (90 - 64)) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[(mantissahi >> (80 - 64)) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[(mantissahi >> (70 - 64)) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[((mantissahi & 63) << 4) + + ((mantissalo >> 60) & 15)]; + t *= 1000; + t += __dpd_d2bbitint[mantissalo >> 50 & 1023]; +#ifdef __SIZEOF_INT128__ + unsigned __int128 m = t; +#else + unsigned _BitInt(128) m = t; +#endif + m *= 1000000000000000ULL; + t = __dpd_d2bbitint[(mantissalo >> 40) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[(mantissalo >> 30) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[(mantissalo >> 20) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[(mantissalo >> 10) & 1023]; + t *= 1000; + t += __dpd_d2bbitint[mantissalo & 1023]; + m += t; + mantissahi = m >> 64; + mantissalo = m; + } +#endif else { FP_SET_EXCEPTION (FP_EX_INVALID @@ -199,7 +249,7 @@ __bid_fixtdbitint (UBILtype *r, SItype rprec, _Decimal128 a) if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)]) goto ovf_ex; if ((arprec % BIL_TYPE_SIZE) != 0 - && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros] + && (resv[BITINT_END (res_limbs + low_zeros - rn, rn - 1 - low_zeros)] & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0) goto ovf_ex; min_limbs = rn - low_zeros; diff --git a/libgcc/soft-fp/fixtdti.c b/libgcc/soft-fp/fixtdti.c index 9ac1333..ee26f26 100644 --- a/libgcc/soft-fp/fixtdti.c +++ b/libgcc/soft-fp/fixtdti.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal128 to 128bit signed integer. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixtdbitint __dpd_fixtdbitint +#define __bid_fixtdti __dpd_fixtdti +#endif extern void __bid_fixtdbitint (UBILtype *, SItype, _Decimal128); extern TItype __bid_fixtdti (_Decimal128); diff --git a/libgcc/soft-fp/fixunsddti.c b/libgcc/soft-fp/fixunsddti.c index 7551e00..b7a4a80 100644 --- a/libgcc/soft-fp/fixunsddti.c +++ b/libgcc/soft-fp/fixunsddti.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal64 to 128bit unsigned integer. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixddbitint __dpd_fixddbitint +#define __bid_fixunsddti __dpd_fixunsddti +#endif extern void __bid_fixddbitint (UBILtype *, SItype, _Decimal64); extern UTItype __bid_fixunsddti (_Decimal64); diff --git a/libgcc/soft-fp/fixunssdti.c b/libgcc/soft-fp/fixunssdti.c index 8d71b2c..3425c29 100644 --- a/libgcc/soft-fp/fixunssdti.c +++ b/libgcc/soft-fp/fixunssdti.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal32 to 128bit unsigned integer. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixsdbitint __dpd_fixsdbitint +#define __bid_fixunssdti __dpd_fixunssdti +#endif extern void __bid_fixsdbitint (UBILtype *, SItype, _Decimal32); extern UTItype __bid_fixunssdti (_Decimal32); diff --git a/libgcc/soft-fp/fixunstdti.c b/libgcc/soft-fp/fixunstdti.c index 41ae974..d63ec2b 100644 --- a/libgcc/soft-fp/fixunstdti.c +++ b/libgcc/soft-fp/fixunstdti.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert _Decimal128 to 128bit unsigned integer. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_fixtdbitint __dpd_fixtdbitint +#define __bid_fixunstdti __dpd_fixunstdti +#endif extern void __bid_fixtdbitint (UBILtype *, SItype, _Decimal128); extern UTItype __bid_fixunstdti (_Decimal128); diff --git a/libgcc/soft-fp/floatbitintdd.c b/libgcc/soft-fp/floatbitintdd.c index 4565572..0547bb5 100644 --- a/libgcc/soft-fp/floatbitintdd.c +++ b/libgcc/soft-fp/floatbitintdd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a _BitInt to _Decimal64. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #ifdef __BITINT_MAXWIDTH__ +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitintdd __dpd_floatbitintdd +#endif extern _Decimal64 __bid_floatbitintdd (const UBILtype *, SItype); _Decimal64 @@ -51,7 +54,11 @@ __bid_floatbitintdd (const UBILtype *i, SItype iprec) } if (iprec < 0) { - SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb); + SItype n; + if (msb == ~(UBILtype) 0) + n = 1; + else + n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb); aiprec = (in - 1) * BIL_TYPE_SIZE + n; } else if (msb == 0) @@ -118,7 +125,8 @@ __bid_floatbitintdd (const UBILtype *i, SItype iprec) } else { - __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i, + __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), + i + BITINT_END (1, 0), (in - 1) * sizeof (UBILtype)); buf[BITINT_END (q_limbs - in, in - 1)] = msb; if (iprec < 0) @@ -239,6 +247,7 @@ __bid_floatbitintdd (const UBILtype *i, SItype iprec) } exponent += 398; +#ifdef ENABLE_DECIMAL_BID_FORMAT if (mantissa >= (UDItype) 0x20000000000000) u.u = (((((iprec < 0) << 2) | (UDItype) 3) << 61) | (((UDItype) exponent) << 51) @@ -247,10 +256,40 @@ __bid_floatbitintdd (const UBILtype *i, SItype iprec) u.u = ((((UDItype) (iprec < 0)) << 63) | (((UDItype) exponent) << 53) | mantissa); +#else + u.u = mantissa; + mantissa = __dpd_b2dbitint[u.u % 1000]; + u.u /= 1000; + mantissa |= ((UDItype) __dpd_b2dbitint[u.u % 1000]) << 10; + u.u /= 1000; + mantissa |= ((UDItype) __dpd_b2dbitint[u.u % 1000]) << 20; + u.u /= 1000; + mantissa |= ((UDItype) __dpd_b2dbitint[u.u % 1000]) << 30; + u.u /= 1000; + mantissa |= ((UDItype) __dpd_b2dbitint[u.u % 1000]) << 40; + u.u /= 1000; + if (u.u >= 8) + u.u = (((((iprec < 0) << 2) | (UDItype) 3) << 61) + | (((UDItype) exponent & (3 << 8)) << 51) + | ((u.u & 1) << 58) + | (((UDItype) exponent & 255) << 50) + | mantissa); + else + u.u = ((((UDItype) (iprec < 0)) << 63) + | (((UDItype) exponent & (3 << 8)) << 53) + | (u.u << 58) + | (((UDItype) exponent & 255) << 50) + | mantissa); +#endif if (inexact) { ui.u = ((((UDItype) (iprec < 0)) << 63) +#ifdef ENABLE_DECIMAL_BID_FORMAT | (((UDItype) (exponent - 1)) << 53) +#else + | (((UDItype) (exponent - 1) & (3 << 8)) << 53) + | (((UDItype) (exponent - 1) & 255) << 50) +#endif | (inexact + 3)); __asm ("" : "+g" (u.d)); __asm ("" : "+g" (ui.d)); diff --git a/libgcc/soft-fp/floatbitintsd.c b/libgcc/soft-fp/floatbitintsd.c index 4901aa8..915f46c 100644 --- a/libgcc/soft-fp/floatbitintsd.c +++ b/libgcc/soft-fp/floatbitintsd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a _BitInt to _Decimal32. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #ifdef __BITINT_MAXWIDTH__ +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitintsd __dpd_floatbitintsd +#endif extern _Decimal32 __bid_floatbitintsd (const UBILtype *, SItype); _Decimal32 @@ -51,7 +54,11 @@ __bid_floatbitintsd (const UBILtype *i, SItype iprec) } if (iprec < 0) { - SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb); + SItype n; + if (msb == ~(UBILtype) 0) + n = 1; + else + n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb); aiprec = (in - 1) * BIL_TYPE_SIZE + n; } else if (msb == 0) @@ -117,7 +124,8 @@ __bid_floatbitintsd (const UBILtype *i, SItype iprec) } else { - __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i, + __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), + i + BITINT_END (1, 0), (in - 1) * sizeof (UBILtype)); buf[BITINT_END (q_limbs - in, in - 1)] = msb; if (iprec < 0) @@ -210,6 +218,7 @@ __bid_floatbitintsd (const UBILtype *i, SItype iprec) } exponent += 101; +#ifdef ENABLE_DECIMAL_BID_FORMAT if (mantissa >= (USItype) 0x800000) u.u = (((((iprec < 0) << 2) | (USItype) 3) << 29) | (((USItype) exponent) << 21) @@ -218,10 +227,34 @@ __bid_floatbitintsd (const UBILtype *i, SItype iprec) u.u = ((((USItype) (iprec < 0)) << 31) | (((USItype) exponent) << 23) | mantissa); +#else + u.u = mantissa; + mantissa = __dpd_b2dbitint[u.u % 1000]; + u.u /= 1000; + mantissa |= ((USItype) __dpd_b2dbitint[u.u % 1000]) << 10; + u.u /= 1000; + if (u.u >= 8) + u.u = (((((iprec < 0) << 2) | (USItype) 3) << 29) + | (((USItype) exponent & (3 << 6)) << 21) + | ((u.u & 1) << 26) + | (((USItype) exponent & 63) << 20) + | mantissa); + else + u.u = ((((USItype) (iprec < 0)) << 31) + | (((USItype) exponent & (3 << 6)) << 23) + | (u.u << 26) + | (((USItype) exponent & 63) << 20) + | mantissa); +#endif if (inexact) { ui.u = ((((USItype) (iprec < 0)) << 31) +#ifdef ENABLE_DECIMAL_BID_FORMAT | (((USItype) (exponent - 1)) << 23) +#else + | (((USItype) (exponent - 1) & (3 << 6)) << 23) + | (((USItype) (exponent - 1) & 63) << 20) +#endif | (inexact + 3)); __asm ("" : "+g" (u.d)); __asm ("" : "+g" (ui.d)); diff --git a/libgcc/soft-fp/floatbitinttd.c b/libgcc/soft-fp/floatbitinttd.c index 5fff339..50b9e77 100644 --- a/libgcc/soft-fp/floatbitinttd.c +++ b/libgcc/soft-fp/floatbitinttd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a _BitInt to _Decimal128. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #ifdef __BITINT_MAXWIDTH__ +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitinttd __dpd_floatbitinttd +#endif extern _Decimal128 __bid_floatbitinttd (const UBILtype *, SItype); _Decimal128 @@ -51,7 +54,11 @@ __bid_floatbitinttd (const UBILtype *i, SItype iprec) } if (iprec < 0) { - SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb); + SItype n; + if (msb == ~(UBILtype) 0) + n = 1; + else + n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb); aiprec = (in - 1) * BIL_TYPE_SIZE + n; } else if (msb == 0) @@ -117,7 +124,8 @@ __bid_floatbitinttd (const UBILtype *i, SItype iprec) } else { - __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i, + __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), + i + BITINT_END (1, 0), (in - 1) * sizeof (UBILtype)); buf[BITINT_END (q_limbs - in, in - 1)] = msb; if (iprec < 0) @@ -253,15 +261,69 @@ __bid_floatbitinttd (const UBILtype *i, SItype iprec) } exponent += 6176; +#ifdef ENABLE_DECIMAL_BID_FORMAT u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__] = ((((UDItype) (iprec < 0)) << 63) | (((UDItype) exponent) << 49) | mantissahi); +#else +#ifdef __SIZEOF_INT128__ + unsigned __int128 m = mantissahi; +#else + unsigned _BitInt(128) m = mantissahi; +#endif + m = (m << 64) | mantissalo; + u.u[0] = m / 1000000000000000ULL; + u.u[1] = m % 1000000000000000ULL; + mantissalo = __dpd_b2dbitint[u.u[1] % 1000]; + u.u[1] /= 1000; + mantissalo |= ((UDItype) __dpd_b2dbitint[u.u[1] % 1000]) << 10; + u.u[1] /= 1000; + mantissalo |= ((UDItype) __dpd_b2dbitint[u.u[1] % 1000]) << 20; + u.u[1] /= 1000; + mantissalo |= ((UDItype) __dpd_b2dbitint[u.u[1] % 1000]) << 30; + u.u[1] /= 1000; + mantissalo |= ((UDItype) __dpd_b2dbitint[u.u[1] % 1000]) << 40; + mantissalo |= ((UDItype) __dpd_b2dbitint[u.u[0] % 1000]) << 50; + u.u[0] /= 1000; + mantissahi = __dpd_b2dbitint[u.u[0] % 1000]; + u.u[0] /= 1000; + mantissalo |= mantissahi << 60; + mantissahi >>= 4; + mantissahi |= ((UDItype) __dpd_b2dbitint[u.u[0] % 1000]) << 6; + u.u[0] /= 1000; + mantissahi |= ((UDItype) __dpd_b2dbitint[u.u[0] % 1000]) << 16; + u.u[0] /= 1000; + mantissahi |= ((UDItype) __dpd_b2dbitint[u.u[0] % 1000]) << 26; + u.u[0] /= 1000; + mantissahi |= ((UDItype) __dpd_b2dbitint[u.u[0] % 1000]) << 36; + u.u[0] /= 1000; + if (u.u[0] >= 8) + u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__] + = (((((iprec < 0) << 2) | (UDItype) 3) << 61) + | (((UDItype) exponent & (3 << 12)) << 47) + | ((u.u[0] & 1) << 58) + | (((UDItype) exponent & 4095) << 46) + | mantissahi); + else + u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__] + = ((((UDItype) (iprec < 0)) << 63) + | (((UDItype) exponent & (3 << 12)) << 49) + | (u.u[0] << 58) + | (((UDItype) exponent & 4095) << 46) + | mantissahi); +#endif u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__] = mantissalo; if (inexact) { ui.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__] +#ifdef ENABLE_DECIMAL_BID_FORMAT = (((UDItype) (iprec < 0)) << 63) | (((UDItype) exponent - 1) << 49); +#else + = ((((UDItype) (iprec < 0)) << 63) + | ((((UDItype) exponent - 1) & (3 << 12)) << 49) + | ((((UDItype) exponent - 1) & 4095) << 46)); +#endif ui.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__] = inexact + 3; __asm ("" : "+g" (u.d)); __asm ("" : "+g" (ui.d)); diff --git a/libgcc/soft-fp/floattidd.c b/libgcc/soft-fp/floattidd.c index 31ad9d0..c4e569d 100644 --- a/libgcc/soft-fp/floattidd.c +++ b/libgcc/soft-fp/floattidd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a 128bit signed integer to _Decimal64. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitintdd __dpd_floatbitintdd +#define __bid_floattidd __dpd_floattidd +#endif extern _Decimal64 __bid_floatbitintdd (const UBILtype *, SItype); extern _Decimal64 __bid_floattidd (TItype); diff --git a/libgcc/soft-fp/floattisd.c b/libgcc/soft-fp/floattisd.c index 37a24a3..641c32a 100644 --- a/libgcc/soft-fp/floattisd.c +++ b/libgcc/soft-fp/floattisd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a 128bit signed integer to _Decimal32. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitintsd __dpd_floatbitintsd +#define __bid_floattisd __dpd_floattisd +#endif extern _Decimal32 __bid_floatbitintsd (const UBILtype *, SItype); extern _Decimal32 __bid_floattisd (TItype); diff --git a/libgcc/soft-fp/floattitd.c b/libgcc/soft-fp/floattitd.c index edc0b37..9d10ed7 100644 --- a/libgcc/soft-fp/floattitd.c +++ b/libgcc/soft-fp/floattitd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a 128bit signed integer to _Decimal128. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitinttd __dpd_floatbitinttd +#define __bid_floattitd __dpd_floattitd +#endif extern _Decimal128 __bid_floatbitinttd (const UBILtype *, SItype); extern _Decimal128 __bid_floattitd (TItype); diff --git a/libgcc/soft-fp/floatuntidd.c b/libgcc/soft-fp/floatuntidd.c index ea4108f..f977400 100644 --- a/libgcc/soft-fp/floatuntidd.c +++ b/libgcc/soft-fp/floatuntidd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a 128bit unsigned integer to _Decimal64. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitintdd __dpd_floatbitintdd +#define __bid_floatunstidd __dpd_floatunstidd +#endif extern _Decimal64 __bid_floatbitintdd (const UBILtype *, SItype); extern _Decimal64 __bid_floatunstidd (UTItype); diff --git a/libgcc/soft-fp/floatuntisd.c b/libgcc/soft-fp/floatuntisd.c index d907353e..cc00d83 100644 --- a/libgcc/soft-fp/floatuntisd.c +++ b/libgcc/soft-fp/floatuntisd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a 128bit unsigned integer to _Decimal32. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitintsd __dpd_floatbitintsd +#define __bid_floatunstisd __dpd_floatunstisd +#endif extern _Decimal32 __bid_floatbitintsd (const UBILtype *, SItype); extern _Decimal32 __bid_floatunstisd (UTItype); diff --git a/libgcc/soft-fp/floatuntitd.c b/libgcc/soft-fp/floatuntitd.c index 5731f2a..551166e 100644 --- a/libgcc/soft-fp/floatuntitd.c +++ b/libgcc/soft-fp/floatuntitd.c @@ -1,7 +1,7 @@ /* Software floating-point emulation. Convert a 128bit unsigned integer to _Decimal128. - Copyright (C) 2023 Free Software Foundation, Inc. + Copyright (C) 2023-2025 Free Software Foundation, Inc. This file is part of GCC. @@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "bitint.h" #if defined(__BITINT_MAXWIDTH__) && defined(__SIZEOF_INT128__) +#ifndef ENABLE_DECIMAL_BID_FORMAT +#define __bid_floatbitinttd __dpd_floatbitinttd +#define __bid_floatunstitd __dpd_floatunstitd +#endif extern _Decimal128 __bid_floatbitinttd (const UBILtype *, SItype); extern _Decimal128 __bid_floatunstitd (UTItype); |
