From 894dfa1e75b2178aa488ae650ea7e274550b585f Mon Sep 17 00:00:00 2001 From: Sam Toyer Date: Sun, 2 Dec 2012 00:08:31 +1000 Subject: [PATCH] Add glibc ilogbl implemenation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Duval --- .../posix/glibc/arch/generic/e_ilogbl.c | 59 +++++++++++++++++++ .../posix/glibc/arch/generic/w_ilogbl.c | 38 ++++++++++++ .../libroot/posix/glibc/arch/x86/Jamfile | 2 + .../libroot/posix/glibc/arch/x86_64/Jamfile | 22 +++---- 4 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 src/system/libroot/posix/glibc/arch/generic/e_ilogbl.c create mode 100644 src/system/libroot/posix/glibc/arch/generic/w_ilogbl.c diff --git a/src/system/libroot/posix/glibc/arch/generic/e_ilogbl.c b/src/system/libroot/posix/glibc/arch/generic/e_ilogbl.c new file mode 100644 index 0000000000..0c7d9d5440 --- /dev/null +++ b/src/system/libroot/posix/glibc/arch/generic/e_ilogbl.c @@ -0,0 +1,59 @@ +/* s_ilogbl.c -- long double version of s_ilogb.c. + * Conversion to long double by Ulrich Drepper, + * Cygnus Support, drepper@cygnus.com. + */ + +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +/* ilogbl(long double x) + * return the binary exponent of non-zero x + * ilogbl(0) = FP_ILOGB0 + * ilogbl(NaN) = FP_ILOGBNAN (no signal is raised) + * ilogbl(+-Inf) = INT_MAX (no signal is raised) + */ + +#include +#include +#include + +int __ieee754_ilogbl (long double x) +{ + int32_t es,hx,lx,ix; + + GET_LDOUBLE_EXP(es,x); + es &= 0x7fff; + if(es==0) { + GET_LDOUBLE_WORDS(es,hx,lx,x); + if((hx|lx)==0) + return FP_ILOGB0; /* ilogbl(0) = FP_ILOGB0 */ + else /* subnormal x */ + if(hx==0) { + for (ix = -16415; lx>0; lx<<=1) ix -=1; + } else { + for (ix = -16383; hx>0; hx<<=1) ix -=1; + } + return ix; + } + else if (es<0x7fff) return es-0x3fff; + else if (FP_ILOGBNAN != INT_MAX) + { + GET_LDOUBLE_WORDS(es,hx,lx,x); + if (((hx & 0x7fffffff)|lx) == 0) + /* ISO C99 requires ilogbl(+-Inf) == INT_MAX. */ + return INT_MAX; + } + return FP_ILOGBNAN; +} diff --git a/src/system/libroot/posix/glibc/arch/generic/w_ilogbl.c b/src/system/libroot/posix/glibc/arch/generic/w_ilogbl.c new file mode 100644 index 0000000000..e02e78c767 --- /dev/null +++ b/src/system/libroot/posix/glibc/arch/generic/w_ilogbl.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Adhemerval Zanella , 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* wrapper ilogbl */ +int +__ilogbl (long double x) +{ + int r = __ieee754_ilogbl (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + /*feraiseexcept (FE_INVALID);*/ + } + return r; +} +weak_alias (__ilogbl, ilogbl) diff --git a/src/system/libroot/posix/glibc/arch/x86/Jamfile b/src/system/libroot/posix/glibc/arch/x86/Jamfile index e6e022f19b..a8e40c7b89 100644 --- a/src/system/libroot/posix/glibc/arch/x86/Jamfile +++ b/src/system/libroot/posix/glibc/arch/x86/Jamfile @@ -34,6 +34,7 @@ local genericSources = e_j1.c e_j1f.c e_jn.c e_jnf.c e_hypotl.c + e_ilogbl.c e_lgamma_r.c e_lgammaf_r.c e_lgammal_r.c k_cos.c k_cosf.c k_sin.c k_sinf.c @@ -84,6 +85,7 @@ local genericSources = w_exp2.c w_exp2f.c w_exp2l.c w_fmod.c w_fmodf.c w_fmodl.c w_hypot.c w_hypotf.c w_hypotl.c + w_ilogbl.c w_j0.c w_j0f.c w_j1.c w_j1f.c w_jn.c w_jnf.c diff --git a/src/system/libroot/posix/glibc/arch/x86_64/Jamfile b/src/system/libroot/posix/glibc/arch/x86_64/Jamfile index 7bc592f2bc..43fdb500f4 100644 --- a/src/system/libroot/posix/glibc/arch/x86_64/Jamfile +++ b/src/system/libroot/posix/glibc/arch/x86_64/Jamfile @@ -35,10 +35,10 @@ local genericSources = e_asinl.c e_atan2.c e_atan2f.c e_atanh.c e_atanhf.c e_atanhl.c e_cosh.c e_coshf.c e_coshl.c e_exp.c e_exp10.c e_exp10f.c e_exp10l.c e_exp2.c e_exp2f.c e_expf.c e_fmod.c e_fmodf.c e_gamma_r.c e_gammaf_r.c e_gammal_r.c - e_hypot.c e_hypotf.c e_hypotl.c e_j0.c e_j0f.c e_j0l.c e_j1.c e_j1f.c - e_j1l.c e_jn.c e_jnf.c e_jnl.c e_lgamma_r.c e_lgammaf_r.c e_lgammal_r.c - e_log.c e_log10.c e_log10f.c e_log2.c e_log2f.c e_logf.c e_pow.c e_powf.c - e_rem_pio2.c e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c + e_hypot.c e_hypotf.c e_hypotl.c e_ilogbl.c e_j0.c e_j0f.c e_j0l.c e_j1.c + e_j1f.c e_j1l.c e_jn.c e_jnf.c e_jnl.c e_lgamma_r.c e_lgammaf_r.c + e_lgammal_r.c e_log.c e_log10.c e_log10f.c e_log2.c e_log2f.c e_logf.c e_pow.c + e_powf.c e_rem_pio2.c e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c e_scalbf.c e_sinh.c e_sinhf.c e_sinhl.c k_cos.c k_cosf.c k_rem_pio2.c k_rem_pio2f.c k_sin.c k_sinf.c k_tan.c @@ -75,13 +75,13 @@ local genericSources = w_atanhl.c w_cosh.c w_coshf.c w_coshl.c w_drem.c w_dremf.c w_dreml.c w_exp.c w_exp10.c w_exp10f.c w_exp10l.c w_exp2.c w_exp2f.c w_exp2l.c w_expf.c w_expl.c w_fmod.c w_fmodf.c w_fmodl.c w_hypot.c w_hypotf.c - w_hypotl.c w_j0.c w_j0f.c w_j0l.c w_j1.c w_j1f.c w_j1l.c w_jn.c w_jnf.c - w_jnl.c w_lgamma.c w_lgamma_r.c w_lgammaf.c w_lgammaf_r.c w_lgammal.c - w_lgammal_r.c w_log.c w_log10.c w_log10f.c w_log10l.c w_log2.c w_log2f.c - w_log2l.c w_logf.c w_logl.c w_pow.c w_powf.c w_powl.c w_remainder.c - w_remainderf.c w_remainderl.c w_scalb.c w_scalbf.c w_scalbl.c w_sinh.c - w_sinhf.c w_sinhl.c w_sqrt.c w_sqrtf.c w_sqrtl.c w_tgamma.c w_tgammaf.c - w_tgammal.c + w_hypotl.c w_ilogbl.c w_j0.c w_j0f.c w_j0l.c w_j1.c w_j1f.c w_j1l.c w_jn.c + w_jnf.c w_jnl.c w_lgamma.c w_lgamma_r.c w_lgammaf.c w_lgammaf_r.c + w_lgammal.c w_lgammal_r.c w_log.c w_log10.c w_log10f.c w_log10l.c w_log2.c + w_log2f.c w_log2l.c w_logf.c w_logl.c w_pow.c w_powf.c w_powl.c + w_remainder.c w_remainderf.c w_remainderl.c w_scalb.c w_scalbf.c w_scalbl.c + w_sinh.c w_sinhf.c w_sinhl.c w_sqrt.c w_sqrtf.c w_sqrtl.c w_tgamma.c + w_tgammaf.c w_tgammal.c ; local architectureObject ;