aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--benchmarks/math_benchmark.cpp13
-rw-r--r--libc/NOTICE26
-rw-r--r--libc/bionic/fpclassify.cpp131
-rw-r--r--libc/include/math.h24
-rw-r--r--libm/Android.bp4
-rw-r--r--libm/signbit.c59
-rw-r--r--libm/signbit.cpp44
-rw-r--r--tests/math_test.cpp28
8 files changed, 109 insertions, 220 deletions
diff --git a/benchmarks/math_benchmark.cpp b/benchmarks/math_benchmark.cpp
index 7b9a28321..4d9d3cb54 100644
--- a/benchmarks/math_benchmark.cpp
+++ b/benchmarks/math_benchmark.cpp
@@ -69,16 +69,11 @@ static void BM_math_isfinite_macro(benchmark::State& state) {
}
BIONIC_BENCHMARK(BM_math_isfinite_macro);
-#if defined(__BIONIC__)
-#define test_isfinite __isfinite
-#else
-#define test_isfinite __finite
-#endif
static void BM_math_isfinite(benchmark::State& state) {
d = 0.0;
v = values[state.range(0)];
while (state.KeepRunning()) {
- d += test_isfinite(v);
+ d += isfinite(v);
}
SetLabel(state);
}
@@ -134,17 +129,15 @@ static void BM_math_isnormal_macro(benchmark::State& state) {
}
BIONIC_BENCHMARK(BM_math_isnormal_macro);
-#if defined(__BIONIC__)
static void BM_math_isnormal(benchmark::State& state) {
d = 0.0;
v = values[state.range(0)];
while (state.KeepRunning()) {
- d += (__isnormal)(v);
+ d += isnormal(v);
}
SetLabel(state);
}
BIONIC_BENCHMARK(BM_math_isnormal);
-#endif
static void BM_math_sin_fast(benchmark::State& state) {
d = 1.0;
@@ -202,7 +195,7 @@ static void BM_math_signbit(benchmark::State& state) {
d = 0.0;
v = values[state.range(0)];
while (state.KeepRunning()) {
- d += (__signbit)(v);
+ d += signbit(v);
}
SetLabel(state);
}
diff --git a/libc/NOTICE b/libc/NOTICE
index c0e62651e..cbcafc8d3 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -3812,32 +3812,6 @@ SUCH DAMAGE.
-------------------------------------------------------------------
Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
Copyright (c) 2002 David Schultz <das@FreeBSD.ORG>
All rights reserved.
diff --git a/libc/bionic/fpclassify.cpp b/libc/bionic/fpclassify.cpp
index 42ed3ef0e..7aa53f3e8 100644
--- a/libc/bionic/fpclassify.cpp
+++ b/libc/bionic/fpclassify.cpp
@@ -26,145 +26,80 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-
#include <math.h>
-#include "private/bionic_ieee.h"
-
-// These aren't declared in our <math.h>.
-extern "C" int __isinf(double);
-extern "C" int __isnan(double);
-
-union float_u {
- float f;
- ieee_single bits;
-};
-
-union double_u {
- double d;
- ieee_double bits;
-};
-
-int __fpclassifyd(double d) {
- double_u u;
- u.d = d;
- if (u.bits.dbl_exp == 0) {
- return ((u.bits.dbl_fracl | u.bits.dbl_frach) == 0) ? FP_ZERO : FP_SUBNORMAL;
- }
- if (u.bits.dbl_exp == DBL_EXP_INFNAN) {
- return ((u.bits.dbl_fracl | u.bits.dbl_frach) == 0) ? FP_INFINITE : FP_NAN;
- }
- return FP_NORMAL;
+// Legacy cruft from before we had builtin implementations of the standard macros.
+// No longer declared in our <math.h>.
+
+extern "C" int __fpclassifyd(double d) {
+ return fpclassify(d);
}
__strong_alias(__fpclassify, __fpclassifyd); // glibc uses __fpclassify, BSD __fpclassifyd.
-int __fpclassifyf(float f) {
- float_u u;
- u.f = f;
- if (u.bits.sng_exp == 0) {
- return (u.bits.sng_frac == 0) ? FP_ZERO : FP_SUBNORMAL;
- }
- if (u.bits.sng_exp == SNG_EXP_INFNAN) {
- return (u.bits.sng_frac == 0) ? FP_INFINITE : FP_NAN;
- }
- return FP_NORMAL;
+extern "C" int __fpclassifyf(float f) {
+ return fpclassify(f);
}
-int __isinf(double d) {
- return (__fpclassifyd(d) == FP_INFINITE);
+extern "C" int __isinf(double d) {
+ return isinf(d);
}
__strong_alias(isinf, __isinf);
-int __isinff(float f) {
- return (__fpclassifyf(f) == FP_INFINITE);
+extern "C" int __isinff(float f) {
+ return isinf(f);
}
__strong_alias(isinff, __isinff);
-int __isnan(double d) {
- return (__fpclassifyd(d) == FP_NAN);
+extern "C" int __isnan(double d) {
+ return isnan(d);
}
__strong_alias(isnan, __isnan);
-int __isnanf(float f) {
- return (__fpclassifyf(f) == FP_NAN);
+extern "C" int __isnanf(float f) {
+ return isnan(f);
}
__strong_alias(isnanf, __isnanf);
-int __isfinite(double d) {
- int type = __fpclassifyd(d);
- return ((type != FP_NAN) && (type != FP_INFINITE));
+extern "C" int __isfinite(double d) {
+ return isfinite(d);
}
__strong_alias(isfinite, __isfinite);
-int __isfinitef(float f) {
- int type = __fpclassifyf(f);
- return ((type != FP_NAN) && (type != FP_INFINITE));
+extern "C" int __isfinitef(float f) {
+ return isfinite(f);
}
__strong_alias(isfinitef, __isfinitef);
-int __isnormal(double d) {
- return (__fpclassifyd(d) == FP_NORMAL);
+extern "C" int __isnormal(double d) {
+ return isnormal(d);
}
__strong_alias(isnormal, __isnormal);
-int __isnormalf(float f) {
- return (__fpclassifyf(f) == FP_NORMAL);
+extern "C" int __isnormalf(float f) {
+ return isnormal(f);
}
__strong_alias(isnormalf, __isnormalf);
-#if defined(__LP64__)
-
-// LP64 uses 128-bit long doubles.
-
-union long_double_u {
- long double ld;
- ieee_ext bits;
-};
-
-#define zero_frac(b) ((b.ext_fracl | b.ext_fraclm | b.ext_frachm | b.ext_frach) == 0)
-
-int __fpclassifyl(long double ld) {
- long_double_u u;
- u.ld = ld;
- if (u.bits.ext_exp == 0) {
- return zero_frac(u.bits) ? FP_ZERO : FP_SUBNORMAL;
- }
- if (u.bits.ext_exp == EXT_EXP_INFNAN) {
- return zero_frac(u.bits) ? FP_INFINITE : FP_NAN;
- }
- return FP_NORMAL;
+extern "C" int __fpclassifyl(long double ld) {
+ return fpclassify(ld);
}
-int __isinfl(long double ld) {
- return (__fpclassifyl(ld) == FP_INFINITE);
+extern "C" int __isinfl(long double ld) {
+ return isinf(ld);
}
-int __isnanl(long double ld) {
- return (__fpclassifyl(ld) == FP_NAN);
+extern "C" int __isnanl(long double ld) {
+ return isnan(ld);
}
-int __isfinitel(long double ld) {
- int type = __fpclassifyl(ld);
- return ((type != FP_NAN) && (type != FP_INFINITE));
+extern "C" int __isfinitel(long double ld) {
+ return isfinite(ld);
}
-int __isnormall(long double ld) {
- return (__fpclassifyl(ld) == FP_NORMAL);
+extern "C" int __isnormall(long double ld) {
+ return isnormal(ld);
}
-#else
-
-// LP32 uses double as long double.
-
-__strong_alias(__fpclassifyl, __fpclassify);
-__strong_alias(__isinfl, __isinf);
-__strong_alias(__isnanl, __isnan);
-__strong_alias(__isfinitel, __isfinite);
-__strong_alias(__isnormall, __isnormal);
-
-#endif
-
__strong_alias(isinfl, __isinfl);
__strong_alias(isnanl, __isnanl);
__strong_alias(isfinitel, __isfinitel);
diff --git a/libc/include/math.h b/libc/include/math.h
index 6f8b86316..57ca2600a 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -352,30 +352,6 @@ double yn(int __n, double __x);
#define MAXFLOAT ((float)3.40282346638528860e+38)
-/* Legacy cruft from before we had builtin implementations of the standard macros. */
-
-int __fpclassifyd(double __x) __attribute_const__;
-int __fpclassifyf(float __x) __attribute_const__;
-int __fpclassifyl(long double __x) __attribute_const__;
-
-int __isfinitef(float __x) __attribute_const__;
-int __isfinite(double __x) __attribute_const__;
-int __isfinitel(long double __x) __attribute_const__;
-
-int __isinff(float __x) __attribute_const__;
-int __isinfl(long double __x) __attribute_const__;
-
-int __isnanf(float __x) __attribute_const__ __INTRODUCED_IN(21);
-int __isnanl(long double __x) __attribute_const__;
-
-int __isnormal(double __x) __attribute_const__;
-int __isnormalf(float __x) __attribute_const__;
-int __isnormall(long double __x) __attribute_const__;
-
-int __signbit(double __x) __attribute_const__;
-int __signbitf(float __x) __attribute_const__;
-int __signbitl(long double __x) __attribute_const__;
-
/* BSD extensions. */
#if defined(__USE_BSD)
diff --git a/libm/Android.bp b/libm/Android.bp
index bf8626450..da9c9a8e7 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -210,11 +210,9 @@ cc_library {
"sincos.c",
"fake_long_double.c",
- // Modified versions of BSD code.
- "signbit.c",
-
// Home-grown stuff.
"fabs.cpp",
+ "signbit.cpp",
],
multilib: {
diff --git a/libm/signbit.c b/libm/signbit.c
deleted file mode 100644
index b98bf45c5..000000000
--- a/libm/signbit.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <math.h>
-
-#include "fpmath.h"
-
-int __signbit(double d)
-{
- union IEEEd2bits u;
-
- u.d = d;
- return (u.bits.sign);
-}
-
-int __signbitf(float f)
-{
- union IEEEf2bits u;
-
- u.f = f;
- return (u.bits.sign);
-}
-
-#ifdef __LP64__
-int __signbitl(long double e)
-{
- union IEEEl2bits u;
-
- u.e = e;
- return (u.bits.sign);
-}
-#else // __LP32__
-__weak_reference(__signbit, __signbitl);
-#endif // __LP64__
diff --git a/libm/signbit.cpp b/libm/signbit.cpp
new file mode 100644
index 000000000..b2a5d6087
--- /dev/null
+++ b/libm/signbit.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+// Legacy cruft from before we had builtin implementations of the standard macros.
+// No longer declared in our <math.h>.
+
+extern "C" int __signbit(double d) {
+ return signbit(d);
+}
+
+extern "C" int __signbitf(float f) {
+ return signbit(f);
+}
+
+extern "C" int __signbitl(long double ld) {
+ return signbit(ld);
+}
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
index 0fc4e505a..466e6979c 100644
--- a/tests/math_test.cpp
+++ b/tests/math_test.cpp
@@ -176,6 +176,11 @@ TEST(MATH_TEST, signbit) {
ASSERT_NE(0, test_capture_signbit(-1.0L));
}
+// Historical BSD cruft that isn't exposed in <math.h> any more.
+extern "C" int __fpclassifyd(double);
+extern "C" int __fpclassifyf(float);
+extern "C" int __fpclassifyl(long double);
+
TEST(MATH_TEST, __fpclassifyd) {
#if defined(__GLIBC__)
#define __fpclassifyd __fpclassify
@@ -208,6 +213,11 @@ TEST(MATH_TEST, finitef) {
ASSERT_FALSE(finitef(HUGE_VALF));
}
+// Historical BSD cruft that isn't exposed in <math.h> any more.
+extern "C" int __isfinite(double);
+extern "C" int __isfinitef(float);
+extern "C" int __isfinitel(long double);
+
TEST(MATH_TEST, __isfinite) {
#if defined(__GLIBC__)
#define __isfinite __finite
@@ -243,6 +253,10 @@ TEST(MATH_TEST, isinf_function) {
ASSERT_TRUE((isinf)(HUGE_VAL));
}
+// Historical BSD cruft that isn't exposed in <math.h> any more.
+extern "C" int __isinff(float);
+extern "C" int __isinfl(long double);
+
TEST(MATH_TEST, __isinff) {
ASSERT_FALSE(__isinff(123.0f));
ASSERT_TRUE(__isinff(HUGE_VALF));
@@ -259,6 +273,10 @@ TEST(MATH_TEST, isnan_function) {
ASSERT_TRUE((isnan)(nan("")));
}
+// Historical BSD cruft that isn't exposed in <math.h> any more.
+extern "C" int __isnanf(float);
+extern "C" int __isnanl(long double);
+
TEST(MATH_TEST, __isnanf) {
ASSERT_FALSE(__isnanf(123.0f));
ASSERT_TRUE(__isnanf(nanf("")));
@@ -274,6 +292,11 @@ TEST(MATH_TEST, isnanf) {
ASSERT_TRUE(isnanf(nanf("")));
}
+// Historical BSD cruft that isn't exposed in <math.h> any more.
+extern "C" int __isnormal(double);
+extern "C" int __isnormalf(float);
+extern "C" int __isnormall(long double);
+
TEST(MATH_TEST, __isnormal) {
#if defined(__BIONIC__)
ASSERT_TRUE(__isnormal(123.0));
@@ -301,6 +324,11 @@ TEST(MATH_TEST, __isnormall) {
#endif // __BIONIC__
}
+// Historical BSD cruft that isn't exposed in <math.h> any more.
+extern "C" int __signbit(double);
+extern "C" int __signbitf(float);
+extern "C" int __signbitl(long double);
+
TEST(MATH_TEST, __signbit) {
ASSERT_EQ(0, __signbit(0.0));
ASSERT_EQ(0, __signbit(1.0));