[test-suite] r204133 - Adding C-based sin/cos functions to sphereflake
Renato Golin
renato.golin at linaro.org
Tue Mar 18 03:01:37 PDT 2014
Author: rengolin
Date: Tue Mar 18 05:01:37 2014
New Revision: 204133
URL: http://llvm.org/viewvc/llvm-project?rev=204133&view=rev
Log:
Adding C-based sin/cos functions to sphereflake
Standard libraries have slightly different results on different targets.
To make the output reproducible in any target we need some C-based
implementation that is simple enough to be the same on all archs.
We could create a common test-suite library for all those functions
(sin/cos, sqrt, rand, etc) and change all tests that were cooked to
accept bogus results to use them, but that's for another commit.
Modified:
test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp
test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.reference_output
Modified: test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/Misc-C%2B%2B/Large/sphereflake.cpp?rev=204133&r1=204132&r2=204133&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp (original)
+++ test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp Tue Mar 18 05:01:37 2014
@@ -147,18 +147,55 @@ struct basis_t{ /* bogus and compact, ex
// Implementations of sin() and cos() may vary slightly in the accuracy of
// their results, typically only in the least significant bit. Round to make
// the results consistent across platforms.
-typedef union { double d; unsigned long long ll; } dbl_ll_union;
+#define FACT3 6
+#define FACT5 120
+#define PI 3.141592656
+#define PI2 6.283185307
+#define PI_2 1.570796327
+#define PI3_2 4.712388984
+
+static double LLVMpow(double d, int n) {
+ int i;
+ double res = d;
+ if (n == 0)
+ return 1;
+ for (i=1; i<n; i++)
+ res *= d;
+ return res;
+}
+
static double LLVMsin(double d) {
- dbl_ll_union u;
- u.d = sin(d);
- u.ll = (u.ll + 1) & ~1ULL;
- return u.d;
+ double sign = 1.0;
+
+ /* move into 2PI area */
+ while (d < 0)
+ d += PI2;
+ while (d > PI2)
+ d -= PI2;
+ /* move into PI/2 area */
+ if (d > PI3_2) {
+ d = PI2 - d;
+ sign = -1.0;
+ } else if (d > PI) {
+ d -= PI;
+ sign = -1.0;
+ } else if (d > PI_2) {
+ d = PI - d;
+ }
+ /* series terms */
+ double f3 = LLVMpow(d, 3)/FACT3;
+ double f5 = LLVMpow(d, 5)/FACT5;
+ d = sign * (d - f3 + f5);
+ /* saturate */
+ if (d > 1.0)
+ d = 1.0;
+ if (d < -1.0)
+ d = -1.0;
+ return d;
}
+
static double LLVMcos(double d) {
- dbl_ll_union u;
- u.d = cos(d);
- u.ll = (u.ll + 1) & ~1ULL;
- return u.d;
+ return LLVMsin(d + PI_2);
}
// LLVM LOCAL end
Modified: test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/Misc-C%2B%2B/Large/sphereflake.reference_output?rev=204133&r1=204132&r2=204133&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.reference_output (original)
+++ test-suite/trunk/SingleSource/Benchmarks/Misc-C++/Large/sphereflake.reference_output Tue Mar 18 05:01:37 2014
@@ -1 +1 @@
-064dd68da3963cf8d246e133a4f10486
+a0a1a950b3e237efde1acee62f1fe08b
More information about the llvm-commits
mailing list