[PATCH] amdgcn, libm: fix infinite loop
Andrew Stubbs <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
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.
---
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
--
2.50.0