diff options
author | Elliott Hughes <enh@google.com> | 2015-08-24 22:57:08 +0000 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-11-07 01:42:32 -0800 |
commit | 245c1718cb035268284bea8dabe3faa3f8326ee8 (patch) | |
tree | b3cba5f5b664b0e11cdfb4c980fc05d11724ece9 /libm | |
parent | ea4e4e7c8c65e0cc3d087ba4d867851b840b9680 (diff) | |
download | bionic-245c1718cb035268284bea8dabe3faa3f8326ee8.zip bionic-245c1718cb035268284bea8dabe3faa3f8326ee8.tar.gz bionic-245c1718cb035268284bea8dabe3faa3f8326ee8.tar.bz2 |
Revert "Revert "Use compiler builtins for fabs.""
Don't enable the inlines when building libm itself. Otherwise clang gets
upset by seeing both an inline and a non-inline definition.
This reverts commit c5deb0f883cbdca7e5ab75f92f82c31d21367f49.
Change-Id: If7abdb351f5a5549d6a331b33af408e8fcfa9868
Diffstat (limited to 'libm')
-rw-r--r-- | libm/Android.mk | 8 | ||||
-rw-r--r-- | libm/fabs.cpp | 46 | ||||
-rw-r--r-- | libm/fake_long_double.c | 1 | ||||
-rw-r--r-- | libm/include/math.h | 9 | ||||
-rw-r--r-- | libm/upstream-freebsd/lib/msun/src/s_fabs.c | 31 | ||||
-rw-r--r-- | libm/upstream-freebsd/lib/msun/src/s_fabsf.c | 33 |
6 files changed, 60 insertions, 68 deletions
diff --git a/libm/Android.mk b/libm/Android.mk index 52e3386..7535f20 100644 --- a/libm/Android.mk +++ b/libm/Android.mk @@ -107,8 +107,6 @@ LOCAL_SRC_FILES := \ upstream-freebsd/lib/msun/src/s_exp2.c \ upstream-freebsd/lib/msun/src/s_exp2f.c \ upstream-freebsd/lib/msun/src/s_expm1f.c \ - upstream-freebsd/lib/msun/src/s_fabs.c \ - upstream-freebsd/lib/msun/src/s_fabsf.c \ upstream-freebsd/lib/msun/src/s_fdim.c \ upstream-freebsd/lib/msun/src/s_finite.c \ upstream-freebsd/lib/msun/src/s_finitef.c \ @@ -174,7 +172,6 @@ LOCAL_SRC_FILES_64 := \ upstream-freebsd/lib/msun/src/s_copysignl.c \ upstream-freebsd/lib/msun/src/e_coshl.c \ upstream-freebsd/lib/msun/src/s_cosl.c \ - upstream-freebsd/lib/msun/src/s_fabsl.c \ upstream-freebsd/lib/msun/src/s_floorl.c \ upstream-freebsd/lib/msun/src/s_fmal.c \ upstream-freebsd/lib/msun/src/s_fmaxl.c \ @@ -227,6 +224,10 @@ LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \ signbit.c \ +# Home-grown stuff. +LOCAL_SRC_FILES += \ + fabs.cpp \ + # Arch specific optimizations. # ----------------------------------------------------------------------------- @@ -480,6 +481,7 @@ LOCAL_C_INCLUDES_64 += $(LOCAL_PATH)/upstream-freebsd/lib/msun/ld128/ LOCAL_CLANG := $(libm_clang) LOCAL_ARM_MODE := arm LOCAL_CFLAGS := \ + -D__BIONIC_NO_MATH_INLINES \ -DFLT_EVAL_METHOD=0 \ -include $(LOCAL_PATH)/freebsd-compat.h \ -Wno-missing-braces \ diff --git a/libm/fabs.cpp b/libm/fabs.cpp new file mode 100644 index 0000000..add73fe --- /dev/null +++ b/libm/fabs.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <math.h> + +#include "fpmath.h" + +double fabs(double x) { +#if __arm__ + // Both Clang and GCC insist on moving r0/r1 into a double register + // and using fabs where bit-twiddling would be a better choice. + // They get fabsf right, but we need to be careful in fabsl too. + IEEEd2bits u; + u.d = x; + u.bits.sign = 0; + return u.d; +#else + return __builtin_fabs(x); +#endif +} + +float fabsf(float x) { + return __builtin_fabsf(x); +} + +#if defined(__LP64__) +long double fabsl(long double x) { return __builtin_fabsl(x); } +#else +long double fabsl(long double x) { + // Don't use __builtin_fabs here because of ARM. (See fabs above.) + return fabs(x); +} +#endif diff --git a/libm/fake_long_double.c b/libm/fake_long_double.c index 317a115..5edf839 100644 --- a/libm/fake_long_double.c +++ b/libm/fake_long_double.c @@ -25,7 +25,6 @@ */ long double copysignl(long double a1, long double a2) { return copysign(a1, a2); } -long double fabsl(long double a1) { return fabs(a1); } long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); } long double fmodl(long double a1, long double a2) { return fmod(a1, a2); } long double fminl(long double a1, long double a2) { return fmin(a1, a2); } diff --git a/libm/include/math.h b/libm/include/math.h index bc48b6a..ce8e3b2 100644 --- a/libm/include/math.h +++ b/libm/include/math.h @@ -20,6 +20,12 @@ #include <sys/cdefs.h> #include <limits.h> +#if !defined(__BIONIC_NO_MATH_INLINES) +#define __BIONIC_MATH_INLINE(__def) extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__)) __def +#else +#define __BIONIC_MATH_INLINE(__def) +#endif + __BEGIN_DECLS #pragma GCC visibility push(default) @@ -161,6 +167,7 @@ double sqrt(double); double ceil(double); double fabs(double) __pure2; +__BIONIC_MATH_INLINE(double fabs(double x) { return __builtin_fabs(x); }) double floor(double); double fmod(double, double); @@ -279,6 +286,7 @@ float sqrtf(float); float ceilf(float); float fabsf(float) __pure2; +__BIONIC_MATH_INLINE(float fabsf(float x) { return __builtin_fabsf(x); }) float floorf(float); float fmodf(float, float); float roundf(float); @@ -366,6 +374,7 @@ long double exp2l(long double); long double expl(long double); long double expm1l(long double); long double fabsl(long double) __pure2; +__BIONIC_MATH_INLINE(long double fabsl(long double x) { return __builtin_fabsl(x); }) long double fdiml(long double, long double); long double floorl(long double); long double fmal(long double, long double, long double); diff --git a/libm/upstream-freebsd/lib/msun/src/s_fabs.c b/libm/upstream-freebsd/lib/msun/src/s_fabs.c deleted file mode 100644 index 15529e5..0000000 --- a/libm/upstream-freebsd/lib/msun/src/s_fabs.c +++ /dev/null @@ -1,31 +0,0 @@ -/* @(#)s_fabs.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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD$"; -#endif - -/* - * fabs(x) returns the absolute value of x. - */ - -#include "math.h" -#include "math_private.h" - -double -fabs(double x) -{ - u_int32_t high; - GET_HIGH_WORD(high,x); - SET_HIGH_WORD(x,high&0x7fffffff); - return x; -} diff --git a/libm/upstream-freebsd/lib/msun/src/s_fabsf.c b/libm/upstream-freebsd/lib/msun/src/s_fabsf.c deleted file mode 100644 index e9383d0..0000000 --- a/libm/upstream-freebsd/lib/msun/src/s_fabsf.c +++ /dev/null @@ -1,33 +0,0 @@ -/* s_fabsf.c -- float version of s_fabs.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@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. - * ==================================================== - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -/* - * fabsf(x) returns the absolute value of x. - */ - -#include "math.h" -#include "math_private.h" - -float -fabsf(float x) -{ - u_int32_t ix; - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(x,ix&0x7fffffff); - return x; -} |