From f1343c7f6721b6a6de43813b57aa5e09cb4fd5f5 Mon Sep 17 00:00:00 2001 From: Alfredo Dal'Ava Junior Date: Thu, 26 Mar 2020 18:50:54 +0000 Subject: [PATCH] msun: swap words order instead of bits order on BIG ENDIAN The "for" loop on big endian was inverting all the bits instead of just the words Issue reported by TestSuite (msun lib nan_test case) Submitted by: Renato Riolino Submitted by: Fernando Valle Reviewed by: pfg, alfredo Approved by: jhibbits (mentor) Sponsored by: Eldorado Research Institute (eldorado.org.br) Differential Revision: https://reviews.freebsd.org/D23926 --- lib/msun/src/s_nan.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/msun/src/s_nan.c b/lib/msun/src/s_nan.c index 659e98179770..17692445ac52 100644 --- a/lib/msun/src/s_nan.c +++ b/lib/msun/src/s_nan.c @@ -66,14 +66,15 @@ _scan_nan(uint32_t *words, int num_words, const char *s) ; /* Scan backwards, filling in the bits in words[] as we go. */ -#if _BYTE_ORDER == _LITTLE_ENDIAN for (bitpos = 0; bitpos < 32 * num_words; bitpos += 4) { -#else - for (bitpos = 32 * num_words - 4; bitpos >= 0; bitpos -= 4) { -#endif if (--si < 0) break; +#if _BYTE_ORDER == _LITTLE_ENDIAN words[bitpos / 32] |= digittoint(s[si]) << (bitpos % 32); +#else + words[num_words - 1 - bitpos / 32] |= + digittoint(s[si]) << (bitpos % 32); +#endif } }