Merge "Revert "Use compiler builtins for fabs.""

This commit is contained in:
Elliott Hughes 2015-08-24 21:08:28 +00:00 committed by Gerrit Code Review
commit c868b4c351
7 changed files with 68 additions and 81 deletions

View File

@ -258,29 +258,3 @@ 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();
}

View File

@ -108,6 +108,8 @@ 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 \
@ -173,6 +175,7 @@ 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 \
@ -225,10 +228,6 @@ LOCAL_SRC_FILES += \
LOCAL_SRC_FILES += \
signbit.c \
# Home-grown stuff.
LOCAL_SRC_FILES += \
fabs.cpp \
# Arch specific optimizations.
# -----------------------------------------------------------------------------

View File

@ -1,46 +0,0 @@
/*
* 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

View File

@ -25,6 +25,7 @@
*/
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); }

View File

@ -20,8 +20,6 @@
#include <sys/cdefs.h>
#include <limits.h>
#define __BIONIC_MATH_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__))
__BEGIN_DECLS
#pragma GCC visibility push(default)
@ -163,7 +161,6 @@ 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);
@ -282,7 +279,6 @@ 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);
@ -370,7 +366,6 @@ 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);

View File

@ -0,0 +1,31 @@
/* @(#)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;
}

View File

@ -0,0 +1,33 @@
/* 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;
}