From fa3d45d19c58f6d5aa0ef42652a71f22aa2d2e92 Mon Sep 17 00:00:00 2001 From: Klaus Treichel Date: Fri, 6 Aug 2010 09:15:33 +0200 Subject: [PATCH] Add new wounding intrinsics for rounding float values towards zero. --- ChangeLog | 22 ++ configure.ac | 2 + include/jit/jit-intrinsic.h | 3 + jit/jit-intrinsic.c | 656 ++++++++++++++++++++---------------- jit/jit-symbol.c | 3 + 5 files changed, 398 insertions(+), 288 deletions(-) diff --git a/ChangeLog b/ChangeLog index f28e113..d882184 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2010-08-06 Klaus Treichel + + * configure.ac: Add checks for the rint, round and trunc c library + functions. + + * include/jit/jit-intrinsic.h (jit_float32_trunc, jit_float64_trunc, + jit_nfloat_trunc): Add prototypes. + + * jit/jit-intrinsic.c: Nove float rounding intrinsics to one block + and refine conmments. + (jit_float32_rint): Use rintf or rint if available. + (jit_float64_rint): Use rint if available. + (jit_nfloat_rint): Use rintl if available. + (jit_float32_round): Use roundf or round if available. + (jit_float64_round): Use round if available. + (jit_nfloat_round): Use roundl if available. + (jit_float32_trunc, jit_float64_trunc, jit_nfloat_trunc): Add new + rounding intrinsics for rounding float values towards zero. + + * jit/jit-symbol.c: Add the new intrinsics jit_float32_trunc, + jit_float64_trunc and jit_nfloat_trunc to the symbol table. + 2010-08-04 Klaus Treichel * include/jit/Makefile.am: Don't include jit-arch.h in the diff --git a/configure.ac b/configure.ac index c976915..58bac76 100644 --- a/configure.ac +++ b/configure.ac @@ -472,6 +472,8 @@ AC_CHECK_FUNCS(sinf sinhf sqrtf tanf tanhf) AC_CHECK_FUNCS(isnanl isinfl finitel fmodl remainderl dreml ceill floorl) AC_CHECK_FUNCS(acosl asinl atanl atan2l cosl coshl expl logl log10l powl) AC_CHECK_FUNCS(sinl sinhl sqrtl tanl tanhl) +AC_CHECK_FUNCS(trunc truncf truncl) +AC_CHECK_FUNCS(roundf round roundl rint rintf rintl) AC_CHECK_FUNCS(dlopen cygwin_conv_to_win32_path mmap munmap mprotect) AC_CHECK_FUNCS(sigsetjmp __sigsetjmp _setjmp) AC_FUNC_ALLOCA diff --git a/include/jit/jit-intrinsic.h b/include/jit/jit-intrinsic.h index 2b28ab2..e002a78 100644 --- a/include/jit/jit-intrinsic.h +++ b/include/jit/jit-intrinsic.h @@ -208,6 +208,7 @@ jit_float32 jit_float32_sinh(jit_float32 value1) JIT_NOTHROW; jit_float32 jit_float32_sqrt(jit_float32 value1) JIT_NOTHROW; jit_float32 jit_float32_tan(jit_float32 value1) JIT_NOTHROW; jit_float32 jit_float32_tanh(jit_float32 value1) JIT_NOTHROW; +jit_float32 jit_float32_trunc(jit_float32 value1) JIT_NOTHROW; jit_int jit_float32_is_finite(jit_float32 value) JIT_NOTHROW; jit_int jit_float32_is_nan(jit_float32 value) JIT_NOTHROW; jit_int jit_float32_is_inf(jit_float32 value) JIT_NOTHROW; @@ -263,6 +264,7 @@ jit_float64 jit_float64_sinh(jit_float64 value1) JIT_NOTHROW; jit_float64 jit_float64_sqrt(jit_float64 value1) JIT_NOTHROW; jit_float64 jit_float64_tan(jit_float64 value1) JIT_NOTHROW; jit_float64 jit_float64_tanh(jit_float64 value1) JIT_NOTHROW; +jit_float64 jit_float64_trunc(jit_float64 value1) JIT_NOTHROW; jit_int jit_float64_is_finite(jit_float64 value) JIT_NOTHROW; jit_int jit_float64_is_nan(jit_float64 value) JIT_NOTHROW; jit_int jit_float64_is_inf(jit_float64 value) JIT_NOTHROW; @@ -311,6 +313,7 @@ jit_nfloat jit_nfloat_sinh(jit_nfloat value1) JIT_NOTHROW; jit_nfloat jit_nfloat_sqrt(jit_nfloat value1) JIT_NOTHROW; jit_nfloat jit_nfloat_tan(jit_nfloat value1) JIT_NOTHROW; jit_nfloat jit_nfloat_tanh(jit_nfloat value1) JIT_NOTHROW; +jit_nfloat jit_nfloat_trunc(jit_nfloat value1) JIT_NOTHROW; jit_int jit_nfloat_is_finite(jit_nfloat value) JIT_NOTHROW; jit_int jit_nfloat_is_nan(jit_nfloat value) JIT_NOTHROW; jit_int jit_nfloat_is_inf(jit_nfloat value) JIT_NOTHROW; diff --git a/jit/jit-intrinsic.c b/jit/jit-intrinsic.c index 6133a2c..904e1b8 100644 --- a/jit/jit-intrinsic.c +++ b/jit/jit-intrinsic.c @@ -1434,11 +1434,9 @@ jit_int jit_float32_sign(jit_float32 value1) * @deftypefunx jit_float32 jit_float32_asin (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_atan (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_atan2 (jit_float32 @var{value1}, jit_float32 @var{value2}) - * @deftypefunx jit_float32 jit_float32_ceil (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_cos (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_cosh (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_exp (jit_float32 @var{value1}) - * @deftypefunx jit_float32 jit_float32_floor (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_log (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_log10 (jit_float32 @var{value1}) * @deftypefunx jit_float32 jit_float32_pow (jit_float32 @var{value1}, jit_float32 @var{value2}) @@ -1494,17 +1492,6 @@ jit_float32 jit_float32_atan2(jit_float32 value1, jit_float32 value2) #endif } -jit_float32 jit_float32_ceil(jit_float32 value1) -{ -#if defined(HAVE_CEILF) - return (jit_float32)(ceilf(value1)); -#elif defined(HAVE_CEIL) - return (jit_float32)(ceil(value1)); -#else - return jit_float32_nan; -#endif -} - jit_float32 jit_float32_cos(jit_float32 value1) { #if defined(HAVE_COSF) @@ -1538,17 +1525,6 @@ jit_float32 jit_float32_exp(jit_float32 value1) #endif } -jit_float32 jit_float32_floor(jit_float32 value1) -{ -#if defined(HAVE_FLOORF) - return (jit_float32)(floorf(value1)); -#elif defined(HAVE_FLOOR) - return (jit_float32)(floor(value1)); -#else - return jit_float32_nan; -#endif -} - jit_float32 jit_float32_log(jit_float32 value1) { #if defined(HAVE_LOGF) @@ -1582,72 +1558,6 @@ jit_float32 jit_float32_pow(jit_float32 value1, jit_float32 value2) #endif } -/*@ - * @deftypefun jit_float32 jit_float32_rint (jit_float32 @var{value1}) - * Round @var{value1} to the nearest integer. Half-way cases - * are rounded to an even number. - * @end deftypefun -@*/ -jit_float32 jit_float32_rint(jit_float32 value1) -{ - jit_float32 above, below; - if(!jit_float32_is_finite(value1)) - { - return value1; - } - above = jit_float32_ceil(value1); - below = jit_float32_floor(value1); - if((above - value1) < (jit_float32)0.5) - { - return above; - } - else if((value1 - below) < (jit_float32)0.5) - { - return below; - } - else if(jit_float32_ieee_rem(above, (jit_float32)2.0) == (jit_float32)0.0) - { - return above; - } - else - { - return below; - } -} - -/*@ - * @deftypefun jit_float32 jit_float32_round (jit_float32 @var{value1}) - * Round @var{value1} to the nearest integer. Half-way cases - * are rounded away from zero. - * @end deftypefun -@*/ -jit_float32 jit_float32_round(jit_float32 value1) -{ - jit_float32 above, below; - if(!jit_float32_is_finite(value1)) - { - return value1; - } - above = jit_float32_ceil(value1); - below = jit_float32_floor(value1); - if((above - value1) < (jit_float32)0.5) - { - return above; - } - else if((value1 - below) < (jit_float32)0.5) - { - return below; - } - else if(above >= (jit_float32)0.0) - { - return above; - } - else - { - return below; - } -} - jit_float32 jit_float32_sin(jit_float32 value1) { #if defined(HAVE_SINF) @@ -2046,11 +1956,9 @@ jit_int jit_float64_sign(jit_float64 value1) * @deftypefunx jit_float64 jit_float64_asin (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_atan (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_atan2 (jit_float64 @var{value1}, jit_float64 @var{value2}) - * @deftypefunx jit_float64 jit_float64_ceil (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_cos (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_cosh (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_exp (jit_float64 @var{value1}) - * @deftypefunx jit_float64 jit_float64_floor (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_log (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_log10 (jit_float64 @var{value1}) * @deftypefunx jit_float64 jit_float64_pow (jit_float64 @var{value1}, jit_float64 @var{value2}) @@ -2098,15 +2006,6 @@ jit_float64 jit_float64_atan2(jit_float64 value1, jit_float64 value2) #endif } -jit_float64 jit_float64_ceil(jit_float64 value1) -{ -#if defined(HAVE_CEIL) - return (jit_float64)(ceil(value1)); -#else - return jit_float64_nan; -#endif -} - jit_float64 jit_float64_cos(jit_float64 value1) { #if defined(HAVE_COS) @@ -2134,15 +2033,6 @@ jit_float64 jit_float64_exp(jit_float64 value1) #endif } -jit_float64 jit_float64_floor(jit_float64 value1) -{ -#if defined(HAVE_FLOOR) - return (jit_float64)(floor(value1)); -#else - return jit_float64_nan; -#endif -} - jit_float64 jit_float64_log(jit_float64 value1) { #if defined(HAVE_LOG) @@ -2170,72 +2060,6 @@ jit_float64 jit_float64_pow(jit_float64 value1, jit_float64 value2) #endif } -/*@ - * @deftypefun jit_float64 jit_float64_rint (jit_float64 @var{value1}) - * Round @var{value1} to the nearest integer. Half-way cases - * are rounded to an even number. - * @end deftypefun -@*/ -jit_float64 jit_float64_rint(jit_float64 value1) -{ - jit_float64 above, below; - if(!jit_float64_is_finite(value1)) - { - return value1; - } - above = jit_float64_ceil(value1); - below = jit_float64_floor(value1); - if((above - value1) < (jit_float64)0.5) - { - return above; - } - else if((value1 - below) < (jit_float64)0.5) - { - return below; - } - else if(jit_float64_ieee_rem(above, (jit_float64)2.0) == (jit_float64)0.0) - { - return above; - } - else - { - return below; - } -} - -/*@ - * @deftypefun jit_float64 jit_float64_round (jit_float64 @var{value1}) - * Round @var{value1} to the nearest integer. Half-way cases - * are rounded away from zero. - * @end deftypefun -@*/ -jit_float64 jit_float64_round(jit_float64 value1) -{ - jit_float64 above, below; - if(!jit_float64_is_finite(value1)) - { - return value1; - } - above = jit_float64_ceil(value1); - below = jit_float64_floor(value1); - if((above - value1) < (jit_float64)0.5) - { - return above; - } - else if((value1 - below) < (jit_float64)0.5) - { - return below; - } - else if(above >= (jit_float64)0.0) - { - return above; - } - else - { - return below; - } -} - jit_float64 jit_float64_sin(jit_float64 value1) { #if defined(HAVE_SIN) @@ -2663,11 +2487,9 @@ jit_int jit_nfloat_sign(jit_nfloat value1) * @deftypefunx jit_nfloat jit_nfloat_asin (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_atan (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_atan2 (jit_nfloat @var{value1}, jit_nfloat @var{value2}) - * @deftypefunx jit_nfloat jit_nfloat_ceil (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_cos (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_cosh (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_exp (jit_nfloat @var{value1}) - * @deftypefunx jit_nfloat jit_nfloat_floor (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_log (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_log10 (jit_nfloat @var{value1}) * @deftypefunx jit_nfloat jit_nfloat_pow (jit_nfloat @var{value1}, jit_nfloat @var{value2}) @@ -2723,17 +2545,6 @@ jit_nfloat jit_nfloat_atan2(jit_nfloat value1, jit_nfloat value2) #endif } -jit_nfloat jit_nfloat_ceil(jit_nfloat value1) -{ -#if defined(HAVE_CEILL) && !defined(JIT_NFLOAT_IS_DOUBLE) - return (jit_nfloat)(ceill(value1)); -#elif defined(HAVE_CEIL) - return (jit_nfloat)(ceil(value1)); -#else - return jit_nfloat_nan; -#endif -} - jit_nfloat jit_nfloat_cos(jit_nfloat value1) { #if defined(HAVE_COSL) && !defined(JIT_NFLOAT_IS_DOUBLE) @@ -2767,17 +2578,6 @@ jit_nfloat jit_nfloat_exp(jit_nfloat value1) #endif } -jit_nfloat jit_nfloat_floor(jit_nfloat value1) -{ -#if defined(HAVE_FLOORL) && !defined(JIT_NFLOAT_IS_DOUBLE) - return (jit_nfloat)(floorl(value1)); -#elif defined(HAVE_FLOOR) - return (jit_nfloat)(floor(value1)); -#else - return jit_nfloat_nan; -#endif -} - jit_nfloat jit_nfloat_log(jit_nfloat value1) { #if defined(HAVE_LOGL) && !defined(JIT_NFLOAT_IS_DOUBLE) @@ -2811,98 +2611,32 @@ jit_nfloat jit_nfloat_pow(jit_nfloat value1, jit_nfloat value2) #endif } -/*@ - * @deftypefun jit_nfloat jit_nfloat_rint (jit_nfloat @var{value1}) - * Round @var{value1} to the nearest integer. Half-way cases - * are rounded to an even number. - * @end deftypefun -@*/ -jit_nfloat jit_nfloat_rint(jit_nfloat value1) +jit_nfloat jit_nfloat_sin(jit_nfloat value1) { - jit_nfloat above, below; - if(!jit_nfloat_is_finite(value1)) - { - return value1; - } - above = jit_nfloat_ceil(value1); - below = jit_nfloat_floor(value1); - if((above - value1) < (jit_nfloat)0.5) - { - return above; - } - else if((value1 - below) < (jit_nfloat)0.5) - { - return below; - } - else if(jit_nfloat_ieee_rem(above, (jit_nfloat)2.0) == (jit_nfloat)0.0) - { - return above; - } - else - { - return below; - } +#if defined(HAVE_SINL) && !defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(sinl(value1)); +#elif defined(HAVE_SIN) + return (jit_nfloat)(sin(value1)); +#else + return jit_nfloat_nan; +#endif } -/*@ - * @deftypefun jit_nfloat jit_nfloat_round (jit_nfloat @var{value1}) - * Round @var{value1} to the nearest integer. Half-way cases - * are rounded away from zero. - * @end deftypefun -@*/ -jit_nfloat jit_nfloat_round(jit_nfloat value1) +jit_nfloat jit_nfloat_sinh(jit_nfloat value1) { - jit_nfloat above, below; - if(!jit_nfloat_is_finite(value1)) - { - return value1; - } - above = jit_nfloat_ceil(value1); - below = jit_nfloat_floor(value1); - if((above - value1) < (jit_nfloat)0.5) - { - return above; - } - else if((value1 - below) < (jit_nfloat)0.5) - { - return below; - } - else if(above >= (jit_nfloat)0.0) - { - return above; - } - else - { - return below; - } -} - -jit_nfloat jit_nfloat_sin(jit_nfloat value1) -{ -#if defined(HAVE_SINL) && !defined(JIT_NFLOAT_IS_DOUBLE) - return (jit_nfloat)(sinl(value1)); -#elif defined(HAVE_SIN) - return (jit_nfloat)(sin(value1)); -#else - return jit_nfloat_nan; -#endif -} - -jit_nfloat jit_nfloat_sinh(jit_nfloat value1) -{ -#if defined(HAVE_SINHL) && !defined(JIT_NFLOAT_IS_DOUBLE) - return (jit_nfloat)(sinhl(value1)); -#elif defined(HAVE_SINH) - return (jit_nfloat)(sinh(value1)); -#else - return jit_nfloat_nan; -#endif -} - -jit_nfloat jit_nfloat_sqrt(jit_nfloat value1) -{ - /* Some platforms give a SIGFPE for negative arguments (e.g. Alpha) */ - if(value1 < (jit_nfloat)0.0) +#if defined(HAVE_SINHL) && !defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(sinhl(value1)); +#elif defined(HAVE_SINH) + return (jit_nfloat)(sinh(value1)); +#else + return jit_nfloat_nan; +#endif +} + +jit_nfloat jit_nfloat_sqrt(jit_nfloat value1) +{ + /* Some platforms give a SIGFPE for negative arguments (e.g. Alpha) */ + if(value1 < (jit_nfloat)0.0) { return jit_nfloat_nan; } @@ -3024,6 +2758,352 @@ jit_int jit_nfloat_is_inf(jit_nfloat value) } } +/*@ + * Floatingpoint rounding operations.defined by ieee754 + * @deftypefun jit_float32 jit_float32_rint (jit_float32 @var{value1}) + * @deftypefunx jit_float64 jit_float64_rint (jit_float64 @var{value1}) + * @deftypefunx jit_nfloat jit_nfloat_rint (jit_nfloat @var{value1}) + * Round @var{value1} to the nearest integer. Half-way cases + * are rounded to an even number. + * @end deftypefun + * @deftypefun jit_float32 jit_float32_ceil (jit_float32 @var{value1}) + * @deftypefunx jit_float64 jit_float64_ceil (jit_float64 @var{value1}) + * @deftypefunx jit_nfloat jit_nfloat_ceil (jit_nfloat @var{value1}) + * Round @var{value1} up towards positive infinity. + * @end deftypefun + * @deftypefun jit_float32 jit_float32_floor (jit_float32 @var{value1}) + * @deftypefunx jit_float64 jit_float64_floor (jit_float64 @var{value1}) + * @deftypefunx jit_nfloat jit_nfloat_floor (jit_nfloat @var{value1}) + * Round @var{value1} down towards negative infinity. + * @end deftypefun + * @deftypefun jit_float32 jit_float32_trunc (jit_float32 @var{value1}) + * @deftypefunx jit_float64 jit_float64_trunc (jit_float64 @var{value1}) + * @deftypefunx jit_nfloat jit_nfloat_trunc (jit_nfloat @var{value1}) + * Round @var{value1} towards zero. + * @end deftypefun +@*/ + +/* + * NOTE: rint rounds the value according to the current rounding mode. + * The default rounding mode is round to nearest with half way cases + * rounded to the even number. So there is no need to set the rounding + * mode here. + */ +jit_float32 jit_float32_rint(jit_float32 value1) +{ +#ifdef HAVE_RINTF + return (jit_float32)rintf(value1); +#elif defined(HAVE_RINT) + return (jit_float32)(rint(value1)); +#else + jit_float32 above, below; + if(!jit_float32_is_finite(value1)) + { + return value1; + } + above = jit_float32_ceil(value1); + below = jit_float32_floor(value1); + if((above - value1) < (jit_float32)0.5) + { + return above; + } + else if((value1 - below) < (jit_float32)0.5) + { + return below; + } + else if(jit_float32_ieee_rem(above, (jit_float32)2.0) == (jit_float32)0.0) + { + return above; + } + else + { + return below; + } +#endif +} + +jit_float64 jit_float64_rint(jit_float64 value1) +{ +#ifdef HAVE_RINT + return (jit_float64)rint(value1); +#else + jit_float64 above, below; + if(!jit_float64_is_finite(value1)) + { + return value1; + } + above = jit_float64_ceil(value1); + below = jit_float64_floor(value1); + if((above - value1) < (jit_float64)0.5) + { + return above; + } + else if((value1 - below) < (jit_float64)0.5) + { + return below; + } + else if(jit_float64_ieee_rem(above, (jit_float64)2.0) == (jit_float64)0.0) + { + return above; + } + else + { + return below; + } +#endif +} + +jit_nfloat jit_nfloat_rint(jit_nfloat value1) +{ +#if defined(HAVE_RINTL) && !defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(rintl(value1)); +#elif defined(HAVE_RINT) && defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(rint(value1)); +#else + jit_nfloat above, below; + if(!jit_nfloat_is_finite(value1)) + { + return value1; + } + above = jit_nfloat_ceil(value1); + below = jit_nfloat_floor(value1); + if((above - value1) < (jit_nfloat)0.5) + { + return above; + } + else if((value1 - below) < (jit_nfloat)0.5) + { + return below; + } + else if(jit_nfloat_ieee_rem(above, (jit_nfloat)2.0) == (jit_nfloat)0.0) + { + return above; + } + else + { + return below; + } +#endif +} + +jit_float32 jit_float32_ceil(jit_float32 value1) +{ +#if defined(HAVE_CEILF) + return (jit_float32)(ceilf(value1)); +#elif defined(HAVE_CEIL) + return (jit_float32)(ceil(value1)); +#else + return jit_float32_nan; +#endif +} + +jit_float64 jit_float64_ceil(jit_float64 value1) +{ +#if defined(HAVE_CEIL) + return (jit_float64)(ceil(value1)); +#else + return jit_float64_nan; +#endif +} + +jit_nfloat jit_nfloat_ceil(jit_nfloat value1) +{ +#if defined(HAVE_CEILL) && !defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(ceill(value1)); +#elif defined(HAVE_CEIL) && defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(ceil(value1)); +#else + return jit_nfloat_nan; +#endif +} + +jit_float32 jit_float32_floor(jit_float32 value1) +{ +#if defined(HAVE_FLOORF) + return (jit_float32)(floorf(value1)); +#elif defined(HAVE_FLOOR) + return (jit_float32)(floor(value1)); +#else + return jit_float32_nan; +#endif +} + +jit_float64 jit_float64_floor(jit_float64 value1) +{ +#if defined(HAVE_FLOOR) + return (jit_float64)(floor(value1)); +#else + return jit_float64_nan; +#endif +} + +jit_nfloat jit_nfloat_floor(jit_nfloat value1) +{ +#if defined(HAVE_FLOORL) && !defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(floorl(value1)); +#elif defined(HAVE_FLOOR) && defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(floor(value1)); +#else + return jit_nfloat_nan; +#endif +} + +jit_float32 jit_float32_trunc(jit_float32 value1) +{ +#if defined(HAVE_TRUNCF) + return (jit_float32)(truncf(value1)); +#elif defined(HAVE_TRUNC) + return (jit_float32)(trunc(value1)); +#else + if(value1 > 0) + { + return jit_float32_floor(value1); + } + else + { + return jit_float32_ceil(value1); + } +#endif +} + +jit_float64 jit_float64_trunc(jit_float64 value1) +{ +#if defined(HAVE_TRUNC) + return (jit_float64)(trunc(value1)); +#else + if(value1 > 0) + { + return jit_float64_floor(value1); + } + else + { + return jit_float64_ceil(value1); + } +#endif +} + +jit_nfloat jit_nfloat_trunc(jit_nfloat value1) +{ +#if defined(HAVE_TRUNCL) && !defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(truncl(value1)); +#elif defined(HAVE_TRUNC) && defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(trunc(value1)); +#else + if(value1 > 0) + { + return jit_nfloat_floor(value1); + } + else + { + return jit_nfloat_ceil(value1); + } +#endif +} + +/*@ + * Floatingpoint rounding operations.not covered by ieee754 + * @deftypefun jit_float32 jit_float32_round (jit_float32 @var{value1}) + * @deftypefunx jit_float64 jit_float64_round (jit_float64 @var{value1}) + * @deftypefunx jit_nfloat jit_nfloat_round (jit_nfloat @var{value1}) + * Round @var{value1} to the nearest integer. Half-way cases + * are rounded away from zero. + * @end deftypefun +@*/ +jit_float32 jit_float32_round(jit_float32 value1) +{ +#ifdef HAVE_ROUNDF + return (jit_float32)roundf(value1); +#else + jit_float32 above, below; + if(!jit_float32_is_finite(value1)) + { + return value1; + } + above = jit_float32_ceil(value1); + below = jit_float32_floor(value1); + if((above - value1) < (jit_float32)0.5) + { + return above; + } + else if((value1 - below) < (jit_float32)0.5) + { + return below; + } + else if(above >= (jit_float32)0.0) + { + return above; + } + else + { + return below; + } +#endif +} + +jit_float64 jit_float64_round(jit_float64 value1) +{ +#ifdef HAVE_ROUND + return (jit_float64)round(value1); +#else + jit_float64 above, below; + if(!jit_float64_is_finite(value1)) + { + return value1; + } + above = jit_float64_ceil(value1); + below = jit_float64_floor(value1); + if((above - value1) < (jit_float64)0.5) + { + return above; + } + else if((value1 - below) < (jit_float64)0.5) + { + return below; + } + else if(above >= (jit_float64)0.0) + { + return above; + } + else + { + return below; + } +#endif +} + +jit_nfloat jit_nfloat_round(jit_nfloat value1) +{ +#if defined(HAVE_ROUNDL) && !defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(roundl(value1)); +#elif defined(HAVE_ROUND) && defined(JIT_NFLOAT_IS_DOUBLE) + return (jit_nfloat)(round(value1)); +#else + jit_nfloat above, below; + if(!jit_nfloat_is_finite(value1)) + { + return value1; + } + above = jit_nfloat_ceil(value1); + below = jit_nfloat_floor(value1); + if((above - value1) < (jit_nfloat)0.5) + { + return above; + } + else if((value1 - below) < (jit_nfloat)0.5) + { + return below; + } + else if(above >= (jit_nfloat)0.0) + { + return above; + } + else + { + return below; + } +#endif +} + /*@ * @deftypefun jit_int jit_int_to_sbyte (jit_int @var{value}) * @deftypefunx jit_int jit_int_to_ubyte (jit_int @var{value}) diff --git a/jit/jit-symbol.c b/jit/jit-symbol.c index 9b74d1c..61b6f64 100644 --- a/jit/jit-symbol.c +++ b/jit/jit-symbol.c @@ -86,6 +86,7 @@ jit_internalsym const _jit_internal_symbols[] = { {"jit_float32_to_uint_ovf", (void *)jit_float32_to_uint_ovf}, {"jit_float32_to_ulong", (void *)jit_float32_to_ulong}, {"jit_float32_to_ulong_ovf", (void *)jit_float32_to_ulong_ovf}, + {"jit_float32_trunc", (void *)jit_float32_trunc}, {"jit_float64_abs", (void *)jit_float64_abs}, {"jit_float64_acos", (void *)jit_float64_acos}, {"jit_float64_add", (void *)jit_float64_add}, @@ -137,6 +138,7 @@ jit_internalsym const _jit_internal_symbols[] = { {"jit_float64_to_uint_ovf", (void *)jit_float64_to_uint_ovf}, {"jit_float64_to_ulong", (void *)jit_float64_to_ulong}, {"jit_float64_to_ulong_ovf", (void *)jit_float64_to_ulong_ovf}, + {"jit_float64_trunc", (void *)jit_float64_trunc}, {"jit_int_abs", (void *)jit_int_abs}, {"jit_int_add", (void *)jit_int_add}, {"jit_int_add_ovf", (void *)jit_int_add_ovf}, @@ -270,6 +272,7 @@ jit_internalsym const _jit_internal_symbols[] = { {"jit_nfloat_to_uint_ovf", (void *)jit_nfloat_to_uint_ovf}, {"jit_nfloat_to_ulong", (void *)jit_nfloat_to_ulong}, {"jit_nfloat_to_ulong_ovf", (void *)jit_nfloat_to_ulong_ovf}, + {"jit_nfloat_trunc", (void *)jit_nfloat_trunc}, {"jit_uint_add", (void *)jit_uint_add}, {"jit_uint_add_ovf", (void *)jit_uint_add_ovf}, {"jit_uint_and", (void *)jit_uint_and},