Author: tkreuzer
Date: Thu Jan 28 00:42:34 2010
New Revision: 45290
URL:
http://svn.reactos.org/svn/reactos?rev=45290&view=rev
Log:
[CRT]
- implement generic C version of cos(). On amd64 machines it will compile into very
optimized SSE2 code. No need to use assembly.
Added:
branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/cos.c (with props)
Removed:
branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/amd64/cos.S
Modified:
branches/ros-amd64-bringup/reactos/lib/sdk/crt/crt.rbuild
branches/ros-amd64-bringup/reactos/lib/sdk/crt/libcntpr.rbuild
Modified: branches/ros-amd64-bringup/reactos/lib/sdk/crt/crt.rbuild
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/s…
==============================================================================
--- branches/ros-amd64-bringup/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] Thu Jan 28
00:42:34 2010
@@ -161,13 +161,13 @@
<file>jn_yn.c</file>-->
</if>
<if property="ARCH" value="amd64">
+ <file>cos.c</file>
<directory name="amd64">
<file>alldiv.S</file>
<file>atan.S</file>
<file>atan2.S</file>
<file>ceil.S</file>
<file>ceilf.S</file>
- <file>cos.S</file>
<file>exp.S</file>
<file>fabs.S</file>
<file>floor.S</file>
Modified: branches/ros-amd64-bringup/reactos/lib/sdk/crt/libcntpr.rbuild
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/s…
==============================================================================
--- branches/ros-amd64-bringup/reactos/lib/sdk/crt/libcntpr.rbuild [iso-8859-1]
(original)
+++ branches/ros-amd64-bringup/reactos/lib/sdk/crt/libcntpr.rbuild [iso-8859-1] Thu Jan 28
00:42:34 2010
@@ -64,7 +64,6 @@
<file>atan.S</file>
<file>atan2.S</file>
<file>ceil.S</file>
- <file>cos.S</file>
<file>exp.S</file>
<file>fabs.S</file>
<file>floor.S</file>
Removed: branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/amd64/cos.S
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/s…
==============================================================================
--- branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/amd64/cos.S [iso-8859-1]
(original)
+++ branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/amd64/cos.S (removed)
@@ -1,21 +1,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * PURPOSE: Implementation of cos
- * FILE: lib/sdk/crt/math/amd64/cos.S
- * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
- */
-
-/* INCLUDES ******************************************************************/
-
-#include <ndk/amd64/asm.h>
-#include <ndk/amd64/asmmacro.S>
-
-.intel_syntax noprefix
-
-
-.proc cos
- UNIMPLEMENTED cos
- ret
-
-.endproc
Added: branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/cos.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/s…
==============================================================================
--- branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/cos.c (added)
+++ branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/cos.c [iso-8859-1] Thu Jan 28
00:42:34 2010
@@ -1,0 +1,89 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS CRT
+ * FILE: lib/crt/math/cos.c
+ * PURPOSE: Generic C Implementation of cos
+ * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
+ */
+
+#define PRECISION 9
+#define M_PI 3.141592653589793238462643
+
+static double cos_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
+static double cos_sign_tbl[] = {1,-1,-1,1};
+
+double
+cos(double x)
+{
+ int quadrant;
+ double x2, result;
+
+ /* Calculate the quadrant */
+ quadrant = x * (2./M_PI);
+
+ /* Get offset inside quadrant */
+ x = x - quadrant * (M_PI/2.);
+
+ /* Normalize quadrant to [0..3] */
+ quadrant = quadrant & 0x3;
+
+ /* Fixup value for the generic function */
+ x += cos_off_tbl[quadrant];
+
+ /* Calculate the negative of the square of x */
+ x2 = - (x * x);
+
+ /* This is an unrolled taylor series using <PRECISION> iterations
+ * Example with 4 iterations:
+ * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
+ * To save multiplications and to keep the precision high, it's performed
+ * like this:
+ * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
+ */
+
+ /* Start with 0, compiler will optimize this away */
+ result = 0;
+
+#if (PRECISION >= 10)
+ result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*20);
+ result *= x2;
+#endif
+#if (PRECISION >= 9)
+ result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
+ result *= x2;
+#endif
+#if (PRECISION >= 8)
+ result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
+ result *= x2;
+#endif
+#if (PRECISION >= 7)
+ result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
+ result *= x2;
+#endif
+#if (PRECISION >= 6)
+ result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
+ result *= x2;
+#endif
+#if (PRECISION >= 5)
+ result += 1./(1.*2*3*4*5*6*7*8*9*10);
+ result *= x2;
+#endif
+ result += 1./(1.*2*3*4*5*6*7*8);
+ result *= x2;
+
+ result += 1./(1.*2*3*4*5*6);
+ result *= x2;
+
+ result += 1./(1.*2*3*4);
+ result *= x2;
+
+ result += 1./(1.*2);
+ result *= x2;
+
+ result += 1;
+
+ /* Apply correct sign */
+ result *= cos_sign_tbl[quadrant];
+
+ return result;
+}
Propchange: branches/ros-amd64-bringup/reactos/lib/sdk/crt/math/cos.c
------------------------------------------------------------------------------
svn:eol-style = native