Index: libm/common/s_llrint.c =================================================================== RCS file: libm/common/s_llrint.c diff -N libm/common/s_llrint.c --- /dev/null 2006-11-30 19:00:00.000000000 -0500 +++ libm/common/s_llrint.c 2009-04-01 16:55:14.057286200 -0400 @@ -0,0 +1,108 @@ +/* lrint adapted to be llrint for Newlib, 2009 by Craig Howland. */ +/* @(#)s_lrint.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * llrint(x) + * Return x rounded to integral value according to the prevailing + * rounding mode. + * Method: + * Using floating addition. + * Exception: + * Inexact flag raised if x not equal to llrint(x). + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif + +/* Adding a double, x, to 2^52 will cause the result to be rounded based on + the fractional part of x, according to the implementation's current rounding + mode. 2^52 is the smallest double that can be represented using all 52 significant + digits. */ +TWO52[2]={ + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ +}; + +long long int +#ifdef __STDC__ + llrint(double x) +#else + llrint(x) + double x; +#endif +{ + __int32_t i0,j0,sx; + __uint32_t i1; + double t; + volatile double w; + long long int result; + + EXTRACT_WORDS(i0,i1,x); + + /* Extract sign bit. */ + sx = (i0>>31)&1; + + /* Extract exponent field. */ + j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + + if(j0 < 20) + { + if(j0 < -1) + return 0; + else + { + 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) + return 0; + j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + i0 &= 0x000fffff; + i0 |= 0x00100000; + result = i0 >> (20 - j0); + } + } + else if (j0 < (int)(8 * sizeof (long long int)) - 1) + { + if (j0 >= 52) + result = ((long long int) ((i0 & 0x000fffff) | 0x0010000) << (j0 - 20)) | + (i1 << (j0 - 52)); + else + { + 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)); + } + } + else + { + return (long long int) x; + } + + return sx ? -result : result; +} + +#endif /* _DOUBLE_IS_32BITS */ Index: libm/common/sf_llrint.c =================================================================== RCS file: libm/common/sf_llrint.c diff -N libm/common/sf_llrint.c --- /dev/null 2006-11-30 19:00:00.000000000 -0500 +++ libm/common/sf_llrint.c 2009-04-01 17:06:09.101112800 -0400 @@ -0,0 +1,101 @@ +/* lrintf adapted to be llrintf for Newlib, 2009 by Craig Howland. */ +/* @(#)sf_lrint.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * llrintf(x) + * Return x rounded to integral value according to the prevailing + * rounding mode. + * Method: + * Using floating addition. + * Exception: + * Inexact flag raised if x not equal to llrintf(x). + */ + +#include "fdlibm.h" + +#ifdef __STDC__ +static const float +#else +static float +#endif +/* Adding a float, x, to 2^23 will cause the result to be rounded based on + the fractional part of x, according to the implementation's current rounding + mode. 2^23 is the smallest float that can be represented using all 23 significant + digits. */ +TWO23[2]={ + 8.3886080000e+06, /* 0x4b000000 */ + -8.3886080000e+06, /* 0xcb000000 */ +}; + +#ifdef __STDC__ + long long int llrintf(float x) +#else + long long int llrintf(x) + float x; +#endif +{ + __int32_t j0,sx; + __uint32_t i0; + float t; + volatile float w; + long long int result; + + GET_FLOAT_WORD(i0,x); + + /* Extract sign bit. */ + sx = (i0 >> 31); + + /* Extract exponent field. */ + j0 = ((i0 & 0x7f800000) >> 23) - 127; + + if (j0 < (int)(sizeof (long long int) * 8) - 1) + { + if (j0 < -1) + return 0; + else if (j0 >= 23) + result = (long long int) ((i0 & 0x7fffff) | 0x800000) << (j0 - 23); + else + { + w = TWO23[sx] + x; + t = w - TWO23[sx]; + GET_FLOAT_WORD (i0, t); + /* Detect the all-zeros representation of plus and + minus zero, which fails the calculation below. */ + if ((i0 & ~(1 << 31)) == 0) + return 0; + j0 = ((i0 >> 23) & 0xff) - 0x7f; + i0 &= 0x7fffff; + i0 |= 0x800000; + result = i0 >> (23 - j0); + } + } + else + { + return (long long int) x; + } + return sx ? -result : result; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + long long int llrint(double x) +#else + long long int llrint(x) + double x; +#endif +{ + return llrintf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ Index: libm/common/Makefile.am =================================================================== RCS file: /cvs/src/src/newlib/libm/common/Makefile.am,v retrieving revision 1.11 diff -p -u -r1.11 Makefile.am --- libm/common/Makefile.am 25 Mar 2009 19:13:01 -0000 1.11 +++ libm/common/Makefile.am 1 Apr 2009 23:41:53 -0000 @@ -9,7 +9,8 @@ src = s_finite.c s_copysign.c s_modf.c s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \ s_log1p.c s_nan.c s_nextafter.c s_pow10.c \ s_rint.c s_logb.c s_log2.c s_matherr.c s_lib_ver.c \ - s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c s_lrint.c \ + s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \ + s_lrint.c s_llrint.c \ s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \ s_signbit.c s_trunc.c @@ -18,7 +19,8 @@ fsrc = sf_finite.c sf_copysign.c sf_modf sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \ sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \ sf_rint.c sf_logb.c sf_log2.c \ - sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c sf_lrint.c \ + sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c \ + sf_lrint.c sf_llrint.c \ sf_lround.c sf_llround.c sf_nearbyint.c sf_remquo.c sf_round.c \ sf_scalbln.c sf_trunc.c