am 5bf79420
: Merge "Revert "Revert "Use compiler builtins for fabs."""
* commit '5bf7942008287381e6d2aa2216d9ded24f639142': Revert "Revert "Use compiler builtins for fabs.""
This commit is contained in:
commit
0ed97d1b5f
@ -258,3 +258,29 @@ void BM_math_signbit::Run(int iters, double value) {
|
||||
|
||||
StopBenchmarkTiming();
|
||||
}
|
||||
|
||||
BENCHMARK_WITH_ARG(BM_math_fabs_macro, double)->AT_COMMON_VALS;
|
||||
void BM_math_fabs_macro::Run(int iters, double value) {
|
||||
StartBenchmarkTiming();
|
||||
|
||||
d = 0.0;
|
||||
v = value;
|
||||
for (int i = 0; i < iters; ++i) {
|
||||
d += fabs(v);
|
||||
}
|
||||
|
||||
StopBenchmarkTiming();
|
||||
}
|
||||
|
||||
BENCHMARK_WITH_ARG(BM_math_fabs, double)->AT_COMMON_VALS;
|
||||
void BM_math_fabs::Run(int iters, double value) {
|
||||
StartBenchmarkTiming();
|
||||
|
||||
d = 0.0;
|
||||
v = value;
|
||||
for (int i = 0; i < iters; ++i) {
|
||||
d += (fabs)(v);
|
||||
}
|
||||
|
||||
StopBenchmarkTiming();
|
||||
}
|
||||
|
@ -108,8 +108,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 \
|
||||
@ -175,7 +173,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 \
|
||||
@ -228,6 +225,10 @@ LOCAL_SRC_FILES += \
|
||||
LOCAL_SRC_FILES += \
|
||||
signbit.c \
|
||||
|
||||
# Home-grown stuff.
|
||||
LOCAL_SRC_FILES += \
|
||||
fabs.cpp \
|
||||
|
||||
# Arch specific optimizations.
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -481,6 +482,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 \
|
||||
|
46
libm/fabs.cpp
Normal file
46
libm/fabs.cpp
Normal file
@ -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
|
@ -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); }
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user