Index: libm/common/s_llrint.c =================================================================== RCS file: /cvs/src/src/newlib/libm/common/s_llrint.c,v retrieving revision 1.1 diff -p -u -r1.1 s_llrint.c --- libm/common/s_llrint.c 3 Apr 2009 17:39:24 -0000 1.1 +++ libm/common/s_llrint.c 26 Jul 2010 23:18:40 -0000 @@ -61,40 +61,56 @@ long long int /* Extract exponent field. */ j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + /* j0 in [-1023,1024] */ if(j0 < 20) { + /* j0 in [-1023,19] */ if(j0 < -1) return 0; else { + /* j0 in [0,19] */ + /* shift amt in [0,19] */ w = TWO52[sx] + x; t = w - TWO52[sx]; GET_HIGH_WORD(i0, t); /* Detect the all-zeros representation of plus and minus zero, which fails the calculation below. */ - if ((i0 & ~(1 << 31)) == 0) + if ((i0 & ~((__int32_t)1 << 31)) == 0) return 0; + /* After round: j0 in [0,20] */ j0 = ((i0 & 0x7ff00000) >> 20) - 1023; i0 &= 0x000fffff; i0 |= 0x00100000; + /* shift amt in [20,0] */ result = i0 >> (20 - j0); } } else if (j0 < (int)(8 * sizeof (long long int)) - 1) { + /* 64bit return: j0 in [20,62] */ if (j0 >= 52) + /* 64bit return: j0 in [52,62] */ + /* 64bit return: left shift amt in [32,42] */ result = ((long long int) ((i0 & 0x000fffff) | 0x0010000) << (j0 - 20)) | + /* 64bit return: right shift amt in [0,10] */ (i1 << (j0 - 52)); else { + /* 64bit return: j0 in [20,51] */ w = TWO52[sx] + x; t = w - TWO52[sx]; EXTRACT_WORDS (i0, i1, t); j0 = ((i0 & 0x7ff00000) >> 20) - 1023; i0 &= 0x000fffff; i0 |= 0x00100000; - result = ((long long int) i0 << (j0 - 20)) | (i1 >> (52 - j0)); + /* After round: + * 64bit return: j0 in [20,52] */ + /* 64bit return: left shift amt in [0,32] */ + /* ***64bit return: right shift amt in [32,0] */ + result = ((long long int) i0 << (j0 - 20)) + | SAFE_RIGHT_SHIFT (i1, (52 - j0)); } } else Index: libm/common/s_llround.c =================================================================== RCS file: /cvs/src/src/newlib/libm/common/s_llround.c,v retrieving revision 1.2 diff -p -u -r1.2 s_llround.c --- libm/common/s_llround.c 20 Jul 2010 01:33:05 -0000 1.2 +++ libm/common/s_llround.c 26 Jul 2010 23:18:40 -0000 @@ -31,10 +31,10 @@ llround(double x) msw &= 0x000fffff; msw |= 0x00100000; - /* exponent_less_1023 in [-1024,1023] */ + /* exponent_less_1023 in [-1023,1024] */ if (exponent_less_1023 < 20) { - /* exponent_less_1023 in [-1024,19] */ + /* exponent_less_1023 in [-1023,19] */ if (exponent_less_1023 < 0) { if (exponent_less_1023 < -1) Index: libm/common/s_lrint.c =================================================================== RCS file: /cvs/src/src/newlib/libm/common/s_lrint.c,v retrieving revision 1.5 diff -p -u -r1.5 s_lrint.c --- libm/common/s_lrint.c 16 Apr 2009 15:39:46 -0000 1.5 +++ libm/common/s_lrint.c 26 Jul 2010 23:18:41 -0000 @@ -98,13 +98,17 @@ TWO52[2]={ /* Extract exponent field. */ j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + /* j0 in [-1023,1024] */ if(j0 < 20) { + /* j0 in [-1023,19] */ if(j0 < -1) return 0; else { + /* j0 in [0,19] */ + /* shift amt in [0,19] */ w = TWO52[sx] + x; t = w - TWO52[sx]; GET_HIGH_WORD(i0, t); @@ -112,26 +116,43 @@ TWO52[2]={ minus zero, which fails the calculation below. */ if ((i0 & ~(1L << 31)) == 0) return 0; + /* After round: j0 in [0,20] */ j0 = ((i0 & 0x7ff00000) >> 20) - 1023; i0 &= 0x000fffff; i0 |= 0x00100000; + /* shift amt in [20,0] */ result = i0 >> (20 - j0); } } else if (j0 < (int)(8 * sizeof (long int)) - 1) { + /* 32bit return: j0 in [20,30] */ + /* 64bit return: j0 in [20,62] */ if (j0 >= 52) + /* 64bit return: j0 in [52,62] */ + /* 64bit return: left shift amt in [32,42] */ result = ((long int) ((i0 & 0x000fffff) | 0x0010000) << (j0 - 20)) | + /* 64bit return: right shift amt in [0,10] */ (i1 << (j0 - 52)); else { + /* 32bit return: j0 in [20,30] */ + /* 64bit return: j0 in [20,51] */ w = TWO52[sx] + x; t = w - TWO52[sx]; EXTRACT_WORDS (i0, i1, t); j0 = ((i0 & 0x7ff00000) >> 20) - 1023; i0 &= 0x000fffff; i0 |= 0x00100000; - result = ((long int) i0 << (j0 - 20)) | (i1 >> (52 - j0)); + /* After round: + * 32bit return: j0 in [20,31]; + * 64bit return: j0 in [20,52] */ + /* 32bit return: left shift amt in [0,11] */ + /* 64bit return: left shift amt in [0,32] */ + /* ***32bit return: right shift amt in [32,21] */ + /* ***64bit return: right shift amt in [32,0] */ + result = ((long int) i0 << (j0 - 20)) + | SAFE_RIGHT_SHIFT (i1, (52 - j0)); } } else Index: libm/common/s_lround.c =================================================================== RCS file: /cvs/src/src/newlib/libm/common/s_lround.c,v retrieving revision 1.3 diff -p -u -r1.3 s_lround.c --- libm/common/s_lround.c 20 Jul 2010 01:33:05 -0000 1.3 +++ libm/common/s_lround.c 26 Jul 2010 23:18:41 -0000 @@ -71,10 +71,10 @@ ANSI C, POSIX exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023; msw &= 0x000fffff; msw |= 0x00100000; - /* exponent_less_1023 in [-1024,1023] */ + /* exponent_less_1023 in [-1023,1024] */ if (exponent_less_1023 < 20) { - /* exponent_less_1023 in [-1024,19] */ + /* exponent_less_1023 in [-1023,19] */ if (exponent_less_1023 < 0) { if (exponent_less_1023 < -1)