Skip to content

Commit 2834e84

Browse files
committed
math: Use 'lsl' for left shifts in fmod/fmod
These two functions are counting loops by waiting for a single bit stored as a signed value to go negative by shifting into the top bit. Use our lsl macro, which converts this to defined behavior. Signed-off-by: Keith Packard <[email protected]>
1 parent 0061c71 commit 2834e84

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

newlib/libm/math/s_fmod.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ fmod64(__float64 x, __float64 y)
5757
/* determine ix = ilogb(x) */
5858
if (hx < 0x00100000) { /* subnormal x */
5959
if (hx == 0) {
60-
for (ix = -1043, i = lx; i > 0; i <<= 1)
60+
for (ix = -1043, i = lx; i > 0; i = lsl(i, 1))
6161
ix -= 1;
6262
} else {
63-
for (ix = -1022, i = (hx << 11); i > 0; i <<= 1)
63+
for (ix = -1022, i = lsl(hx, 11); i > 0; i = lsl(i, 1))
6464
ix -= 1;
6565
}
6666
} else
@@ -69,10 +69,10 @@ fmod64(__float64 x, __float64 y)
6969
/* determine iy = ilogb(y) */
7070
if (hy < 0x00100000) { /* subnormal y */
7171
if (hy == 0) {
72-
for (iy = -1043, i = ly; i > 0; i <<= 1)
72+
for (iy = -1043, i = ly; i > 0; i = lsl(i, 1))
7373
iy -= 1;
7474
} else {
75-
for (iy = -1022, i = (hy << 11); i > 0; i <<= 1)
75+
for (iy = -1022, i = lsl(hy, 11); i > 0; i = lsl(i, 1))
7676
iy -= 1;
7777
}
7878
} else

newlib/libm/math/sf_fmod.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ fmodf(float x, float y)
5656

5757
/* determine ix = ilogb(x) */
5858
if (FLT_UWORD_IS_SUBNORMAL(hx)) { /* subnormal x */
59-
for (ix = -126, i = (hx << 8); i > 0; i <<= 1)
59+
for (ix = -126, i = lsl(hx, 8); i > 0; i = lsl(i, 1))
6060
ix -= 1;
6161
} else
6262
ix = (hx >> 23) - 127;
6363

6464
/* determine iy = ilogb(y) */
6565
if (FLT_UWORD_IS_SUBNORMAL(hy)) { /* subnormal y */
66-
for (iy = -126, i = (hy << 8); i >= 0; i <<= 1)
66+
for (iy = -126, i = lsl(hy, 8); i >= 0; i = lsl(i, 1))
6767
iy -= 1;
6868
} else
6969
iy = (hy >> 23) - 127;

0 commit comments

Comments
 (0)