diff -Nrcpad gcc-14-20250822/LAST_UPDATED gcc-14-20250829/LAST_UPDATED
*** gcc-14-20250822/LAST_UPDATED	Fri Aug 22 22:33:21 2025
--- gcc-14-20250829/LAST_UPDATED	Fri Aug 29 22:33:06 2025
***************
*** 1 ****
! Obtained from git: releases/gcc-14 revision 087fe1daf1024c3d481b708c40cf47cc26b06a3a
--- 1 ----
! Obtained from git: releases/gcc-14 revision e645728e9de64d019661c8f92bb487e06d95644a
diff -Nrcpad gcc-14-20250822/MD5SUMS gcc-14-20250829/MD5SUMS
*** gcc-14-20250822/MD5SUMS	Fri Aug 22 22:33:24 2025
--- gcc-14-20250829/MD5SUMS	Fri Aug 29 22:33:13 2025
***************
*** 1,5 ****
  # This file contains the MD5 checksums of the files in the
! # gcc-14-20250822.tar.xz tarball.
  #
  # Besides verifying that all files in the tarball were correctly expanded,
  # it also can be used to determine if any files have changed since the
--- 1,5 ----
  # This file contains the MD5 checksums of the files in the
! # gcc-14-20250829.tar.xz tarball.
  #
  # Besides verifying that all files in the tarball were correctly expanded,
  # it also can be used to determine if any files have changed since the
*************** fc9280b02bc68e4fb1ef8d51ccc25061  Change
*** 23,29 ****
  fd4ecdf5d672efe2b0e409aca9cf9446  ChangeLog.jit
  09538b708302f1735f6fa05b622ecf5e  ChangeLog.tree-ssa
  24ab760126489e69436a43185dc3d202  INSTALL/README
! 07c410d5ea030ab1420edebb9ca57815  LAST_UPDATED
  1671040823f8eb8436a06fdd18065e02  MAINTAINERS
  304c3887135aefa27c21292ec585b0a3  Makefile.def
  8dd93fbf2e32bcbd2faba10e3b8ba2b0  Makefile.in
--- 23,29 ----
  fd4ecdf5d672efe2b0e409aca9cf9446  ChangeLog.jit
  09538b708302f1735f6fa05b622ecf5e  ChangeLog.tree-ssa
  24ab760126489e69436a43185dc3d202  INSTALL/README
! f57189c0bfda32af2ef13efd96d5043d  LAST_UPDATED
  1671040823f8eb8436a06fdd18065e02  MAINTAINERS
  304c3887135aefa27c21292ec585b0a3  Makefile.def
  8dd93fbf2e32bcbd2faba10e3b8ba2b0  Makefile.in
*************** fb3fadb88e1d2b3b640cfaaa5ff11780  gcc/Ch
*** 541,547 ****
  3eb07e0b2e542409bf73d359f7f65609  gcc/ChangeLog.ptr
  e13638e26743ba41e6011b76cc00d9a9  gcc/ChangeLog.tree-ssa
  739ab47f6425bcea1d05e4fc0542de54  gcc/ChangeLog.tuples
! d1812ce45d0c994da4c17dc4dbf7e6d3  gcc/DATESTAMP
  d41d8cd98f00b204e9800998ecf8427e  gcc/DEV-PHASE
  eb92e1ff5e982ca07e173e0eb286d243  gcc/FSFChangeLog
  30e1e33411566388b3164558482dc5e6  gcc/FSFChangeLog.10
--- 541,547 ----
  3eb07e0b2e542409bf73d359f7f65609  gcc/ChangeLog.ptr
  e13638e26743ba41e6011b76cc00d9a9  gcc/ChangeLog.tree-ssa
  739ab47f6425bcea1d05e4fc0542de54  gcc/ChangeLog.tuples
! b31ed24229fa9d0b9db7d2b7b65fce34  gcc/DATESTAMP
  d41d8cd98f00b204e9800998ecf8427e  gcc/DEV-PHASE
  eb92e1ff5e982ca07e173e0eb286d243  gcc/FSFChangeLog
  30e1e33411566388b3164558482dc5e6  gcc/FSFChangeLog.10
*************** dce7dac7e905ada28c6563d930b531eb  gcc/fo
*** 5872,5878 ****
  090850db6c719557b18e35fafc041a4c  gcc/fold-const.cc
  62f9c541bc34eb653f289ecd29c7848a  gcc/fold-const.h
  5cce8057cb6a40c0ce23fcd6497d35c0  gcc/fold-mem-offsets.cc
! 2d4d77e802cbfc2c1f47e23261ce6c3d  gcc/fortran/ChangeLog
  3330102ad3a0217cba963be6b5eefd58  gcc/fortran/ChangeLog-2002
  d000ab985b1eeb1ad5749f98b8fef99f  gcc/fortran/ChangeLog-2003
  bf42f94f0c51dcc7d8051cc7fda1efdc  gcc/fortran/ChangeLog-2004
--- 5872,5878 ----
  090850db6c719557b18e35fafc041a4c  gcc/fold-const.cc
  62f9c541bc34eb653f289ecd29c7848a  gcc/fold-const.h
  5cce8057cb6a40c0ce23fcd6497d35c0  gcc/fold-mem-offsets.cc
! b9ebbcb3695e3e356b3316ebafde4d58  gcc/fortran/ChangeLog
  3330102ad3a0217cba963be6b5eefd58  gcc/fortran/ChangeLog-2002
  d000ab985b1eeb1ad5749f98b8fef99f  gcc/fortran/ChangeLog-2003
  bf42f94f0c51dcc7d8051cc7fda1efdc  gcc/fortran/ChangeLog-2004
*************** e8a9eb01b9451a357155e7152df1c669  gcc/ta
*** 8060,8066 ****
  a05663c52c607143c607d3ecf1391979  gcc/targhooks.cc
  51d240e574a3f9ecec346d64a04ac634  gcc/targhooks.h
  f39fcaa8197187283ccfed40107b426d  gcc/testsuite/.gitattributes
! 30c8778369d85a4dbed5ebd2b91247f0  gcc/testsuite/ChangeLog
  862f04afbd87da2cc6bc432c3f28430f  gcc/testsuite/ChangeLog-1993-2007
  029a5d8dacd25eb5d4711452ac448e5b  gcc/testsuite/ChangeLog-2008
  13ac28c41d51b66b4ec40dba6bd50f39  gcc/testsuite/ChangeLog-2009
--- 8060,8066 ----
  a05663c52c607143c607d3ecf1391979  gcc/targhooks.cc
  51d240e574a3f9ecec346d64a04ac634  gcc/targhooks.h
  f39fcaa8197187283ccfed40107b426d  gcc/testsuite/.gitattributes
! d2d5968f9f30208c1e776752bf45f54d  gcc/testsuite/ChangeLog
  862f04afbd87da2cc6bc432c3f28430f  gcc/testsuite/ChangeLog-1993-2007
  029a5d8dacd25eb5d4711452ac448e5b  gcc/testsuite/ChangeLog-2008
  13ac28c41d51b66b4ec40dba6bd50f39  gcc/testsuite/ChangeLog-2009
*************** b912addc770944f54b5baa8db2467d9d  gcc/te
*** 75232,75237 ****
--- 75232,75238 ----
  c87152a8a84d546309327b3da89eb566  gcc/testsuite/gcc.target/i386/pr120427-3.c
  f5a1252b1fe24ea2b97ff3762c399ed9  gcc/testsuite/gcc.target/i386/pr120427-4.c
  16984aa55364473d08d90334f60bf59e  gcc/testsuite/gcc.target/i386/pr120427-5.c
+ 42f04e2f72a90bf2d17b50fc75ebd985  gcc/testsuite/gcc.target/i386/pr120691.c
  e33b63cd8f6d60b286b2286424f25714  gcc/testsuite/gcc.target/i386/pr120908.c
  b03b1d817538a863277c823b5e4cdf75  gcc/testsuite/gcc.target/i386/pr12092-1.c
  06cf62e068f23c847b4e4ce15a37d992  gcc/testsuite/gcc.target/i386/pr121208-1a.c
*************** bfef0c39d2e18e1590bf85f6afaaf9c2  libgcc
*** 111833,111839 ****
  e836871902e82a5e376bdd0794f0beab  libgcc/config/libbid/bid128_2_str_tables.c
  4ae2e9585f7f68e0fbf01d51287ee599  libgcc/config/libbid/bid128_add.c
  afd6e2e596fa685d0a1669cde95a2097  libgcc/config/libbid/bid128_compare.c
! edd3de8d977c5e231a0ac0f5f1d5338f  libgcc/config/libbid/bid128_div.c
  ebb538d19872d8a99961ff5bff534910  libgcc/config/libbid/bid128_fma.c
  b4411cdd1a08d141bc293d73b476350f  libgcc/config/libbid/bid128_logb.c
  618b888d97b3e477f9ec7a3aeaecced4  libgcc/config/libbid/bid128_minmax.c
--- 111834,111840 ----
  e836871902e82a5e376bdd0794f0beab  libgcc/config/libbid/bid128_2_str_tables.c
  4ae2e9585f7f68e0fbf01d51287ee599  libgcc/config/libbid/bid128_add.c
  afd6e2e596fa685d0a1669cde95a2097  libgcc/config/libbid/bid128_compare.c
! 11471081781702f652df5b1d0b066690  libgcc/config/libbid/bid128_div.c
  ebb538d19872d8a99961ff5bff534910  libgcc/config/libbid/bid128_fma.c
  b4411cdd1a08d141bc293d73b476350f  libgcc/config/libbid/bid128_logb.c
  618b888d97b3e477f9ec7a3aeaecced4  libgcc/config/libbid/bid128_minmax.c
*************** b4411cdd1a08d141bc293d73b476350f  libgcc
*** 111841,111850 ****
  685109e3f821d2308e75eabd60b7cff4  libgcc/config/libbid/bid128_next.c
  59fb6c8023e798913180f27b241843ef  libgcc/config/libbid/bid128_noncomp.c
  21c548973d660b86b45f2a4d01332512  libgcc/config/libbid/bid128_quantize.c
! 00d8651e2b007712cca40554215bc45a  libgcc/config/libbid/bid128_rem.c
  689924f7cf7e2db168f7e6a0e32592c6  libgcc/config/libbid/bid128_round_integral.c
  3e035478ac31ad563c4529f4e94b661e  libgcc/config/libbid/bid128_scalb.c
! 633fa66d23625a4de253c7728f727b2a  libgcc/config/libbid/bid128_sqrt.c
  fbb52269b4b1898aa3503298d3df8504  libgcc/config/libbid/bid128_string.c
  87935a519781386dadc978f45d99baa9  libgcc/config/libbid/bid128_to_int16.c
  1fa58480e7ba615dec06172276b43faf  libgcc/config/libbid/bid128_to_int32.c
--- 111842,111851 ----
  685109e3f821d2308e75eabd60b7cff4  libgcc/config/libbid/bid128_next.c
  59fb6c8023e798913180f27b241843ef  libgcc/config/libbid/bid128_noncomp.c
  21c548973d660b86b45f2a4d01332512  libgcc/config/libbid/bid128_quantize.c
! 8a8cada3474170d7be5d2a4949e5decc  libgcc/config/libbid/bid128_rem.c
  689924f7cf7e2db168f7e6a0e32592c6  libgcc/config/libbid/bid128_round_integral.c
  3e035478ac31ad563c4529f4e94b661e  libgcc/config/libbid/bid128_scalb.c
! dc5fcacfe386435130cf443bc410cc77  libgcc/config/libbid/bid128_sqrt.c
  fbb52269b4b1898aa3503298d3df8504  libgcc/config/libbid/bid128_string.c
  87935a519781386dadc978f45d99baa9  libgcc/config/libbid/bid128_to_int16.c
  1fa58480e7ba615dec06172276b43faf  libgcc/config/libbid/bid128_to_int32.c
*************** e69ac31751a696953bcee1735bef9232  libgcc
*** 111858,111864 ****
  7b86f0cda7f0ee44ae4ea9111df00225  libgcc/config/libbid/bid32_to_bid64.c
  ad0c7c07db8339ffb3d1941979e21691  libgcc/config/libbid/bid64_add.c
  5410490c806940016bcd18ec6f4e3b68  libgcc/config/libbid/bid64_compare.c
! 85706083cbcefdb982ae020a1b1d6c66  libgcc/config/libbid/bid64_div.c
  491fd7d68c1561e03c72183da257192a  libgcc/config/libbid/bid64_fma.c
  53c0af598ef8fef16cd6e60a76f46ba5  libgcc/config/libbid/bid64_logb.c
  c18adb58481dd52323c1699ca70eae22  libgcc/config/libbid/bid64_minmax.c
--- 111859,111865 ----
  7b86f0cda7f0ee44ae4ea9111df00225  libgcc/config/libbid/bid32_to_bid64.c
  ad0c7c07db8339ffb3d1941979e21691  libgcc/config/libbid/bid64_add.c
  5410490c806940016bcd18ec6f4e3b68  libgcc/config/libbid/bid64_compare.c
! c58f910498e37d7a5793eb4a0804a26f  libgcc/config/libbid/bid64_div.c
  491fd7d68c1561e03c72183da257192a  libgcc/config/libbid/bid64_fma.c
  53c0af598ef8fef16cd6e60a76f46ba5  libgcc/config/libbid/bid64_logb.c
  c18adb58481dd52323c1699ca70eae22  libgcc/config/libbid/bid64_minmax.c
*************** c18adb58481dd52323c1699ca70eae22  libgcc
*** 111869,111875 ****
  1f540678e9e06f95f1f6e8a93d94be63  libgcc/config/libbid/bid64_rem.c
  6d0d318399debc04c93d5fc037e9e377  libgcc/config/libbid/bid64_round_integral.c
  c673253ed935f365ac12a9d23267789c  libgcc/config/libbid/bid64_scalb.c
! 084154ce854be3982cff3d9ca55f1eb6  libgcc/config/libbid/bid64_sqrt.c
  605ff6e92d6c6d4ec1267e12bec6e5e5  libgcc/config/libbid/bid64_string.c
  5730f7689c31dfe1daef0f3918a022dc  libgcc/config/libbid/bid64_to_bid128.c
  18aef3e86c68de5a72b30ba1dae529ca  libgcc/config/libbid/bid64_to_int16.c
--- 111870,111876 ----
  1f540678e9e06f95f1f6e8a93d94be63  libgcc/config/libbid/bid64_rem.c
  6d0d318399debc04c93d5fc037e9e377  libgcc/config/libbid/bid64_round_integral.c
  c673253ed935f365ac12a9d23267789c  libgcc/config/libbid/bid64_scalb.c
! 521322e263c671f1414f58c5615ae24c  libgcc/config/libbid/bid64_sqrt.c
  605ff6e92d6c6d4ec1267e12bec6e5e5  libgcc/config/libbid/bid64_string.c
  5730f7689c31dfe1daef0f3918a022dc  libgcc/config/libbid/bid64_to_bid128.c
  18aef3e86c68de5a72b30ba1dae529ca  libgcc/config/libbid/bid64_to_int16.c
diff -Nrcpad gcc-14-20250822/gcc/DATESTAMP gcc-14-20250829/gcc/DATESTAMP
*** gcc-14-20250822/gcc/DATESTAMP	Fri Aug 22 22:32:19 2025
--- gcc-14-20250829/gcc/DATESTAMP	Fri Aug 29 22:32:13 2025
***************
*** 1 ****
! 20250822
--- 1 ----
! 20250829
diff -Nrcpad gcc-14-20250822/gcc/fortran/ChangeLog gcc-14-20250829/gcc/fortran/ChangeLog
*** gcc-14-20250822/gcc/fortran/ChangeLog	Fri Aug 22 22:32:20 2025
--- gcc-14-20250829/gcc/fortran/ChangeLog	Fri Aug 29 22:32:14 2025
***************
*** 1,3 ****
--- 1,29 ----
+ 2025-08-22  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	Backported from master:
+ 	2025-07-18  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	PR fortran/121145
+ 	* trans-expr.cc (gfc_conv_procedure_call): Do not create pointer
+ 	check for proc-pointer actual passed to optional dummy.
+ 
+ 2025-08-22  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	Backported from master:
+ 	2025-06-27  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	PR fortran/120784
+ 	* interface.cc (gfc_match_end_interface): Detect empty local_name.
+ 
+ 2025-08-22  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	Backported from master:
+ 	2025-06-23  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	PR fortran/120784
+ 	* interface.cc (gfc_match_end_interface): If a use-associated
+ 	symbol is renamed, use the local_name for checking.
+ 
  2025-07-16  Paul Thomas  <pault@gcc.gnu.org>
  
  	Backported from master:
diff -Nrcpad gcc-14-20250822/gcc/testsuite/ChangeLog gcc-14-20250829/gcc/testsuite/ChangeLog
*** gcc-14-20250822/gcc/testsuite/ChangeLog	Fri Aug 22 22:32:21 2025
--- gcc-14-20250829/gcc/testsuite/ChangeLog	Fri Aug 29 22:32:16 2025
***************
*** 1,3 ****
--- 1,27 ----
+ 2025-08-22  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	Backported from master:
+ 	2025-07-18  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	PR fortran/121145
+ 	* gfortran.dg/pointer_check_15.f90: New test.
+ 
+ 2025-08-22  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	Backported from master:
+ 	2025-06-27  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	PR fortran/120784
+ 	* gfortran.dg/interface_63.f90: Extend testcase.
+ 
+ 2025-08-22  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	Backported from master:
+ 	2025-06-23  Harald Anlauf  <anlauf@gmx.de>
+ 
+ 	PR fortran/120784
+ 	* gfortran.dg/interface_63.f90: New test.
+ 
  2025-08-20  Martin Jambor  <mjambor@suse.cz>
  
  	Backported from master:
diff -Nrcpad gcc-14-20250822/gcc/testsuite/gcc.target/i386/pr120691.c gcc-14-20250829/gcc/testsuite/gcc.target/i386/pr120691.c
*** gcc-14-20250822/gcc/testsuite/gcc.target/i386/pr120691.c	Thu Jan  1 00:00:00 1970
--- gcc-14-20250829/gcc/testsuite/gcc.target/i386/pr120691.c	Fri Aug 29 22:32:20 2025
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do run { target { ! ia32 } } } */
+ /* { dg-options "-O0 -mfpmath=sse" } */
+ /* { dg-require-effective-target fenv } */
+ /* { dg-require-effective-target dfp } */
+ 
+ #include <fenv.h>
+ 
+ int   main()   {
+   fesetround( FE_UPWARD );
+   _Decimal128   x1 =  9825,  x2 =  10000 ;
+ 
+   double c = (double) (x1 / x2);
+ 
+   if (c != 0.9825)
+     __builtin_abort ();
+ 
+   return   0 ;
+ }
diff -Nrcpad gcc-14-20250822/libgcc/config/libbid/bid128_div.c gcc-14-20250829/libgcc/config/libbid/bid128_div.c
*** gcc-14-20250822/libgcc/config/libbid/bid128_div.c	Fri Aug 22 22:32:42 2025
--- gcc-14-20250829/libgcc/config/libbid/bid128_div.c	Fri Aug 29 22:32:24 2025
*************** see the files COPYING3 and COPYING.RUNTI
*** 24,38 ****
  #define BID_128RES
  #include "bid_div_macros.h"
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
- #include <fenv.h>
- 
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
  
  extern UINT32 convert_table[5][128][2];
  extern SINT8 factors[][2];
  extern UINT8 packed_10000_zeros[];
  
  BID128_FUNCTION_ARG2 (bid128_div, x, y)
  
       UINT256 CA4, CA4r, P256;
--- 24,39 ----
  #define BID_128RES
  #include "bid_div_macros.h"
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
+ #include <stdio.h>
+ #include <fenv.h>
  
  extern UINT32 convert_table[5][128][2];
  extern SINT8 factors[][2];
  extern UINT8 packed_10000_zeros[];
  
+ 
  BID128_FUNCTION_ARG2 (bid128_div, x, y)
  
       UINT256 CA4, CA4r, P256;
*************** BID128_FUNCTION_ARG2 (bid128_div, x, y)
*** 45,54 ****
--- 46,63 ----
         digits_q, amount;
       int nzeros, i, j, k, d5;
       unsigned rmode;
+      int old_rm, rm_changed=0;
+ 
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
       fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+   
  valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
  
    // unpack arguments, check for NaN or Infinity
*************** if ((x.w[1] & 0x7c00000000000000ull) ==
*** 62,67 ****
--- 71,78 ----
  #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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
      // x is Infinity?
*************** if ((x.w[1] & 0x7800000000000000ull) ==
*** 75,80 ****
--- 86,93 ----
  #endif
      res.w[1] = 0x7c00000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is NaN?
*************** if ((x.w[1] & 0x7800000000000000ull) ==
*** 85,90 ****
--- 98,105 ----
      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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  }
*************** if ((y.w[1] & 0x7800000000000000ull) < 0
*** 97,102 ****
--- 112,119 ----
      // x=y=0, return NaN
      res.w[1] = 0x7c00000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // return 0
*************** if ((y.w[1] & 0x7800000000000000ull) < 0
*** 108,113 ****
--- 125,132 ----
      exponent_x = 0;
    res.w[1] |= (((UINT64) exponent_x) << 49);
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  }
*************** if (!valid_y) {
*** 122,127 ****
--- 141,148 ----
  #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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is Infinity?
*************** if (!valid_y) {
*** 129,134 ****
--- 150,157 ----
      // return +/-0
      res.w[1] = sign_x ^ sign_y;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
*************** if (!valid_y) {
*** 138,143 ****
--- 161,168 ----
    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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (__unsigned_compare_gt_128 (CY, CX))
*** 186,191 ****
--- 211,218 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // get number of decimal digits in CQ
*************** if (!CA4.w[0] && !CA4.w[1])
*** 379,384 ****
--- 406,413 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #endif
*************** if (diff_expon >= 0) {
*** 469,474 ****
--- 498,505 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  
  }
*************** get_BID128 (&res, sign_x ^ sign_y, diff_
*** 477,482 ****
--- 508,515 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  }
  
*************** TYPE0_FUNCTION_ARGTYPE1_ARGTYPE2 (UINT12
*** 496,505 ****
--- 529,545 ----
         digits_q, amount;
       int nzeros, i, j, k, d5;
       unsigned rmode;
+      int old_rm, rm_changed=0;
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
       fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
  valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], y);
  
  	// unpack arguments, check for NaN or Infinity
*************** if ((x & NAN_MASK64) == NAN_MASK64) {
*** 519,524 ****
--- 559,566 ----
    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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  	   // x is Infinity?
*************** if (((x) & 0x7800000000000000ull) == 0x7
*** 532,544 ****
  #endif
    res.w[1] = 0x7c00000000000000ull;
    res.w[0] = 0;
!     BID_RETURN (res);
    }
    if ((((y) & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
    // otherwise return +/-Inf
    res.w[1] =
      (((x) ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull;
    res.w[0] = 0;
    BID_RETURN (res);
    }
  }
--- 574,590 ----
  #endif
    res.w[1] = 0x7c00000000000000ull;
    res.w[0] = 0;
!   // restore the rounding mode back if it has been changed
!   if (rm_changed) fesetround(old_rm);
!   BID_RETURN (res);
    }
    if ((((y) & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
    // otherwise return +/-Inf
    res.w[1] =
      (((x) ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull;
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
    }
  }
*************** if ((((y) & 0x7800000000000000ull) != 0x
*** 551,556 ****
--- 597,604 ----
    // x=y=0, return NaN
    res.w[1] = 0x7c00000000000000ull;
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  	   // return 0
*************** else if (exponent_x < 0)
*** 566,571 ****
--- 614,621 ----
    exponent_x = 0;
  res.w[1] |= (((UINT64) exponent_x) << 49);
  res.w[0] = 0;
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  }
  }
*************** if (!valid_y) {
*** 583,595 ****
    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);
!     BID_RETURN (res);
    }
    // y is Infinity?
    if (((y) & 0x7800000000000000ull) == 0x7800000000000000ull) {
      // return +/-0
      res.w[1] = sign_x ^ sign_y;
      res.w[0] = 0;
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
--- 633,649 ----
    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
!   if (rm_changed) fesetround(old_rm);
!   BID_RETURN (res);
    }
    // y is Infinity?
    if (((y) & 0x7800000000000000ull) == 0x7800000000000000ull) {
      // return +/-0
      res.w[1] = sign_x ^ sign_y;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
*************** if (!valid_y) {
*** 599,604 ****
--- 653,660 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (__unsigned_compare_gt_128 (CY, CX))
*** 647,652 ****
--- 703,710 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // get number of decimal digits in CQ
*************** __div_256_by_128 (&CQ, &CA4, CY);
*** 843,848 ****
--- 901,908 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  #endif
*************** if (diff_expon >= 0) {
*** 932,937 ****
--- 992,999 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  
  }
*************** get_BID128 (&res, sign_x ^ sign_y, diff_
*** 940,945 ****
--- 1002,1009 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  }
  
*************** BID128_FUNCTION_ARGTYPE1_ARG128 (bid128d
*** 955,964 ****
--- 1019,1035 ----
         digits_q, amount;
       int nzeros, i, j, k, d5;
       unsigned rmode;
+      int old_rm, rm_changed=0;
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
       fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
  valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
  
  	// unpack arguments, check for NaN or Infinity
*************** if ((x & NAN_MASK64) == NAN_MASK64) {
*** 978,983 ****
--- 1049,1056 ----
    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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  	   // x is Infinity?
*************** if ((x & 0x7800000000000000ull) == 0x780
*** 991,996 ****
--- 1064,1071 ----
  #endif
      res.w[1] = 0x7c00000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
*************** if ((x & 0x7800000000000000ull) == 0x780
*** 998,1003 ****
--- 1073,1080 ----
    res.w[1] =
      ((x ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
    }
  }
*************** if ((y.w[1] & INFINITY_MASK64) != INFINI
*** 1010,1015 ****
--- 1087,1094 ----
      // x=y=0, return NaN
      res.w[1] = 0x7c00000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // return 0
*************** if ((y.w[1] & INFINITY_MASK64) != INFINI
*** 1021,1026 ****
--- 1100,1107 ----
      exponent_x = 0;
    res.w[1] |= (((UINT64) exponent_x) << 49);
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  }
*************** if (!valid_y) {
*** 1037,1042 ****
--- 1118,1125 ----
  #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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is Infinity?
*************** if (!valid_y) {
*** 1044,1049 ****
--- 1127,1134 ----
      // return +/-0
      res.w[1] = sign_x ^ sign_y;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
*************** if (!valid_y) {
*** 1053,1058 ****
--- 1138,1145 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (__unsigned_compare_gt_128 (CY, CX))
*** 1101,1106 ****
--- 1188,1195 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // get number of decimal digits in CQ
*************** __div_256_by_128 (&CQ, &CA4, CY);
*** 1300,1305 ****
--- 1389,1396 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  #endif
*************** if (diff_expon >= 0) {
*** 1389,1394 ****
--- 1480,1487 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  
*************** get_BID128 (&res, sign_x ^ sign_y, diff_
*** 1396,1401 ****
--- 1489,1496 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  
  }
*************** BID128_FUNCTION_ARG128_ARGTYPE2 (bid128q
*** 1411,1420 ****
--- 1506,1521 ----
       int exponent_x, exponent_y, bin_index, bin_expon, diff_expon, ed2,
         digits_q, amount;
       int nzeros, i, j, k, d5, rmode;
+      int old_rm, rm_changed=0;
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
       fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
  
  valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], y);
  	// unpack arguments, check for NaN or Infinity
*************** if ((x.w[1] & 0x7c00000000000000ull) ==
*** 1428,1433 ****
--- 1529,1536 ----
  #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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
      // x is Infinity?
*************** if ((x.w[1] & 0x7800000000000000ull) ==
*** 1441,1446 ****
--- 1544,1551 ----
  #endif
      res.w[1] = 0x7c00000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is NaN?
*************** if ((x.w[1] & 0x7800000000000000ull) ==
*** 1451,1456 ****
--- 1556,1563 ----
      res.w[1] = ((x.w[1] ^ y) & 0x8000000000000000ull) |
        0x7800000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  }
*************** if ((y & 0x7800000000000000ull) < 0x7800
*** 1463,1468 ****
--- 1570,1577 ----
      // x=y=0, return NaN
      res.w[1] = 0x7c00000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // return 0
*************** if ((y & 0x7800000000000000ull) < 0x7800
*** 1474,1479 ****
--- 1583,1590 ----
      exponent_x = 0;
    res.w[1] |= (((UINT64) exponent_x) << 49);
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  }
*************** if (!valid_y) {
*** 1490,1502 ****
    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);
!     BID_RETURN (res);
    }
    // y is Infinity?
    if ((y & INFINITY_MASK64) == INFINITY_MASK64) {
      // return +/-0
      res.w[1] = ((x.w[1] ^ y) & 0x8000000000000000ull);
      res.w[0] = 0;
      BID_RETURN (res);
    }
    // y is 0
--- 1601,1617 ----
    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
!   if (rm_changed) fesetround(old_rm);
!   BID_RETURN (res);
    }
    // y is Infinity?
    if ((y & INFINITY_MASK64) == INFINITY_MASK64) {
      // return +/-0
      res.w[1] = ((x.w[1] ^ y) & 0x8000000000000000ull);
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0
*************** if (!valid_y) {
*** 1505,1510 ****
--- 1620,1627 ----
  #endif
    res.w[1] = (sign_x ^ sign_y) | INFINITY_MASK64;
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (__unsigned_compare_gt_128 (CY, CX))
*** 1553,1558 ****
--- 1670,1677 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // get number of decimal digits in CQ
*************** __div_256_by_128 (&CQ, &CA4, CY);
*** 1749,1754 ****
--- 1868,1875 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  #endif
*************** if (diff_expon >= 0) {
*** 1838,1843 ****
--- 1959,1966 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  
  }
*************** get_BID128 (&res, sign_x ^ sign_y, diff_
*** 1846,1851 ****
--- 1969,1976 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  
  }
diff -Nrcpad gcc-14-20250822/libgcc/config/libbid/bid128_rem.c gcc-14-20250829/libgcc/config/libbid/bid128_rem.c
*** gcc-14-20250822/libgcc/config/libbid/bid128_rem.c	Fri Aug 22 22:32:42 2025
--- gcc-14-20250829/libgcc/config/libbid/bid128_rem.c	Fri Aug 29 22:32:24 2025
*************** see the files COPYING3 and COPYING.RUNTI
*** 23,28 ****
--- 23,29 ----
  
  #define BID_128RES
  #include "bid_div_macros.h"
+ #include <fenv.h>
  
  
  BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (UINT128, bid128_rem, x, y)
*************** BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE
*** 34,42 ****
--- 35,50 ----
       int_float f64, fx;
       int exponent_x, exponent_y, diff_expon, bin_expon_cx, scale,
         scale0;
+      int old_rm, rm_changed=0;
  
    // unpack arguments, check for NaN or Infinity
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
  valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
  
  if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) {
*************** if ((x.w[1] & 0x7c00000000000000ull) ==
*** 52,57 ****
--- 60,67 ----
  #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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
      // x is Infinity?
*************** if ((x.w[1] & 0x7800000000000000ull) ==
*** 66,71 ****
--- 76,83 ----
  #endif
      res.w[1] = 0x7c00000000000000ull;
      res.w[0] = 0;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  
*************** if ((!CY.w[1]) && (!CY.w[0])) {
*** 79,84 ****
--- 91,98 ----
    // x=y=0, return NaN
    res.w[1] = 0x7c00000000000000ull;
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  if (valid_y || ((y.w[1] & NAN_MASK64) == INFINITY_MASK64)) {
*************** if (valid_y || ((y.w[1] & NAN_MASK64) ==
*** 89,94 ****
--- 103,110 ----
  
    res.w[1] = sign_x | (((UINT64) exponent_x) << 49);
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  }
*************** if (!valid_y) {
*** 103,108 ****
--- 119,126 ----
  #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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is Infinity?
*************** if (!valid_y) {
*** 110,115 ****
--- 128,135 ----
      // return x
      res.w[1] = x.w[1];
      res.w[0] = x.w[0];
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0
*************** if (!valid_y) {
*** 119,124 ****
--- 139,146 ----
  #endif
    res.w[1] = 0x7c00000000000000ull;
    res.w[0] = 0;
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  
*************** if (diff_expon <= 0) {
*** 130,135 ****
--- 152,159 ----
    if (diff_expon > 34) {
      // |x|<|y| in this case
      res = x;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // set exponent of y to exponent_x, scale coefficient_y
*************** if (diff_expon <= 0) {
*** 139,144 ****
--- 163,170 ----
    if (P256.w[2] || P256.w[3]) {
      // |x|<|y| in this case
      res = x;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  
*************** if (diff_expon <= 0) {
*** 147,152 ****
--- 173,180 ----
    if (__unsigned_compare_ge_128 (P256, CX2)) {
      // |x|<|y| in this case
      res = x;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  
*************** if (diff_expon <= 0) {
*** 164,169 ****
--- 192,199 ----
    }
  
    get_BID128_very_fast (&res, sign_x, exponent_x, CR);
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
    // 2^64
*************** while (diff_expon > 0) {
*** 200,205 ****
--- 230,237 ----
    // 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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  }
*************** if ((__unsigned_compare_gt_128 (CX2, CY)
*** 213,217 ****
--- 245,251 ----
  }
  
  get_BID128_very_fast (&res, sign_x, exponent_y, CX);
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  }
diff -Nrcpad gcc-14-20250822/libgcc/config/libbid/bid128_sqrt.c gcc-14-20250829/libgcc/config/libbid/bid128_sqrt.c
*** gcc-14-20250822/libgcc/config/libbid/bid128_sqrt.c	Fri Aug 22 22:32:42 2025
--- gcc-14-20250829/libgcc/config/libbid/bid128_sqrt.c	Fri Aug 29 22:32:24 2025
*************** see the files COPYING3 and COPYING.RUNTI
*** 24,32 ****
  #define BID_128RES
  #include "bid_internal.h"
  #include "bid_sqrt_macros.h"
- #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  #include <fenv.h>
! 
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
  
--- 24,31 ----
  #define BID_128RES
  #include "bid_internal.h"
  #include "bid_sqrt_macros.h"
  #include <fenv.h>
! #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
  
*************** BID128_FUNCTION_ARG1 (bid128_sqrt, x)
*** 39,48 ****
--- 38,54 ----
       int_float fx, f64;
       int exponent_x, bin_expon_cx;
       int digits, scale, exponent_q;
+      int old_rm, rm_changed=0;
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
       fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
    // unpack arguments, check for NaN or Infinity
  if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) {
  res.w[1] = CX.w[1];
*************** if ((x.w[1] & 0x7c00000000000000ull) ==
*** 54,59 ****
--- 60,67 ----
      __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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
      // x is Infinity?
*************** if ((x.w[1] & 0x7800000000000000ull) ==
*** 66,71 ****
--- 74,81 ----
      __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
    }
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
      // x is 0 otherwise
*************** res.w[1] =
*** 74,79 ****
--- 84,91 ----
    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
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  }
  if (sign_x) {
*************** if (sign_x) {
*** 82,87 ****
--- 94,101 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (CS.w[0] * CS.w[0] == A10.w[0]) {
*** 117,122 ****
--- 131,138 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  }
*************** get_BID128_fast (&res, 0,
*** 288,293 ****
--- 304,311 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  }
  
*************** BID128_FUNCTION_ARGTYPE1 (bid128d_sqrt,
*** 302,311 ****
--- 320,337 ----
       int_float fx, f64;
       int exponent_x, bin_expon_cx;
       int digits, scale, exponent_q;
+      int old_rm, rm_changed=0;
+ 
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
       fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
  	// unpack arguments, check for NaN or Infinity
     // unpack arguments, check for NaN or Infinity
  CX.w[1] = 0;
*************** if ((x & 0x7c00000000000000ull) == 0x7c0
*** 321,326 ****
--- 347,354 ----
    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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  	   // x is Infinity?
*************** if ((x & 0x7800000000000000ull) == 0x780
*** 332,337 ****
--- 360,367 ----
      __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
    }
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  	   // x is 0 otherwise
*************** res.w[1] =
*** 342,347 ****
--- 372,379 ----
    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
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  }
  if (sign_x) {
*************** if (sign_x) {
*** 350,355 ****
--- 382,389 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (CS.w[0] * CS.w[0] == A10.w[0]) {
*** 387,392 ****
--- 421,428 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  }
*************** get_BID128_fast (&res, 0, (exponent_q +
*** 558,564 ****
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
  BID_RETURN (res);
  
- 
  }
--- 594,601 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  
  }
diff -Nrcpad gcc-14-20250822/libgcc/config/libbid/bid64_div.c gcc-14-20250829/libgcc/config/libbid/bid64_div.c
*** gcc-14-20250822/libgcc/config/libbid/bid64_div.c	Fri Aug 22 22:32:42 2025
--- gcc-14-20250829/libgcc/config/libbid/bid64_div.c	Fri Aug 29 22:32:24 2025
*************** see the files COPYING3 and COPYING.RUNTI
*** 55,63 ****
  
  #include "bid_internal.h"
  #include "bid_div_macros.h"
- #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  #include <fenv.h>
! 
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
  
--- 55,62 ----
  
  #include "bid_internal.h"
  #include "bid_div_macros.h"
  #include <fenv.h>
! #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
  
*************** extern UINT32 convert_table[5][128][2];
*** 65,71 ****
  extern SINT8 factors[][2];
  extern UINT8 packed_10000_zeros[];
  
- 
  #if DECIMAL_CALL_BY_REFERENCE
  
  void
--- 64,69 ----
*************** bid64_div (UINT64 x,
*** 94,99 ****
--- 92,98 ----
    int rmode, amount;
    int nzeros, i, j, k, d5;
    UINT32 QX32, tdigit[3], digit, digit_h, digit_low;
+   int old_rm, rm_changed=0;
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    fexcept_t binaryflags = 0;
  #endif
*************** bid64_div (UINT64 x,
*** 106,111 ****
--- 105,116 ----
    y = *py;
  #endif
  
+   // Set it to round-to-nearest (if different)
+   if ((old_rm=fegetround()) != FE_TONEAREST) {
+     rm_changed=1;
+     fesetround(FE_TONEAREST);
+   }
+ 
    valid_x = unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x);
    valid_y = unpack_BID64 (&sign_y, &exponent_y, &coefficient_y, y);
  
*************** bid64_div (UINT64 x,
*** 123,128 ****
--- 128,135 ----
        if ((x & SNAN_MASK64) == SNAN_MASK64)	// sNaN
  	__set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (coefficient_x & QUIET_MASK64);
      }
      // x is Infinity?
*************** bid64_div (UINT64 x,
*** 134,143 ****
--- 141,154 ----
  #ifdef SET_STATUS_FLAGS
  	  __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+           // restore the rounding mode back if it has been changed
+           if (rm_changed) fesetround(old_rm);
  	  BID_RETURN (NAN_MASK64);
  	}
        } else {
  	// otherwise return +/-Inf
+         // restore the rounding mode back if it has been changed
+         if (rm_changed) fesetround(old_rm);
  	BID_RETURN (((x ^ y) & 0x8000000000000000ull) |
  		    INFINITY_MASK64);
        }
*************** bid64_div (UINT64 x,
*** 149,154 ****
--- 160,167 ----
  #ifdef SET_STATUS_FLAGS
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (NAN_MASK64);
      }
      if (((y & INFINITY_MASK64) != INFINITY_MASK64)) {
*************** bid64_div (UINT64 x,
*** 163,168 ****
--- 176,183 ----
  	exponent_x = DECIMAL_MAX_EXPON_64;
        else if (exponent_x < 0)
  	exponent_x = 0;
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN ((sign_x ^ sign_y) | (((UINT64) exponent_x) << 53));
      }
  
*************** bid64_div (UINT64 x,
*** 176,192 ****
--- 191,213 ----
        if ((y & SNAN_MASK64) == SNAN_MASK64)	// sNaN
  	__set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (coefficient_y & QUIET_MASK64);
      }
      // y is Infinity?
      if ((y & INFINITY_MASK64) == INFINITY_MASK64) {
        // return +/-0
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (((x ^ y) & 0x8000000000000000ull));
      }
      // y is 0
  #ifdef SET_STATUS_FLAGS
      __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN ((sign_x ^ sign_y) | INFINITY_MASK64);
    }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** bid64_div (UINT64 x,
*** 255,260 ****
--- 276,283 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
        (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
      // get decimal digits of Q
*************** bid64_div (UINT64 x,
*** 424,429 ****
--- 447,454 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
        (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
    }
*************** bid64_div (UINT64 x,
*** 494,499 ****
--- 519,526 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    } else {
      // UF occurs
*************** bid64_div (UINT64 x,
*** 510,515 ****
--- 537,544 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
  
    }
*************** int exponent_x, exponent_y, bin_index, b
*** 528,537 ****
--- 557,573 ----
    digits_q, amount;
  int nzeros, i, j, k, d5, done = 0;
  unsigned rmode;
+ int old_rm, rm_changed=0;
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
  valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
  
  	// unpack arguments, check for NaN or Infinity
*************** if (!unpack_BID64 (&sign_x, &exponent_x,
*** 545,550 ****
--- 581,588 ----
    // test if x is NaN
    if (((x) & 0x7c00000000000000ull) == 0x7c00000000000000ull) {
      res = CX.w[0];
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res & QUIET_MASK64);
    }
    // x is Infinity?
*************** if (!unpack_BID64 (&sign_x, &exponent_x,
*** 557,570 ****
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
        BID_RETURN (res);
      }
- 	if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
-     // otherwise return +/-Inf
-     res =
-       (((x) ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
-     BID_RETURN (res);
- 	}
    }
    // x is 0
    if ((y.w[1] & INFINITY_MASK64) != INFINITY_MASK64) {
--- 595,612 ----
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
+       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
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
    }
    // x is 0
    if ((y.w[1] & INFINITY_MASK64) != INFINITY_MASK64) {
*************** if (!unpack_BID64 (&sign_x, &exponent_x,
*** 574,579 ****
--- 616,623 ----
  #endif
        // x=y=0, return NaN
        res = 0x7c00000000000000ull;
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
      // return 0
*************** if (!unpack_BID64 (&sign_x, &exponent_x,
*** 584,589 ****
--- 628,635 ----
      else if (exponent_x < 0)
        exponent_x = 0;
      res |= (((UINT64) exponent_x) << 53);
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  }
*************** if (!valid_y) {
*** 604,615 ****
--- 650,665 ----
      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
+     if (rm_changed) fesetround(old_rm);
      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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
*************** if (!valid_y) {
*** 618,623 ****
--- 668,675 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (__unsigned_compare_gt_128 (CY, CX))
*** 680,685 ****
--- 732,739 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
        (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
  
*************** if (!done) {
*** 816,830 ****
  
        }
      }
! 	if(diff_expon>=0){
!     res =
!       fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
! 			       rnd_mode, pfpsf);
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
!     BID_RETURN (res);
! 	}
    }
  #endif
  
--- 870,886 ----
  
        }
      }
!     if(diff_expon>=0){
!       res =
! 	fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.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
!       if (rm_changed) fesetround(old_rm);
!       BID_RETURN (res);
!     }
    }
  #endif
  
*************** if (!done) {
*** 905,910 ****
--- 961,968 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    } else {
      // UF occurs
*************** if (!done) {
*** 921,928 ****
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
      BID_RETURN (res);
- 
    }
  
  }
--- 979,987 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  
  }
*************** int exponent_x, exponent_y, bin_index, b
*** 942,951 ****
--- 1001,1018 ----
    digits_q, amount;
  int nzeros, i, j, k, d5, done = 0;
  unsigned rmode;
+ int old_rm, rm_changed=0;
+ 
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
  valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], (y));
  
  	// unpack arguments, check for NaN or Infinity
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 964,970 ****
        amount = recip_scale[18];
        __shr_128 (Tmp, Qh, amount);
        res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
!     BID_RETURN (res);
    }
    // x is Infinity?
    if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
--- 1031,1039 ----
        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
!       if (rm_changed) fesetround(old_rm);
!       BID_RETURN (res);
    }
    // x is Infinity?
    if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 976,989 ****
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
        BID_RETURN (res);
      }
- 	if (((y & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
-     // otherwise return +/-Inf
-     res =
-       ((x.w[1] ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull;
-     BID_RETURN (res);
- 	}
    }
    // x is 0
    if (((y & INFINITY_MASK64) != INFINITY_MASK64) &&
--- 1045,1062 ----
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
+       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
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
    }
    // x is 0
    if (((y & INFINITY_MASK64) != INFINITY_MASK64) &&
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 993,1009 ****
  #endif
      // x=y=0, return NaN
      res = 0x7c00000000000000ull;
      BID_RETURN (res);
    }
    // return 0
    if (((y & 0x7800000000000000ull) != 0x7800000000000000ull)) {
! 	  if (!CY.w[0]) {
  #ifdef SET_STATUS_FLAGS
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
        BID_RETURN (res);
! 	  }
      exponent_x =
        exponent_x - exponent_y - DECIMAL_EXPONENT_BIAS_128 +
        (DECIMAL_EXPONENT_BIAS << 1);
--- 1066,1086 ----
  #endif
      // x=y=0, return NaN
      res = 0x7c00000000000000ull;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // return 0
    if (((y & 0x7800000000000000ull) != 0x7800000000000000ull)) {
!     if (!CY.w[0]) {
  #ifdef SET_STATUS_FLAGS
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
!     }
      exponent_x =
        exponent_x - exponent_y - DECIMAL_EXPONENT_BIAS_128 +
        (DECIMAL_EXPONENT_BIAS << 1);
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 1012,1017 ****
--- 1089,1096 ----
      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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  }
*************** if (!valid_y) {
*** 1025,1036 ****
--- 1104,1119 ----
      if ((y & SNAN_MASK64) == SNAN_MASK64)	// sNaN
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
*************** if (!valid_y) {
*** 1039,1044 ****
--- 1122,1129 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (__unsigned_compare_gt_128 (CY, CX))
*** 1103,1108 ****
--- 1188,1195 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
        (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
  
*************** if (!done) {
*** 1159,1260 ****
  #endif
  #ifndef LEAVE_TRAILING_ZEROS
      // check whether result is exact
!   {
! 	  if(!done) {
!     // check whether CX, CY are short
!     if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
!       i = (int) CY.w[0] - 1;
!       j = (int) CX.w[0] - 1;
!       // difference in powers of 2 factors for Y and X
!       nzeros = ed2 - factors[i][0] + factors[j][0];
!       // difference in powers of 5 factors
!       d5 = ed2 - factors[i][1] + factors[j][1];
!       if (d5 < nzeros)
! 		nzeros = d5;
!       // get P*(2^M[extra_digits])/10^extra_digits
!       __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
!       //__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
  
!       // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
!       amount = recip_scale[nzeros];
!       __shr_128_long (CQ, Qh, amount);
  
!       diff_expon += nzeros;
!     } else {
!       // decompose Q as Qh*10^17 + Ql
!       //T128 = reciprocals10_128[17];
!       Q_low = CQ.w[0];
  
!       {
! 	tdigit[0] = Q_low & 0x3ffffff;
! 	tdigit[1] = 0;
! 	QX = Q_low >> 26;
! 	QX32 = QX;
! 	nzeros = 0;
  
! 	for (j = 0; QX32; j++, QX32 >>= 7) {
! 	  k = (QX32 & 127);
! 	  tdigit[0] += convert_table[j][k][0];
! 	  tdigit[1] += convert_table[j][k][1];
! 	  if (tdigit[0] >= 100000000) {
! 	    tdigit[0] -= 100000000;
! 	    tdigit[1]++;
! 	  }
! 	}
  
! 	if (tdigit[1] >= 100000000) {
! 	  tdigit[1] -= 100000000;
! 	  if (tdigit[1] >= 100000000)
! 	    tdigit[1] -= 100000000;
! 	}
  
! 	digit = tdigit[0];
! 	if (!digit && !tdigit[1])
! 	  nzeros += 16;
! 	else {
! 	  if (!digit) {
! 	    nzeros += 8;
! 	    digit = tdigit[1];
! 	  }
! 	  // decompose digit
! 	  PD = (UINT64) digit *0x068DB8BBull;
! 	  digit_h = (UINT32) (PD >> 40);
! 	  digit_low = digit - digit_h * 10000;
  
! 	  if (!digit_low)
! 	    nzeros += 4;
! 	  else
! 	    digit_h = digit_low;
  
! 	  if (!(digit_h & 1))
! 	    nzeros +=
! 	      3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
! 			    (digit_h & 7));
! 	}
  
! 	if (nzeros) {
! 	  // get P*(2^M[extra_digits])/10^extra_digits
! 	  __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
  
! 	  // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
! 	  amount = recip_scale[nzeros];
! 	  __shr_128 (CQ, Qh, amount);
  	}
- 	diff_expon += nzeros;
- 
        }
!     }
! 	  }
! 	if(diff_expon>=0){
!     res =
!       fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
! 			       rnd_mode, pfpsf);
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
!     (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
!     BID_RETURN (res);
! 	}
!   }
  #endif
  
    if (diff_expon >= 0) {
--- 1246,1349 ----
  #endif
  #ifndef LEAVE_TRAILING_ZEROS
      // check whether result is exact
!     {
!       if(!done) {
! 	// check whether CX, CY are short
! 	if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
! 	  i = (int) CY.w[0] - 1;
! 	  j = (int) CX.w[0] - 1;
! 	  // difference in powers of 2 factors for Y and X
! 	  nzeros = ed2 - factors[i][0] + factors[j][0];
! 	  // difference in powers of 5 factors
! 	  d5 = ed2 - factors[i][1] + factors[j][1];
! 	  if (d5 < nzeros)
! 	    nzeros = d5;
! 	  // get P*(2^M[extra_digits])/10^extra_digits
! 	  __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
! 	  //__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
  
! 	  // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
! 	  amount = recip_scale[nzeros];
! 	  __shr_128_long (CQ, Qh, amount);
  
! 	  diff_expon += nzeros;
! 	} else {
! 	  // decompose Q as Qh*10^17 + Ql
! 	  //T128 = reciprocals10_128[17];
! 	  Q_low = CQ.w[0];
  
! 	  {
! 	    tdigit[0] = Q_low & 0x3ffffff;
! 	    tdigit[1] = 0;
! 	    QX = Q_low >> 26;
! 	    QX32 = QX;
! 	    nzeros = 0;
  
! 	    for (j = 0; QX32; j++, QX32 >>= 7) {
! 	      k = (QX32 & 127);
! 	      tdigit[0] += convert_table[j][k][0];
! 	      tdigit[1] += convert_table[j][k][1];
! 	      if (tdigit[0] >= 100000000) {
! 		tdigit[0] -= 100000000;
! 		tdigit[1]++;
! 	      }
! 	    }
  
! 	    if (tdigit[1] >= 100000000) {
! 	      tdigit[1] -= 100000000;
! 	      if (tdigit[1] >= 100000000)
! 		tdigit[1] -= 100000000;
! 	    }
  
! 	    digit = tdigit[0];
! 	    if (!digit && !tdigit[1])
! 	      nzeros += 16;
! 	    else {
! 	      if (!digit) {
! 		nzeros += 8;
! 		digit = tdigit[1];
! 	      }
! 	      // decompose digit
! 	      PD = (UINT64) digit *0x068DB8BBull;
! 	      digit_h = (UINT32) (PD >> 40);
! 	      digit_low = digit - digit_h * 10000;
  
! 	      if (!digit_low)
! 		nzeros += 4;
! 	      else
! 		digit_h = digit_low;
  
! 	      if (!(digit_h & 1))
! 		nzeros +=
! 		  3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
! 				(digit_h & 7));
! 	    }
! 	
! 	    if (nzeros) {
! 	      // get P*(2^M[extra_digits])/10^extra_digits
! 	      __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
  
! 	      // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
! 	      amount = recip_scale[nzeros];
! 	      __shr_128 (CQ, Qh, amount);
! 	    }
! 	    diff_expon += nzeros;
  
! 	  }
  	}
        }
!       if(diff_expon>=0){
! 	res =
! 	  fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.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
! 	if (rm_changed) fesetround(old_rm);
! 	BID_RETURN (res);
!       }
!     }
  #endif
  
    if (diff_expon >= 0) {
*************** if (!done) {
*** 1337,1342 ****
--- 1426,1433 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    } else {
      // UF occurs
*************** if (!done) {
*** 1353,1360 ****
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
      BID_RETURN (res);
- 
    }
  
  }
--- 1444,1452 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  
  }
*************** int exponent_x, exponent_y, bin_index, b
*** 1379,1388 ****
--- 1471,1487 ----
    digits_q, amount;
  int nzeros, i, j, k, d5, done = 0;
  unsigned rmode;
+ int old_rm, rm_changed=0;
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  fexcept_t binaryflags = 0;
  #endif
  
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
+ 
  valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
  
  	// unpack arguments, check for NaN or Infinity
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 1401,1407 ****
        amount = recip_scale[18];
        __shr_128 (Tmp, Qh, amount);
        res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
!     BID_RETURN (res);
    }
    // x is Infinity?
    if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
--- 1500,1508 ----
        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
!       if (rm_changed) fesetround(old_rm);
!       BID_RETURN (res);
    }
    // x is Infinity?
    if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 1413,1427 ****
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
        BID_RETURN (res);
      }
- 	if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
-     // otherwise return +/-Inf
-     res =
-       ((x.w[1] ^ y.
- 	w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
-     BID_RETURN (res);
- 	}
    }
    // x is 0
    if (((y.w[1] & 0x7800000000000000ull) != 0x7800000000000000ull)) {
--- 1514,1532 ----
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
        res = 0x7c00000000000000ull;
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
+       BID_RETURN (res);
+     }
+     if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
+       // otherwise return +/-Inf
+       res =
+ 	((x.w[1] ^ y.
+ 	  w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
    }
    // x is 0
    if (((y.w[1] & 0x7800000000000000ull) != 0x7800000000000000ull)) {
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 1431,1436 ****
--- 1536,1543 ----
  #endif
      // x=y=0, return NaN
      res = 0x7c00000000000000ull;
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // return 0
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 1441,1446 ****
--- 1548,1555 ----
    else if (exponent_x < 0)
      exponent_x = 0;
    res |= (((UINT64) exponent_x) << 53);
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
    }
  }
*************** if (!valid_y) {
*** 1460,1471 ****
        amount = recip_scale[18];
        __shr_128 (Tmp, Qh, amount);
        res = (CY.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
!     BID_RETURN (res);
    }
    // y is Infinity?
    if ((y.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
      // return +/-0
      res = sign_x ^ sign_y;
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
--- 1569,1584 ----
        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
!       if (rm_changed) fesetround(old_rm);
!       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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // y is 0, return +/-Inf
*************** if (!valid_y) {
*** 1474,1479 ****
--- 1587,1594 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (__unsigned_compare_gt_128 (CY, CX))
*** 1536,1541 ****
--- 1651,1658 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
        (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
  
*************** if (!done) {
*** 1594,1693 ****
  #ifndef LEAVE_TRAILING_ZEROS
      // check whether result is exact
    {
! 	  if(!done) {
!     // check whether CX, CY are short
!     if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
!       i = (int) CY.w[0] - 1;
!       j = (int) CX.w[0] - 1;
!       // difference in powers of 2 factors for Y and X
!       nzeros = ed2 - factors[i][0] + factors[j][0];
!       // difference in powers of 5 factors
!       d5 = ed2 - factors[i][1] + factors[j][1];
!       if (d5 < nzeros)
! 	nzeros = d5;
!       // get P*(2^M[extra_digits])/10^extra_digits
!       __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
!       //__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
! 
!       // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
!       amount = recip_scale[nzeros];
!       __shr_128_long (CQ, Qh, amount);
! 
!       diff_expon += nzeros;
!     } else {
!       // decompose Q as Qh*10^17 + Ql
!       //T128 = reciprocals10_128[17];
!       Q_low = CQ.w[0];
! 
!       {
! 	tdigit[0] = Q_low & 0x3ffffff;
! 	tdigit[1] = 0;
! 	QX = Q_low >> 26;
! 	QX32 = QX;
! 	nzeros = 0;
  
! 	for (j = 0; QX32; j++, QX32 >>= 7) {
! 	  k = (QX32 & 127);
! 	  tdigit[0] += convert_table[j][k][0];
! 	  tdigit[1] += convert_table[j][k][1];
! 	  if (tdigit[0] >= 100000000) {
! 	    tdigit[0] -= 100000000;
! 	    tdigit[1]++;
  	  }
- 	}
  
! 	if (tdigit[1] >= 100000000) {
! 	  tdigit[1] -= 100000000;
! 	  if (tdigit[1] >= 100000000)
  	    tdigit[1] -= 100000000;
! 	}
! 
! 	digit = tdigit[0];
! 	if (!digit && !tdigit[1])
! 	  nzeros += 16;
! 	else {
! 	  if (!digit) {
! 	    nzeros += 8;
! 	    digit = tdigit[1];
  	  }
- 	  // decompose digit
- 	  PD = (UINT64) digit *0x068DB8BBull;
- 	  digit_h = (UINT32) (PD >> 40);
- 	  digit_low = digit - digit_h * 10000;
  
! 	  if (!digit_low)
! 	    nzeros += 4;
! 	  else
! 	    digit_h = digit_low;
  
! 	  if (!(digit_h & 1))
! 	    nzeros +=
! 	      3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
! 			    (digit_h & 7));
! 	}
  
! 	if (nzeros) {
! 	  // get P*(2^M[extra_digits])/10^extra_digits
! 	  __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
  
! 	  // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
! 	  amount = recip_scale[nzeros];
! 	  __shr_128 (CQ, Qh, amount);
! 	}
! 	diff_expon += nzeros;
  
        }
      }
! 	  }
! 	if(diff_expon>=0){
!     res =
!       fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
! 			       rnd_mode, pfpsf);
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
!     (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
!     BID_RETURN (res);
! 	}
    }
  #endif
  
--- 1711,1812 ----
  #ifndef LEAVE_TRAILING_ZEROS
      // check whether result is exact
    {
!     if(!done) {
!       // check whether CX, CY are short
!       if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
! 	i = (int) CY.w[0] - 1;
! 	j = (int) CX.w[0] - 1;
! 	// difference in powers of 2 factors for Y and X
! 	nzeros = ed2 - factors[i][0] + factors[j][0];
! 	// difference in powers of 5 factors
! 	d5 = ed2 - factors[i][1] + factors[j][1];
! 	if (d5 < nzeros)
! 	  nzeros = d5;
! 	// get P*(2^M[extra_digits])/10^extra_digits
! 	__mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
! 	//__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
! 	
! 	// now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
! 	amount = recip_scale[nzeros];
! 	__shr_128_long (CQ, Qh, amount);
! 	
! 	diff_expon += nzeros;
!       } else {
! 	// decompose Q as Qh*10^17 + Ql
! 	//T128 = reciprocals10_128[17];
! 	Q_low = CQ.w[0];
!       
! 	{
! 	  tdigit[0] = Q_low & 0x3ffffff;
! 	  tdigit[1] = 0;
! 	  QX = Q_low >> 26;
! 	  QX32 = QX;
! 	  nzeros = 0;
  
! 	  for (j = 0; QX32; j++, QX32 >>= 7) {
! 	    k = (QX32 & 127);
! 	    tdigit[0] += convert_table[j][k][0];
! 	    tdigit[1] += convert_table[j][k][1];
! 	    if (tdigit[0] >= 100000000) {
! 	      tdigit[0] -= 100000000;
! 	      tdigit[1]++;
! 	    }
  	  }
  
! 	  if (tdigit[1] >= 100000000) {
  	    tdigit[1] -= 100000000;
! 	    if (tdigit[1] >= 100000000)
! 	      tdigit[1] -= 100000000;
  	  }
  
! 	  digit = tdigit[0];
! 	  if (!digit && !tdigit[1])
! 	    nzeros += 16;
! 	  else {
! 	    if (!digit) {
! 	      nzeros += 8;
! 	      digit = tdigit[1];
! 	    }
! 	    // decompose digit
! 	    PD = (UINT64) digit *0x068DB8BBull;
! 	    digit_h = (UINT32) (PD >> 40);
! 	    digit_low = digit - digit_h * 10000;
  
! 	    if (!digit_low)
! 	      nzeros += 4;
! 	    else
! 	      digit_h = digit_low;
  
! 	    if (!(digit_h & 1))
! 	      nzeros +=
! 		3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
! 			      (digit_h & 7));
! 	  }
  
! 	  if (nzeros) {
! 	    // get P*(2^M[extra_digits])/10^extra_digits
! 	    __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
! 
! 	    // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
! 	    amount = recip_scale[nzeros];
! 	    __shr_128 (CQ, Qh, amount);
! 	  }
! 	  diff_expon += nzeros;
  
+ 	}
        }
      }
!     if(diff_expon>=0){
!       res =
! 	fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.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
!       if (rm_changed) fesetround(old_rm);
!       BID_RETURN (res);
!     }
    }
  #endif
  
*************** if (!done) {
*** 1772,1777 ****
--- 1891,1898 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    } else {
      // UF occurs
*************** if (!done) {
*** 1788,1795 ****
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
      BID_RETURN (res);
- 
    }
  
  }
--- 1909,1917 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  
  }
diff -Nrcpad gcc-14-20250822/libgcc/config/libbid/bid64_sqrt.c gcc-14-20250829/libgcc/config/libbid/bid64_sqrt.c
*** gcc-14-20250822/libgcc/config/libbid/bid64_sqrt.c	Fri Aug 22 22:32:42 2025
--- gcc-14-20250829/libgcc/config/libbid/bid64_sqrt.c	Fri Aug 29 22:32:24 2025
*************** see the files COPYING3 and COPYING.RUNTI
*** 41,49 ****
  
  #include "bid_internal.h"
  #include "bid_sqrt_macros.h"
- #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  #include <fenv.h>
! 
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
  
--- 41,48 ----
  
  #include "bid_internal.h"
  #include "bid_sqrt_macros.h"
  #include <fenv.h>
! #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  #define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
  #endif
  
*************** bid64_sqrt (UINT64 x _RND_MODE_PARAM _EX
*** 73,78 ****
--- 72,79 ----
    int exponent_x, exponent_q, bin_expon_cx;
    int digits_x;
    int scale;
+   int old_rm, rm_changed=0;
+ 
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    fexcept_t binaryflags = 0;
  #endif
*************** bid64_sqrt (UINT64 x _RND_MODE_PARAM _EX
*** 84,89 ****
--- 85,96 ----
    x = *px;
  #endif
  
+   // Set it to round-to-nearest (if different)
+   if ((old_rm=fegetround()) != FE_TONEAREST) {
+     rm_changed=1;
+     fesetround(FE_TONEAREST);
+   }
+   
    // unpack arguments, check for NaN or Infinity
    if (!unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x)) {
      // x is Inf. or NaN or 0
*************** bid64_sqrt (UINT64 x _RND_MODE_PARAM _EX
*** 100,110 ****
--- 107,121 ----
        if ((x & SNAN_MASK64) == SNAN_MASK64)	// sNaN
  	__set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // x<0?
*************** bid64_sqrt (UINT64 x _RND_MODE_PARAM _EX
*** 113,118 ****
--- 124,131 ----
  #ifdef SET_STATUS_FLAGS
      __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** bid64_sqrt (UINT64 x _RND_MODE_PARAM _EX
*** 141,146 ****
--- 154,161 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
      (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // if exponent is odd, scale coefficient by 10
*************** bid64_sqrt (UINT64 x _RND_MODE_PARAM _EX
*** 206,211 ****
--- 221,228 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
    (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  
*************** int digits, scale, exponent_q = 0, exact
*** 223,228 ****
--- 240,252 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  fexcept_t binaryflags = 0;
  #endif
+ int old_rm, rm_changed=0;
+ 
+ // Set it to round-to-nearest (if different)
+ if ((old_rm=fegetround()) != FE_TONEAREST) {
+   rm_changed=1;
+   fesetround(FE_TONEAREST);
+ }
  
  	// unpack arguments, check for NaN or Infinity
  if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) {
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 240,245 ****
--- 264,271 ----
      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
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // x is Infinity?
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 251,256 ****
--- 277,284 ----
        __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
      }
+     // restore the rounding mode back if it has been changed
+     if (rm_changed) fesetround(old_rm);
      BID_RETURN (res);
    }
    // x is 0 otherwise
*************** if (!unpack_BID128_value (&sign_x, &expo
*** 264,269 ****
--- 292,299 ----
      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
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  if (sign_x) {
*************** if (sign_x) {
*** 271,276 ****
--- 301,308 ----
  #ifdef SET_STATUS_FLAGS
    __set_status_flags (pfpsf, INVALID_EXCEPTION);
  #endif
+   // restore the rounding mode back if it has been changed
+   if (rm_changed) fesetround(old_rm);
    BID_RETURN (res);
  }
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
*************** if (CS.w[0] < 10000000000000000ull) {
*** 312,317 ****
--- 344,351 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
        (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+       // restore the rounding mode back if it has been changed
+       if (rm_changed) fesetround(old_rm);
        BID_RETURN (res);
      }
    }
*************** res = get_BID64 (0, exponent_q, CS.w[0],
*** 546,552 ****
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
  BID_RETURN (res);
  
- 
  }
--- 580,587 ----
  #ifdef UNCHANGED_BINARY_STATUS_FLAGS
  (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
  #endif
+ // restore the rounding mode back if it has been changed
+ if (rm_changed) fesetround(old_rm);
  BID_RETURN (res);
  
  }
