* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\r
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)\r
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF \r
.globl __alldiv\r
.globl __aulldvrm\r
.globl __alldvrm\r
+.globl _atan\r
+.globl _ceil\r
+.globl _cos\r
+.globl _fabs\r
+.globl _floor\r
+.globl _log\r
+.globl _pow\r
+.globl _sin\r
+.globl _sqrt\r
+.globl _tan\r
+.globl __fltused\r
+\r
+/* DATA ********************************************************************/\r
+\r
+fzero:\r
+ .long 0 // Floating point zero\r
+ .long 0 // Floating point zero\r
+\r
+__fltused:\r
+ .long 0x9875\r
\r
/* FUNCTIONS ***************************************************************/\r
\r
/*\r
* long long\r
- * __alldiv(long long Dividend, long long Divisor);\r
+ * __alldiv(long long Dividend, long long Divisor)//\r
*\r
* Parameters:\r
* [ESP+04h] - long long Dividend\r
\r
/*\r
* long long\r
- * __allmul(long long Multiplier, long long Multiplicand);\r
+ * __allmul(long long Multiplier, long long Multiplicand)//\r
*\r
* Parameters:\r
* [ESP+04h] - long long Multiplier\r
\r
/*\r
* unsigned long long\r
- * __aullrem(unsigned long long Dividend, unsigned long long Divisor);\r
+ * __aullrem(unsigned long long Dividend, unsigned long long Divisor)//\r
*\r
* Parameters:\r
* [ESP+04h] - unsigned long long Dividend\r
\r
/*\r
* long long\r
- * __allshl(long long Value, unsigned char Shift);\r
+ * __allshl(long long Value, unsigned char Shift)//\r
*\r
* Parameters:\r
* EDX:EAX - signed long long value to be shifted left\r
\r
/*\r
* long long\r
- * __allshr(long long Value, unsigned char Shift);\r
+ * __allshr(long long Value, unsigned char Shift)//\r
*\r
* Parameters:\r
* EDX:EAX - signed long long value to be shifted right\r
\r
/*\r
* unsigned long long\r
- * __aulldiv(unsigned long long Dividend, unsigned long long Divisor);\r
+ * __aulldiv(unsigned long long Dividend, unsigned long long Divisor)//\r
*\r
* Parameters:\r
* [ESP+04h] - unsigned long long Dividend\r
\r
/*\r
* unsigned long long\r
- * __aullshr(unsigned long long Value, unsigned char Shift);\r
+ * __aullshr(unsigned long long Value, unsigned char Shift)//\r
*\r
* Parameters:\r
* EDX:EAX - unsigned long long value to be shifted right\r
\r
/*\r
* long long\r
- * __allrem(long long Dividend, long long Divisor);\r
+ * __allrem(long long Dividend, long long Divisor)//\r
*\r
* Parameters:\r
* [ESP+04h] - long long Dividend\r
\r
ret 16\r
\r
+_atan:\r
+ push ebp\r
+ mov ebp,esp\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fld1 // Load constant 1\r
+ fpatan // Take the arctangent\r
+ pop ebp\r
+ ret\r
+\r
+_ceil:\r
+ push ebp\r
+ mov ebp,esp\r
+ sub esp,4 // Allocate temporary space\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fstcw [ebp-2] // Save control word\r
+ fclex // Clear exceptions\r
+ mov word ptr [ebp-4],0xb63 // Rounding control word\r
+ fldcw [ebp-4] // Set new rounding control\r
+ frndint // Round to integer\r
+ fclex // Clear exceptions\r
+ fldcw [ebp-2] // Restore control word\r
+ mov esp,ebp // Deallocate temporary space\r
+ pop ebp\r
+ ret\r
+\r
+_cos:\r
+ push ebp\r
+ mov ebp,esp // Point to the stack frame\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fcos // Take the cosine\r
+ pop ebp\r
+ ret\r
+\r
+_fabs:\r
+ push ebp\r
+ mov ebp,esp\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fabs // Take the absolute value\r
+ pop ebp\r
+ ret\r
+\r
+_floor:\r
+ push ebp\r
+ mov ebp,esp\r
+ sub esp,4 // Allocate temporary space\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fstcw [ebp-2] // Save control word\r
+ fclex // Clear exceptions\r
+ mov word ptr [ebp-4],0x763 // Rounding control word\r
+ fldcw [ebp-4] // Set new rounding control\r
+ frndint // Round to integer\r
+ fclex // Clear exceptions\r
+ fldcw [ebp-2] // Restore control word\r
+ mov esp,ebp\r
+ pop ebp\r
+ ret\r
+\r
+_log:\r
+ push ebp\r
+ mov ebp,esp\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fldln2 // Load log base e of 2\r
+ fxch st(1) // Exchange st, st(1)\r
+ fyl2x // Compute the natural log(x)\r
+ pop ebp\r
+ ret\r
+\r
+_pow:\r
+ push ebp\r
+ mov ebp,esp\r
+ sub esp,12 // Allocate temporary space\r
+ push edi // Save register edi\r
+ push eax // Save register eax\r
+ mov dword ptr [ebp-12],0 // Set negation flag to zero\r
+ fld qword ptr [ebp+16] // Load real from stack\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ mov edi,offset flat:fzero // Point to real zero\r
+ fcom qword ptr [edi] // Compare x with zero\r
+ fstsw ax // Get the FPU status word\r
+ mov al,ah // Move condition flags to AL\r
+ lahf // Load Flags into AH\r
+ and al, 0b01000101 // Isolate C0, C2 and C3\r
+ and ah,not 0b01000101 // Turn off CF, PF and ZF\r
+ or ah,al // Set new CF, PF and ZF\r
+ sahf // Store AH into Flags\r
+ jb __fpow1 // Re-direct if x < 0\r
+ ja __fpow3 // Re-direct if x > 0\r
+ fxch // Swap st, st(1)\r
+ fcom qword ptr [edi] // Compare y with zero\r
+ fxch // Restore x as top of stack\r
+ fstsw ax // Get the FPU status word\r
+ mov al,ah // Move condition flags to AL\r
+ lahf // Load Flags into AH\r
+ and al, 0b01000101 // Isolate C0, C2 and C3\r
+ and ah,not 0b01000101 // Turn off CF, PF and ZF\r
+ or ah,al // Set new CF, PF and ZF\r
+ sahf // Store AH into Flags\r
+ ja __fpow3 // Re-direct if y > 0\r
+ fstp st(1) // Set new stack top and pop\r
+ mov eax,1 // Set domain error (EDOM)\r
+ jmp __fpow5 // End of case\r
+__fpow1: fxch // Put y on top of stack\r
+ fld st // Duplicate y as st(1)\r
+ frndint // Round to integer\r
+ fxch // Put y on top of stack\r
+ fcomp // y = int(y) ?\r
+ fstsw ax // Get the FPU status word\r
+ mov al,ah // Move condition flags to AL\r
+ lahf // Load Flags into AH\r
+ and al, 0b01000101 // Isolate C0, C2 and C3\r
+ and ah,not 0b01000101 // Turn off CF, PF and ZF\r
+ or ah,al // Set new CF, PF and ZF\r
+ sahf // Store AH into Flags\r
+ je __fpow2 // Proceed if y = int(y)\r
+ fstp st(1) // Set new stack top and pop\r
+ fldz // Set result to zero\r
+ fstp st(1) // Set new stack top and pop\r
+ mov eax,1 // Set domain error (EDOM)\r
+ jmp __fpow5 // End of case\r
+__fpow2: fist dword ptr [ebp-12] // Store y as integer\r
+ and dword ptr [ebp-12],1 // Set bit if y is odd\r
+ fxch // Put x on top of stack\r
+ fabs // x = |x|\r
+__fpow3: fldln2 // Load log base e of 2\r
+ fxch st(1) // Exchange st, st(1)\r
+ fyl2x // Compute the natural log(x)\r
+ fmulp // Compute y * ln(x)\r
+ fldl2e // Load log base 2(e)\r
+ fmulp st(1),st // Multiply x * log base 2(e)\r
+ fst st(1) // Push result\r
+ frndint // Round to integer\r
+ fsub st(1),st // Subtract\r
+ fxch // Exchange st, st(1)\r
+ f2xm1 // Compute 2 to the (x - 1)\r
+ fld1 // Load real number 1\r
+ faddp // 2 to the x\r
+ fscale // Scale by power of 2\r
+ fstp st(1) // Set new stack top and pop\r
+ test dword ptr [ebp-12],1 // Negation required ?\r
+ jz __fpow4 // No, re-direct\r
+ fchs // Negate the result\r
+__fpow4: fstp qword ptr [ebp-8] // Save (double)pow(x, y)\r
+ fld qword ptr [ebp-8] // Load (double)pow(x, y)\r
+ fxam // Examine st\r
+ fstsw ax // Get the FPU status word\r
+ cmp ah,5 // Infinity ?\r
+ jne __fpow6 // No, end of case\r
+ mov eax,2 // Set range error (ERANGE)\r
+ // Get errno pointer offset\r
+__fpow5: int 3\r
+ mov edi,0 // TODO: offset flat:__crt_errno\r
+ mov edi,[edi] // Get C errno variable pointer\r
+ mov dword ptr [edi],eax // Set errno\r
+__fpow6: pop eax // Restore register eax\r
+ pop edi // Restore register edi\r
+ mov esp,ebp // Deallocate temporary space\r
+ pop ebp\r
+ ret\r
+\r
+_sin:\r
+ push ebp // Save register bp\r
+ mov ebp,esp // Point to the stack frame\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fsin // Take the sine\r
+ pop ebp // Restore register bp\r
+ ret\r
+\r
+_sqrt:\r
+ push ebp\r
+ mov ebp,esp\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fsqrt // Take the square root\r
+ pop ebp\r
+ ret\r
+\r
+_tan:\r
+ push ebp\r
+ mov ebp,esp\r
+ sub esp,4 // Allocate temporary space\r
+ fld qword ptr [ebp+8] // Load real from stack\r
+ fptan // Take the tangent\r
+ fstp dword ptr [ebp-4] // Throw away the constant 1\r
+ mov esp,ebp // Deallocate temporary space\r
+ pop ebp\r
+ ret\r
+++ /dev/null
-/* COPYRIGHT: See COPYING in the top level directory
- * Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
- * PROJECT: ReactOS system libraries
- * FILE: lib/rtl/math.c
- * PURPOSE: Math functions for i387.
- * PROGRAMMER: John C. Bowman <bowman@ipp-garching.mpg.de>
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <rtl.h>
-
-#define NDEBUG
-#include <debug.h>
-
-/* FUNCTIONS *****************************************************************/
-
-double atan (double __x);
-double ceil (double __x);
-double cos (double __x);
-double fabs (double __x);
-double floor (double __x);
-double log (double __x);
-double __log2 (double __x);
-double pow (double __x, double __y);
-double sin (double __x);
-double sqrt (double __x);
-double tan (double __x);
-
-int _fltused = 0x9875;
-
-double atan (double __x)
-{
- register double __val;
- __asm __volatile__
- ("fld1\n\t"
- "fpatan"
- : "=t" (__val) : "0" (__x));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double ceil (double __x)
-{
- register double __val;
- __volatile unsigned short int __cw, __cwtmp;
-
- __asm __volatile ("fnstcw %0" : "=m" (__cw));
- __cwtmp = (__cw & 0xf3ff) | 0x0800; /* rounding up */
- __asm __volatile ("fldcw %0" : : "m" (__cwtmp));
- __asm __volatile ("frndint" : "=t" (__val) : "0" (__x));
- __asm __volatile ("fldcw %0" : : "m" (__cw));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double cos (double __x)
-{
- register double __val;
- __asm __volatile__
- ("fcos"
- : "=t" (__val): "0" (__x));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double fabs (double __x)
-{
- register double __val;
- __asm __volatile__
- ("fabs"
- : "=t" (__val) : "0" (__x));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double floor (double __x)
-{
- register double __val;
- __volatile unsigned short int __cw, __cwtmp;
-
- __asm __volatile ("fnstcw %0" : "=m" (__cw));
- __cwtmp = (__cw & 0xf3ff) | 0x0400; /* rounding down */
- __asm __volatile ("fldcw %0" : : "m" (__cwtmp));
- __asm __volatile ("frndint" : "=t" (__val) : "0" (__x));
- __asm __volatile ("fldcw %0" : : "m" (__cw));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double log (double __x)
-{
- register double __val;
- __asm __volatile__
- ("fldln2\n\t"
- "fxch\n\t"
- "fyl2x"
- : "=t" (__val) : "0" (__x));
-
- return __val;
-}
-
-double __log2 (double __x)
-{
- register double __val;
- __asm __volatile__
- ("fld1\n\t"
- "fxch\n\t"
- "fyl2x"
- : "=t" (__val) : "0" (__x));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double pow (double __x, double __y)
-{
- register double __val, __exponent;
- long __p = (long) __y;
-
- if (__x == 0.0 && __y > 0.0)
- return 0.0;
- if (__y == (double) __p)
- {
- double __r = 1.0;
- if (__p == 0)
- return 1.0;
- if (__p < 0)
- {
- __p = -__p;
- __x = 1.0 / __x;
- }
- while (1)
- {
- if (__p & 1)
- __r *= __x;
- __p >>= 1;
- if (__p == 0)
- return __r;
- __x *= __x;
- }
- /* NOTREACHED */
- }
- __asm __volatile__
- ("fmul %%st(1) # y * log2(x)\n\t"
- "fst %%st(1)\n\t"
- "frndint # int(y * log2(x))\n\t"
- "fxch\n\t"
- "fsub %%st(1) # fract(y * log2(x))\n\t"
- "f2xm1 # 2^(fract(y * log2(x))) - 1\n\t"
- : "=t" (__val), "=u" (__exponent) : "0" (__log2 (__x)), "1" (__y));
- __val += 1.0;
- __asm __volatile__
- ("fscale"
- : "=t" (__val) : "0" (__val), "u" (__exponent));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double sin (double __x)
-{
- register double __val;
- __asm __volatile__
- ("fsin"
- : "=t" (__val) : "0" (__x));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double sqrt (double __x)
-{
- register double __val;
- __asm __volatile__
- ("fsqrt"
- : "=t" (__val) : "0" (__x));
-
- return __val;
-}
-
-/*
- * @implemented
- */
-double tan (double __x)
-{
- register double __val;
- register double __val2 __attribute__ ((unused));
- __asm __volatile__
- ("fptan"
- : "=t" (__val2), "=u" (__val) : "0" (__x));
-
- return __val;
-}