[newlib-cygwin/main] amdgcn, libm: fix infinite loop

Jeff Johnston jjohnstn@sourceware.org
Fri Aug 8 23:01:05 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f13e8e21599ff12ea76980d6a8b19b0a5ebe9bed

commit f13e8e21599ff12ea76980d6a8b19b0a5ebe9bed
Author: Andrew Stubbs <ams@baylibre.com>
Date:   Thu Aug 7 13:09:41 2025 +0000

    amdgcn, libm: fix infinite loop
    
    The end condition on this loop, unlike all the other similar loops, is
    "i >= 0", which is a problem because "i <<= 1" can go negative and then zero if
    you continue shifting, and so back to true, again.  This isn't a problem for
    the loop in the scalar implementation, but it means we need to mask the shift
    in the vector implementation.
    
    This fixes GCC PR#121392.

Diff:
---
 newlib/libm/machine/amdgcn/v64sf_fmod.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/newlib/libm/machine/amdgcn/v64sf_fmod.c b/newlib/libm/machine/amdgcn/v64sf_fmod.c
index 7302420ad..b62b81929 100644
--- a/newlib/libm/machine/amdgcn/v64sf_fmod.c
+++ b/newlib/libm/machine/amdgcn/v64sf_fmod.c
@@ -70,8 +70,11 @@ DEF_VS_MATH_FUNC (v64sf, fmodf, v64sf x, v64sf y)
   v64si iy;
   VECTOR_IF (hy < 0x00800000, cond)	// subnormal y
     iy = VECTOR_INIT (-126);
-    for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); i <<= 1)
-      VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0));
+    for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); /* i <<= 1 */)
+      {
+	VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0));
+	VECTOR_COND_MOVE (i, i << 1, cond & (i >= 0));
+      }
   VECTOR_ELSE (cond)
     VECTOR_COND_MOVE (iy, (hy >> 23) - 127, cond);
   VECTOR_ENDIF


More information about the Newlib-cvs mailing list