mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 22:13:06 +00:00
Create a branch for audio work
svn path=/branches/audio-bringup/; revision=49478
This commit is contained in:
parent
26c20f3857
commit
5eb25b5c24
20759 changed files with 0 additions and 1141005 deletions
10
lib/sdk/crt/math/abs.c
Normal file
10
lib/sdk/crt/math/abs.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int
|
||||
abs(int j)
|
||||
{
|
||||
return j<0 ? -j : j;
|
||||
}
|
28
lib/sdk/crt/math/acos.c
Normal file
28
lib/sdk/crt/math/acos.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Math functions for i387.
|
||||
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
double acos(double __x)
|
||||
{
|
||||
return atan2(sqrt(1.0 - __x * __x), __x);
|
||||
}
|
7
lib/sdk/crt/math/adjust.c
Normal file
7
lib/sdk/crt/math/adjust.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
int _adjust_fdiv = 0;
|
||||
|
||||
/* EOF */
|
28
lib/sdk/crt/math/amd64/alldiv.S
Normal file
28
lib/sdk/crt/math/amd64/alldiv.S
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of alldiv
|
||||
* FILE: lib/sdk/crt/math/amd64/alldiv.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC _fltused
|
||||
_fltused:
|
||||
.long 0x9875
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
.proc alldiv
|
||||
UNIMPLEMENTED alldiv
|
||||
ret
|
||||
|
||||
.endp alldiv
|
21
lib/sdk/crt/math/amd64/atan.S
Normal file
21
lib/sdk/crt/math/amd64/atan.S
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of atan
|
||||
* FILE: lib/sdk/crt/math/amd64/atan.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC atan
|
||||
atan:
|
||||
UNIMPLEMENTED atan
|
||||
ret
|
21
lib/sdk/crt/math/amd64/atan2.S
Normal file
21
lib/sdk/crt/math/amd64/atan2.S
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of atan2
|
||||
* FILE: lib/sdk/crt/math/amd64/atan2.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC atan2
|
||||
atan2:
|
||||
UNIMPLEMENTED atan2
|
||||
ret
|
22
lib/sdk/crt/math/amd64/ceil.S
Normal file
22
lib/sdk/crt/math/amd64/ceil.S
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of ceil
|
||||
* FILE: lib/sdk/crt/math/amd64/ceil.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC ceil
|
||||
ceil:
|
||||
UNIMPLEMENTED ceil
|
||||
ret
|
||||
|
40
lib/sdk/crt/math/amd64/ceilf.S
Normal file
40
lib/sdk/crt/math/amd64/ceilf.S
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of tan
|
||||
* FILE: lib/sdk/crt/math/amd64/ceilf.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC ceilf
|
||||
ceilf:
|
||||
/* Put parameter on the stack */
|
||||
movss [rsp - 0x10], xmm0
|
||||
fld dword ptr [rsp]
|
||||
|
||||
/* Change fpu control word to round up */
|
||||
fstcw [rsp - 0x10]
|
||||
mov eax, [rsp - 0x10]
|
||||
or eax, 0x00800
|
||||
and eax, 0x0fbff
|
||||
mov [rsp - 0x08], eax
|
||||
fldcw [rsp - 0x08]
|
||||
|
||||
/* Round to integer */
|
||||
frndint
|
||||
|
||||
/* Restore fpu control word */
|
||||
fldcw [rsp - 0x10]
|
||||
|
||||
fstp dword ptr [rsp - 0x10]
|
||||
movss xmm0, [rsp - 0x10]
|
||||
ret
|
22
lib/sdk/crt/math/amd64/exp.S
Normal file
22
lib/sdk/crt/math/amd64/exp.S
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of exp
|
||||
* FILE: lib/sdk/crt/math/amd64/exp.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC exp
|
||||
exp:
|
||||
UNIMPLEMENTED exp
|
||||
ret
|
||||
|
22
lib/sdk/crt/math/amd64/fabs.S
Normal file
22
lib/sdk/crt/math/amd64/fabs.S
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of fabs
|
||||
* FILE: lib/sdk/crt/math/amd64/fabs.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC fabs
|
||||
fabs:
|
||||
UNIMPLEMENTED fabs
|
||||
ret
|
||||
|
21
lib/sdk/crt/math/amd64/floor.S
Normal file
21
lib/sdk/crt/math/amd64/floor.S
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of floor
|
||||
* FILE: lib/sdk/crt/math/amd64/floor.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC floor
|
||||
floor:
|
||||
UNIMPLEMENTED floor
|
||||
ret
|
40
lib/sdk/crt/math/amd64/floorf.S
Normal file
40
lib/sdk/crt/math/amd64/floorf.S
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of tan
|
||||
* FILE: lib/sdk/crt/math/amd64/floorf.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
.code64
|
||||
|
||||
PUBLIC floorf
|
||||
floorf:
|
||||
/* Put parameter on the stack */
|
||||
movss [rsp - 0x10], xmm0
|
||||
fld dword ptr [rsp]
|
||||
|
||||
/* Change fpu control word to round down */
|
||||
fstcw [rsp - 0x10]
|
||||
mov eax, [rsp - 0x10]
|
||||
or eax, 0x00400
|
||||
and eax, 0x0f7ff
|
||||
mov [rsp - 0x08], eax
|
||||
fldcw [rsp - 0x08]
|
||||
|
||||
/* Round to integer */
|
||||
frndint
|
||||
|
||||
/* Restore fpu control word */
|
||||
fldcw [rsp - 0x10]
|
||||
|
||||
fstp dword ptr [rsp - 0x10]
|
||||
movss xmm0, [rsp - 0x10]
|
||||
ret
|
19
lib/sdk/crt/math/amd64/fmod.S
Normal file
19
lib/sdk/crt/math/amd64/fmod.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of fmod
|
||||
* FILE: lib/sdk/crt/math/amd64/fmod.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC fmod
|
||||
fmod:
|
||||
UNIMPLEMENTED fmod
|
||||
ret
|
19
lib/sdk/crt/math/amd64/fmodf.S
Normal file
19
lib/sdk/crt/math/amd64/fmodf.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of fmodf
|
||||
* FILE: lib/sdk/crt/math/amd64/fmodf.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC fmodf
|
||||
fmodf:
|
||||
UNIMPLEMENTED fmodf
|
||||
ret
|
19
lib/sdk/crt/math/amd64/ldexp.S
Normal file
19
lib/sdk/crt/math/amd64/ldexp.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of ldexp
|
||||
* FILE: lib/sdk/crt/math/amd64/ldexp.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC ldexp
|
||||
ldexp:
|
||||
UNIMPLEMENTED ldexp
|
||||
ret
|
19
lib/sdk/crt/math/amd64/log.S
Normal file
19
lib/sdk/crt/math/amd64/log.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of log
|
||||
* FILE: lib/sdk/crt/math/amd64/log.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC log
|
||||
log:
|
||||
UNIMPLEMENTED log
|
||||
ret
|
20
lib/sdk/crt/math/amd64/log10.S
Normal file
20
lib/sdk/crt/math/amd64/log10.S
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of log10
|
||||
* FILE: lib/sdk/crt/math/amd64/log10.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC log10
|
||||
log10:
|
||||
UNIMPLEMENTED log10
|
||||
ret
|
||||
|
20
lib/sdk/crt/math/amd64/pow.S
Normal file
20
lib/sdk/crt/math/amd64/pow.S
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of pow
|
||||
* FILE: lib/sdk/crt/math/amd64/pow.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC pow
|
||||
pow:
|
||||
UNIMPLEMENTED pow
|
||||
ret
|
||||
|
19
lib/sdk/crt/math/amd64/sqrt.S
Normal file
19
lib/sdk/crt/math/amd64/sqrt.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of sqrt
|
||||
* FILE: lib/sdk/crt/math/amd64/sqrt.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC sqrt
|
||||
sqrt:
|
||||
UNIMPLEMENTED sqrt
|
||||
ret
|
19
lib/sdk/crt/math/amd64/sqrtf.S
Normal file
19
lib/sdk/crt/math/amd64/sqrtf.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of tan
|
||||
* FILE: lib/sdk/crt/math/amd64/sqrtf.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC sqrtf
|
||||
sqrtf:
|
||||
sqrtss xmm0, xmm0
|
||||
ret
|
19
lib/sdk/crt/math/amd64/tan.S
Normal file
19
lib/sdk/crt/math/amd64/tan.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: Implementation of tan
|
||||
* FILE: lib/sdk/crt/math/amd64/tan.S
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <reactos/asm.h>
|
||||
#include <ndk/amd64/asm.h>
|
||||
|
||||
/* DATA *********************************************************************/
|
||||
|
||||
PUBLIC tan
|
||||
tan:
|
||||
UNIMPLEMENTED tan
|
||||
ret
|
28
lib/sdk/crt/math/asin.c
Normal file
28
lib/sdk/crt/math/asin.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Math functions for i387.
|
||||
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
double asin(double __x)
|
||||
{
|
||||
return atan2(__x, sqrt(1.0 - __x * __x));
|
||||
}
|
14
lib/sdk/crt/math/cabs.c
Normal file
14
lib/sdk/crt/math/cabs.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <math.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double _cabs( struct _complex z )
|
||||
{
|
||||
return sqrt( z.x*z.x + z.y*z.y );
|
||||
// return hypot(z.x,z.y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
89
lib/sdk/crt/math/cos.c
Normal file
89
lib/sdk/crt/math/cos.c
Normal file
|
@ -0,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@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*19*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;
|
||||
}
|
11
lib/sdk/crt/math/cosf.c
Normal file
11
lib/sdk/crt/math/cosf.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
float cosf(float _X)
|
||||
{
|
||||
return ((float)cos((double)_X));
|
||||
}
|
12
lib/sdk/crt/math/cosh.c
Normal file
12
lib/sdk/crt/math/cosh.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double cosh(double x)
|
||||
{
|
||||
const double ebig = exp(fabs(x));
|
||||
return (ebig + 1.0/ebig) / 2.0;
|
||||
}
|
27
lib/sdk/crt/math/div.c
Normal file
27
lib/sdk/crt/math/div.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <precomp.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
div_t
|
||||
div(int num, int denom)
|
||||
{
|
||||
div_t r;
|
||||
|
||||
if (num > 0 && denom < 0) {
|
||||
num = -num;
|
||||
denom = -denom;
|
||||
}
|
||||
r.quot = num / denom;
|
||||
r.rem = num % denom;
|
||||
if (num < 0 && denom > 0)
|
||||
{
|
||||
if (r.rem > 0)
|
||||
{
|
||||
r.quot++;
|
||||
r.rem -= denom;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
89
lib/sdk/crt/math/fdivbug.c
Normal file
89
lib/sdk/crt/math/fdivbug.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include <precomp.h>
|
||||
#include <math.h>
|
||||
|
||||
/* The following functions are likely workarounds for the pentium fdiv bug */
|
||||
void __stdcall _adj_fdiv_m32( unsigned int arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m32 stub\n");
|
||||
}
|
||||
void __stdcall _adj_fdiv_m32i( int arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m32i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m64 stub\n");
|
||||
}
|
||||
|
||||
void _adj_fdiv_r(void)
|
||||
{
|
||||
FIXME("_adj_fdiv_r stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m32( unsigned int arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m32i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m32i( int arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m32i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m64 stub\n");
|
||||
}
|
||||
|
||||
void _adj_fpatan(void)
|
||||
{
|
||||
FIXME("_adj_fpatan stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdiv_m16i( short arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m16i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m16i( short arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m16i stub\n");
|
||||
}
|
||||
|
||||
void _adj_fprem(void)
|
||||
{
|
||||
FIXME("_adj_fprem stub\n");
|
||||
}
|
||||
|
||||
void _adj_fprem1(void)
|
||||
{
|
||||
FIXME("_adj_fprem1 stub\n");
|
||||
}
|
||||
|
||||
void _adj_fptan(void)
|
||||
{
|
||||
FIXME("_adj_fptan stub\n");
|
||||
}
|
||||
|
||||
void _safe_fdiv(void)
|
||||
{
|
||||
FIXME("_safe_fdiv stub\n");
|
||||
}
|
||||
|
||||
void _safe_fdivr(void)
|
||||
{
|
||||
FIXME("_safe_fdivr stub\n");
|
||||
}
|
||||
|
||||
void _safe_fprem(void)
|
||||
{
|
||||
FIXME("_safe_fprem stub\n");
|
||||
}
|
||||
|
||||
void _safe_fprem1(void)
|
||||
{
|
||||
FIXME("_safe_fprem1 stub\n");
|
||||
}
|
||||
|
||||
|
29
lib/sdk/crt/math/frexp.c
Normal file
29
lib/sdk/crt/math/frexp.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <internal/ieee.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double
|
||||
frexp(double __x, int *exptr)
|
||||
{
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_s* x;
|
||||
} x;
|
||||
|
||||
x.__x = &__x;
|
||||
|
||||
if ( exptr != NULL )
|
||||
*exptr = x.x->exponent - 0x3FE;
|
||||
|
||||
|
||||
x.x->exponent = 0x3FE;
|
||||
|
||||
return __x;
|
||||
}
|
||||
|
||||
|
||||
|
6
lib/sdk/crt/math/huge_val.c
Normal file
6
lib/sdk/crt/math/huge_val.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
#include <internal/ieee.h>
|
||||
|
||||
#undef _HUGE
|
||||
double_s _HUGE = { 0x00000, 0x00000, 0x7ff, 0x0 };
|
98
lib/sdk/crt/math/hypot.c
Normal file
98
lib/sdk/crt/math/hypot.c
Normal file
|
@ -0,0 +1,98 @@
|
|||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
/*
|
||||
* hypot() function for DJGPP.
|
||||
*
|
||||
* hypot() computes sqrt(x^2 + y^2). The problem with the obvious
|
||||
* naive implementation is that it might fail for very large or
|
||||
* very small arguments. For instance, for large x or y the result
|
||||
* might overflow even if the value of the function should not,
|
||||
* because squaring a large number might trigger an overflow. For
|
||||
* very small numbers, their square might underflow and will be
|
||||
* silently replaced by zero; this won't cause an exception, but might
|
||||
* have an adverse effect on the accuracy of the result.
|
||||
*
|
||||
* This implementation tries to avoid the above pitfals, without
|
||||
* inflicting too much of a performance hit.
|
||||
*
|
||||
*/
|
||||
#include <precomp.h>
|
||||
|
||||
/* Approximate square roots of DBL_MAX and DBL_MIN. Numbers
|
||||
between these two shouldn't neither overflow nor underflow
|
||||
when squared. */
|
||||
#define __SQRT_DBL_MAX 1.3e+154
|
||||
#define __SQRT_DBL_MIN 2.3e-162
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double
|
||||
_hypot(double x, double y)
|
||||
{
|
||||
double abig = fabs(x), asmall = fabs(y);
|
||||
double ratio;
|
||||
|
||||
/* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */
|
||||
if (abig < asmall)
|
||||
{
|
||||
double temp = abig;
|
||||
|
||||
abig = asmall;
|
||||
asmall = temp;
|
||||
}
|
||||
|
||||
/* Trivial case. */
|
||||
if (asmall == 0.)
|
||||
return abig;
|
||||
|
||||
/* Scale the numbers as much as possible by using its ratio.
|
||||
For example, if both ABIG and ASMALL are VERY small, then
|
||||
X^2 + Y^2 might be VERY inaccurate due to loss of
|
||||
significant digits. Dividing ASMALL by ABIG scales them
|
||||
to a certain degree, so that accuracy is better. */
|
||||
|
||||
if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX)
|
||||
return abig * sqrt(1.0 + ratio*ratio);
|
||||
else
|
||||
{
|
||||
/* Slower but safer algorithm due to Moler and Morrison. Never
|
||||
produces any intermediate result greater than roughly the
|
||||
larger of X and Y. Should converge to machine-precision
|
||||
accuracy in 3 iterations. */
|
||||
|
||||
double r = ratio*ratio, t, s, p = abig, q = asmall;
|
||||
|
||||
do {
|
||||
t = 4. + r;
|
||||
if (t == 4.)
|
||||
break;
|
||||
s = r / t;
|
||||
p += 2. * s * p;
|
||||
q *= s;
|
||||
r = (q / p) * (q / p);
|
||||
} while (1);
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <msvcrt/stdio.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("hypot(3, 4) =\t\t\t %25.17e\n", _hypot(3., 4.));
|
||||
printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", _hypot(3.e+150, 4.e+150));
|
||||
printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", _hypot(3.e+306, 4.e+306));
|
||||
printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n",_hypot(3.e-320, 4.e-320));
|
||||
printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n",_hypot(0.7*DBL_MAX, 0.7*DBL_MAX));
|
||||
printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", _hypot(DBL_MAX, 1.0));
|
||||
printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", _hypot(1.0, DBL_MAX));
|
||||
printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", _hypot(0.0, DBL_MAX));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
224
lib/sdk/crt/math/i386/alldiv_asm.s
Normal file
224
lib/sdk/crt/math/i386/alldiv_asm.s
Normal file
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/alldiv_asm.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __alldiv
|
||||
.globl __fltused
|
||||
|
||||
/* DATA ********************************************************************/
|
||||
|
||||
__fltused:
|
||||
.long 0x9875
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// lldiv - signed long divide
|
||||
//
|
||||
// Purpose:
|
||||
// Does a signed long divide of the arguments. Arguments are
|
||||
// not changed.
|
||||
//
|
||||
// Entry:
|
||||
// Arguments are passed on the stack:
|
||||
// 1st pushed: divisor (QWORD)
|
||||
// 2nd pushed: dividend (QWORD)
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX contains the quotient (dividend/divisor)
|
||||
// NOTE: this routine removes the parameters from the stack.
|
||||
//
|
||||
// Uses:
|
||||
// ECX
|
||||
//
|
||||
|
||||
__alldiv:
|
||||
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
|
||||
// Set up the local stack and save the index registers. When this is done
|
||||
// the stack frame will look as follows (assuming that the expression a/b will
|
||||
// generate a call to lldiv(a, b)):
|
||||
//
|
||||
// -----------------
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--divisor (b)--|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--dividend (a)-|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | return addr** |
|
||||
// |---------------|
|
||||
// | EDI |
|
||||
// |---------------|
|
||||
// | ESI |
|
||||
// |---------------|
|
||||
// ESP---->| EBX |
|
||||
// -----------------
|
||||
//
|
||||
|
||||
#define DVNDLO [esp + 16] // stack address of dividend (a)
|
||||
#define DVNDHI [esp + 20] // stack address of dividend (a)
|
||||
#define DVSRLO [esp + 24] // stack address of divisor (b)
|
||||
#define DVSRHI [esp + 28] // stack address of divisor (b)
|
||||
|
||||
// Determine sign of the result (edi = 0 if result is positive, non-zero
|
||||
// otherwise) and make operands positive.
|
||||
|
||||
xor edi,edi // result sign assumed positive
|
||||
|
||||
mov eax,DVNDHI // hi word of a
|
||||
or eax,eax // test to see if signed
|
||||
jge short L1 // skip rest if a is already positive
|
||||
inc edi // complement result sign flag
|
||||
mov edx,DVNDLO // lo word of a
|
||||
neg eax // make a positive
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov DVNDHI,eax // save positive value
|
||||
mov DVNDLO,edx
|
||||
L1:
|
||||
mov eax,DVSRHI // hi word of b
|
||||
or eax,eax // test to see if signed
|
||||
jge short L2 // skip rest if b is already positive
|
||||
inc edi // complement the result sign flag
|
||||
mov edx,DVSRLO // lo word of a
|
||||
neg eax // make b positive
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov DVSRHI,eax // save positive value
|
||||
mov DVSRLO,edx
|
||||
L2:
|
||||
|
||||
//
|
||||
// Now do the divide. First look to see if the divisor is less than 4194304K.
|
||||
// If so, then we can use a simple algorithm with word divides, otherwise
|
||||
// things get a little more complex.
|
||||
//
|
||||
// NOTE - eax currently contains the high order word of DVSR
|
||||
//
|
||||
|
||||
or eax,eax // check to see if divisor < 4194304K
|
||||
jnz short L3 // nope, gotta do this the hard way
|
||||
mov ecx,DVSRLO // load divisor
|
||||
mov eax,DVNDHI // load high word of dividend
|
||||
xor edx,edx
|
||||
div ecx // eax <- high order bits of quotient
|
||||
mov ebx,eax // save high bits of quotient
|
||||
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
|
||||
div ecx // eax <- low order bits of quotient
|
||||
mov edx,ebx // edx:eax <- quotient
|
||||
jmp short L4 // set sign, restore stack and return
|
||||
|
||||
//
|
||||
// Here we do it the hard way. Remember, eax contains the high word of DVSR
|
||||
//
|
||||
|
||||
L3:
|
||||
mov ebx,eax // ebx:ecx <- divisor
|
||||
mov ecx,DVSRLO
|
||||
mov edx,DVNDHI // edx:eax <- dividend
|
||||
mov eax,DVNDLO
|
||||
L5:
|
||||
shr ebx,1 // shift divisor right one bit
|
||||
rcr ecx,1
|
||||
shr edx,1 // shift dividend right one bit
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jnz short L5 // loop until divisor < 4194304K
|
||||
div ecx // now divide, ignore remainder
|
||||
mov esi,eax // save quotient
|
||||
|
||||
//
|
||||
// We may be off by one, so to check, we will multiply the quotient
|
||||
// by the divisor and check the result against the orignal dividend
|
||||
// Note that we must also check for overflow, which can occur if the
|
||||
// dividend is close to 2**64 and the quotient is off by 1.
|
||||
//
|
||||
|
||||
mul dword ptr DVSRHI // QUOT * DVSRHI
|
||||
mov ecx,eax
|
||||
mov eax,DVSRLO
|
||||
mul esi // QUOT * DVSRLO
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jc short L6 // carry means Quotient is off by 1
|
||||
|
||||
//
|
||||
// do long compare here between original dividend and the result of the
|
||||
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
|
||||
// subtract one (1) from the quotient.
|
||||
//
|
||||
|
||||
cmp edx,DVNDHI // compare hi words of result and original
|
||||
ja short L6 // if result > original, do subtract
|
||||
jb short L7 // if result < original, we are ok
|
||||
cmp eax,DVNDLO // hi words are equal, compare lo words
|
||||
jbe short L7 // if less or equal we are ok, else subtract
|
||||
L6:
|
||||
dec esi // subtract 1 from quotient
|
||||
L7:
|
||||
xor edx,edx // edx:eax <- quotient
|
||||
mov eax,esi
|
||||
|
||||
//
|
||||
// Just the cleanup left to do. edx:eax contains the quotient. Set the sign
|
||||
// according to the save value, cleanup the stack, and return.
|
||||
//
|
||||
|
||||
L4:
|
||||
dec edi // check to see if result is negative
|
||||
jnz short L8 // if EDI == 0, result should be negative
|
||||
neg edx // otherwise, negate the result
|
||||
neg eax
|
||||
sbb edx,0
|
||||
|
||||
//
|
||||
// Restore the saved registers and return.
|
||||
//
|
||||
|
||||
L8:
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
|
||||
ret 16
|
246
lib/sdk/crt/math/i386/alldvrm_asm.s
Normal file
246
lib/sdk/crt/math/i386/alldvrm_asm.s
Normal file
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/alldvrm.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __alldvrm
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
__alldvrm:
|
||||
push edi
|
||||
push esi
|
||||
push ebp
|
||||
|
||||
// Set up the local stack and save the index registers. When this is done
|
||||
// the stack frame will look as follows (assuming that the expression a/b will
|
||||
// generate a call to alldvrm(a, b)):
|
||||
//
|
||||
// -----------------
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--divisor (b)--|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--dividend (a)-|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | return addr** |
|
||||
// |---------------|
|
||||
// | EDI |
|
||||
// |---------------|
|
||||
// | ESI |
|
||||
// |---------------|
|
||||
// ESP---->| EBP |
|
||||
// -----------------
|
||||
//
|
||||
|
||||
#undef DVNDLO
|
||||
#undef DVNDHI
|
||||
#undef DVSRLO
|
||||
#undef DVSRHI
|
||||
#define DVNDLO [esp + 16] // stack address of dividend (a)
|
||||
#define DVNDHI [esp + 20] // stack address of dividend (a)
|
||||
#define DVSRLO [esp + 24] // stack address of divisor (b)
|
||||
#define DVSRHI [esp + 28] // stack address of divisor (b)
|
||||
|
||||
// Determine sign of the quotient (edi = 0 if result is positive, non-zero
|
||||
// otherwise) and make operands positive.
|
||||
// Sign of the remainder is kept in ebp.
|
||||
|
||||
xor edi,edi // result sign assumed positive
|
||||
xor ebp,ebp // result sign assumed positive
|
||||
|
||||
mov eax,DVNDHI // hi word of a
|
||||
or eax,eax // test to see if signed
|
||||
jge short ....L1 // skip rest if a is already positive
|
||||
inc edi // complement result sign flag
|
||||
inc ebp // complement result sign flag
|
||||
mov edx,DVNDLO // lo word of a
|
||||
neg eax // make a positive
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov DVNDHI,eax // save positive value
|
||||
mov DVNDLO,edx
|
||||
....L1:
|
||||
mov eax,DVSRHI // hi word of b
|
||||
or eax,eax // test to see if signed
|
||||
jge short ....L2 // skip rest if b is already positive
|
||||
inc edi // complement the result sign flag
|
||||
mov edx,DVSRLO // lo word of a
|
||||
neg eax // make b positive
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov DVSRHI,eax // save positive value
|
||||
mov DVSRLO,edx
|
||||
....L2:
|
||||
|
||||
//
|
||||
// Now do the divide. First look to see if the divisor is less than 4194304K.
|
||||
// If so, then we can use a simple algorithm with word divides, otherwise
|
||||
// things get a little more complex.
|
||||
//
|
||||
// NOTE - eax currently contains the high order word of DVSR
|
||||
//
|
||||
|
||||
or eax,eax // check to see if divisor < 4194304K
|
||||
jnz short ....L3 // nope, gotta do this the hard way
|
||||
mov ecx,DVSRLO // load divisor
|
||||
mov eax,DVNDHI // load high word of dividend
|
||||
xor edx,edx
|
||||
div ecx // eax <- high order bits of quotient
|
||||
mov ebx,eax // save high bits of quotient
|
||||
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
|
||||
div ecx // eax <- low order bits of quotient
|
||||
mov esi,eax // ebx:esi <- quotient
|
||||
//
|
||||
// Now we need to do a multiply so that we can compute the remainder.
|
||||
//
|
||||
mov eax,ebx // set up high word of quotient
|
||||
mul dword ptr DVSRLO // HIWORD(QUOT) * DVSR
|
||||
mov ecx,eax // save the result in ecx
|
||||
mov eax,esi // set up low word of quotient
|
||||
mul dword ptr DVSRLO // LOWORD(QUOT) * DVSR
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jmp short ....L4 // complete remainder calculation
|
||||
|
||||
//
|
||||
// Here we do it the hard way. Remember, eax contains the high word of DVSR
|
||||
//
|
||||
|
||||
....L3:
|
||||
mov ebx,eax // ebx:ecx <- divisor
|
||||
mov ecx,DVSRLO
|
||||
mov edx,DVNDHI // edx:eax <- dividend
|
||||
mov eax,DVNDLO
|
||||
....L5:
|
||||
shr ebx,1 // shift divisor right one bit
|
||||
rcr ecx,1
|
||||
shr edx,1 // shift dividend right one bit
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jnz short ....L5 // loop until divisor < 4194304K
|
||||
div ecx // now divide, ignore remainder
|
||||
mov esi,eax // save quotient
|
||||
|
||||
//
|
||||
// We may be off by one, so to check, we will multiply the quotient
|
||||
// by the divisor and check the result against the orignal dividend
|
||||
// Note that we must also check for overflow, which can occur if the
|
||||
// dividend is close to 2**64 and the quotient is off by 1.
|
||||
//
|
||||
|
||||
mul dword ptr DVSRHI // QUOT * DVSRHI
|
||||
mov ecx,eax
|
||||
mov eax,DVSRLO
|
||||
mul esi // QUOT * DVSRLO
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jc short ....L6 // carry means Quotient is off by 1
|
||||
|
||||
//
|
||||
// do long compare here between original dividend and the result of the
|
||||
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
|
||||
// subtract one (1) from the quotient.
|
||||
//
|
||||
|
||||
cmp edx,DVNDHI // compare hi words of result and original
|
||||
ja short ....L6 // if result > original, do subtract
|
||||
jb short ....L7 // if result < original, we are ok
|
||||
cmp eax,DVNDLO // hi words are equal, compare lo words
|
||||
jbe short ....L7 // if less or equal we are ok, else subtract
|
||||
....L6:
|
||||
dec esi // subtract 1 from quotient
|
||||
sub eax,DVSRLO // subtract divisor from result
|
||||
sbb edx,DVSRHI
|
||||
....L7:
|
||||
xor ebx,ebx // ebx:esi <- quotient
|
||||
|
||||
....L4:
|
||||
//
|
||||
// Calculate remainder by subtracting the result from the original dividend.
|
||||
// Since the result is already in a register, we will do the subtract in the
|
||||
// opposite direction and negate the result if necessary.
|
||||
//
|
||||
|
||||
sub eax,DVNDLO // subtract dividend from result
|
||||
sbb edx,DVNDHI
|
||||
|
||||
//
|
||||
// Now check the result sign flag to see if the result is supposed to be positive
|
||||
// or negative. It is currently negated (because we subtracted in the 'wrong'
|
||||
// direction), so if the sign flag is set we are done, otherwise we must negate
|
||||
// the result to make it positive again.
|
||||
//
|
||||
|
||||
dec ebp // check result sign flag
|
||||
jns short ....L9 // result is ok, set up the quotient
|
||||
neg edx // otherwise, negate the result
|
||||
neg eax
|
||||
sbb edx,0
|
||||
|
||||
//
|
||||
// Now we need to get the quotient into edx:eax and the remainder into ebx:ecx.
|
||||
//
|
||||
....L9:
|
||||
mov ecx,edx
|
||||
mov edx,ebx
|
||||
mov ebx,ecx
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
|
||||
//
|
||||
// Just the cleanup left to do. edx:eax contains the quotient. Set the sign
|
||||
// according to the save value, cleanup the stack, and return.
|
||||
//
|
||||
|
||||
dec edi // check to see if result is negative
|
||||
jnz short ....L8 // if EDI == 0, result should be negative
|
||||
neg edx // otherwise, negate the result
|
||||
neg eax
|
||||
sbb edx,0
|
||||
|
||||
//
|
||||
// Restore the saved registers and return.
|
||||
//
|
||||
|
||||
....L8:
|
||||
pop ebp
|
||||
pop esi
|
||||
pop edi
|
||||
|
||||
ret 16
|
115
lib/sdk/crt/math/i386/allmul_asm.s
Normal file
115
lib/sdk/crt/math/i386/allmul_asm.s
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/allmul.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __allmul
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// llmul - long multiply routine
|
||||
//
|
||||
// Purpose:
|
||||
// Does a long multiply (same for signed/unsigned)
|
||||
// Parameters are not changed.
|
||||
//
|
||||
// Entry:
|
||||
// Parameters are passed on the stack:
|
||||
// 1st pushed: multiplier (QWORD)
|
||||
// 2nd pushed: multiplicand (QWORD)
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX - product of multiplier and multiplicand
|
||||
// NOTE: parameters are removed from the stack
|
||||
//
|
||||
// Uses:
|
||||
// ECX
|
||||
//
|
||||
|
||||
__allmul:
|
||||
|
||||
#define ALO [esp + 4] // stack address of a
|
||||
#define AHI [esp + 8] // stack address of a
|
||||
#define BLO [esp + 12] // stack address of b
|
||||
#define BHI [esp + 16] // stack address of b
|
||||
|
||||
//
|
||||
// AHI, BHI : upper 32 bits of A and B
|
||||
// ALO, BLO : lower 32 bits of A and B
|
||||
//
|
||||
// ALO * BLO
|
||||
// ALO * BHI
|
||||
// + BLO * AHI
|
||||
// ---------------------
|
||||
//
|
||||
|
||||
mov eax,AHI
|
||||
mov ecx,BHI
|
||||
or ecx,eax //test for both hiwords zero.
|
||||
mov ecx,BLO
|
||||
jnz short hard //both are zero, just mult ALO and BLO
|
||||
|
||||
mov eax,ALO
|
||||
mul ecx
|
||||
|
||||
ret 16 // callee restores the stack
|
||||
|
||||
hard:
|
||||
push ebx
|
||||
|
||||
// must redefine A and B since esp has been altered
|
||||
|
||||
#define A2LO [esp + 8] // stack address of a
|
||||
#define A2HI [esp + 12] // stack address of a
|
||||
#define B2LO [esp + 16] // stack address of b
|
||||
#define B2HI [esp + 20] // stack address of b
|
||||
|
||||
mul ecx //eax has AHI, ecx has BLO, so AHI * BLO
|
||||
mov ebx,eax //save result
|
||||
|
||||
mov eax,A2LO
|
||||
mul dword ptr B2HI //ALO * BHI
|
||||
add ebx,eax //ebx = ((ALO * BHI) + (AHI * BLO))
|
||||
|
||||
mov eax,A2LO //ecx = BLO
|
||||
mul ecx //so edx:eax = ALO*BLO
|
||||
add edx,ebx //now edx has all the LO*HI stuff
|
||||
|
||||
pop ebx
|
||||
|
||||
ret 16 // callee restores the stack
|
||||
|
229
lib/sdk/crt/math/i386/allrem_asm.s
Normal file
229
lib/sdk/crt/math/i386/allrem_asm.s
Normal file
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/allrem.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __allrem
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// llrem - signed long remainder
|
||||
//
|
||||
// Purpose:
|
||||
// Does a signed long remainder of the arguments. Arguments are
|
||||
// not changed.
|
||||
//
|
||||
// Entry:
|
||||
// Arguments are passed on the stack:
|
||||
// 1st pushed: divisor (QWORD)
|
||||
// 2nd pushed: dividend (QWORD)
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX contains the remainder (dividend%divisor)
|
||||
// NOTE: this routine removes the parameters from the stack.
|
||||
//
|
||||
// Uses:
|
||||
// ECX
|
||||
//
|
||||
|
||||
__allrem :
|
||||
|
||||
push ebx
|
||||
push edi
|
||||
|
||||
// Set up the local stack and save the index registers. When this is done
|
||||
// the stack frame will look as follows (assuming that the expression a%b will
|
||||
// generate a call to lrem(a, b)):
|
||||
//
|
||||
// -----------------
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--divisor (b)--|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--dividend (a)-|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | return addr** |
|
||||
// |---------------|
|
||||
// | EBX |
|
||||
// |---------------|
|
||||
// ESP---->| EDI |
|
||||
// -----------------
|
||||
//
|
||||
|
||||
#undef DVNDLO
|
||||
#undef DVNDHI
|
||||
#undef DVSRLO
|
||||
#undef DVSRHI
|
||||
#define DVNDLO [esp + 12] // stack address of dividend (a)
|
||||
#define DVNDHI [esp + 16] // stack address of dividend (a)
|
||||
#define DVSRLO [esp + 20] // stack address of divisor (b)
|
||||
#define DVSRHI [esp + 24] // stack address of divisor (b)
|
||||
|
||||
// Determine sign of the result (edi = 0 if result is positive, non-zero
|
||||
// otherwise) and make operands positive.
|
||||
|
||||
xor edi,edi // result sign assumed positive
|
||||
|
||||
mov eax,DVNDHI // hi word of a
|
||||
or eax,eax // test to see if signed
|
||||
jge short .L1 // skip rest if a is already positive
|
||||
inc edi // complement result sign flag bit
|
||||
mov edx,DVNDLO // lo word of a
|
||||
neg eax // make a positive
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov DVNDHI,eax // save positive value
|
||||
mov DVNDLO,edx
|
||||
.L1:
|
||||
mov eax,DVSRHI // hi word of b
|
||||
or eax,eax // test to see if signed
|
||||
jge short .L2 // skip rest if b is already positive
|
||||
mov edx,DVSRLO // lo word of b
|
||||
neg eax // make b positive
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov DVSRHI,eax // save positive value
|
||||
mov DVSRLO,edx
|
||||
.L2:
|
||||
|
||||
//
|
||||
// Now do the divide. First look to see if the divisor is less than 4194304K.
|
||||
// If so, then we can use a simple algorithm with word divides, otherwise
|
||||
// things get a little more complex.
|
||||
//
|
||||
// NOTE - eax currently contains the high order word of DVSR
|
||||
//
|
||||
|
||||
or eax,eax // check to see if divisor < 4194304K
|
||||
jnz short .L3 // nope, gotta do this the hard way
|
||||
mov ecx,DVSRLO // load divisor
|
||||
mov eax,DVNDHI // load high word of dividend
|
||||
xor edx,edx
|
||||
div ecx // edx <- remainder
|
||||
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
|
||||
div ecx // edx <- final remainder
|
||||
mov eax,edx // edx:eax <- remainder
|
||||
xor edx,edx
|
||||
dec edi // check result sign flag
|
||||
jns short .L4 // negate result, restore stack and return
|
||||
jmp short .L8 // result sign ok, restore stack and return
|
||||
|
||||
//
|
||||
// Here we do it the hard way. Remember, eax contains the high word of DVSR
|
||||
//
|
||||
|
||||
.L3:
|
||||
mov ebx,eax // ebx:ecx <- divisor
|
||||
mov ecx,DVSRLO
|
||||
mov edx,DVNDHI // edx:eax <- dividend
|
||||
mov eax,DVNDLO
|
||||
.L5:
|
||||
shr ebx,1 // shift divisor right one bit
|
||||
rcr ecx,1
|
||||
shr edx,1 // shift dividend right one bit
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jnz short .L5 // loop until divisor < 4194304K
|
||||
div ecx // now divide, ignore remainder
|
||||
|
||||
//
|
||||
// We may be off by one, so to check, we will multiply the quotient
|
||||
// by the divisor and check the result against the orignal dividend
|
||||
// Note that we must also check for overflow, which can occur if the
|
||||
// dividend is close to 2**64 and the quotient is off by 1.
|
||||
//
|
||||
|
||||
mov ecx,eax // save a copy of quotient in ECX
|
||||
mul dword ptr DVSRHI
|
||||
xchg ecx,eax // save product, get quotient in EAX
|
||||
mul dword ptr DVSRLO
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jc short .L6 // carry means Quotient is off by 1
|
||||
|
||||
//
|
||||
// do long compare here between original dividend and the result of the
|
||||
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
|
||||
// subtract the original divisor from the result.
|
||||
//
|
||||
|
||||
cmp edx,DVNDHI // compare hi words of result and original
|
||||
ja short .L6 // if result > original, do subtract
|
||||
jb short .L7 // if result < original, we are ok
|
||||
cmp eax,DVNDLO // hi words are equal, compare lo words
|
||||
jbe short .L7 // if less or equal we are ok, else subtract
|
||||
.L6:
|
||||
sub eax,DVSRLO // subtract divisor from result
|
||||
sbb edx,DVSRHI
|
||||
.L7:
|
||||
|
||||
//
|
||||
// Calculate remainder by subtracting the result from the original dividend.
|
||||
// Since the result is already in a register, we will do the subtract in the
|
||||
// opposite direction and negate the result if necessary.
|
||||
//
|
||||
|
||||
sub eax,DVNDLO // subtract dividend from result
|
||||
sbb edx,DVNDHI
|
||||
|
||||
//
|
||||
// Now check the result sign flag to see if the result is supposed to be positive
|
||||
// or negative. It is currently negated (because we subtracted in the 'wrong'
|
||||
// direction), so if the sign flag is set we are done, otherwise we must negate
|
||||
// the result to make it positive again.
|
||||
//
|
||||
|
||||
dec edi // check result sign flag
|
||||
jns short .L8 // result is ok, restore stack and return
|
||||
.L4:
|
||||
neg edx // otherwise, negate the result
|
||||
neg eax
|
||||
sbb edx,0
|
||||
|
||||
//
|
||||
// Just the cleanup left to do. edx:eax contains the quotient.
|
||||
// Restore the saved registers and return.
|
||||
//
|
||||
|
||||
.L8:
|
||||
pop edi
|
||||
pop ebx
|
||||
|
||||
ret 16
|
94
lib/sdk/crt/math/i386/allshl_asm.s
Normal file
94
lib/sdk/crt/math/i386/allshl_asm.s
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/allshl.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __allshl
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// llshl - long shift left
|
||||
//
|
||||
// Purpose:
|
||||
// Does a Long Shift Left (signed and unsigned are identical)
|
||||
// Shifts a long left any number of bits.
|
||||
//
|
||||
// Entry:
|
||||
// EDX:EAX - long value to be shifted
|
||||
// CL - number of bits to shift by
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX - shifted value
|
||||
//
|
||||
// Uses:
|
||||
// CL is destroyed.
|
||||
//
|
||||
|
||||
__allshl:
|
||||
|
||||
//
|
||||
// Handle shifts of 64 or more bits (all get 0)
|
||||
//
|
||||
cmp cl, 64
|
||||
jae short RETZERO
|
||||
|
||||
//
|
||||
// Handle shifts of between 0 and 31 bits
|
||||
//
|
||||
cmp cl, 32
|
||||
jae short MORE32
|
||||
shld edx,eax,cl
|
||||
shl eax,cl
|
||||
ret
|
||||
|
||||
//
|
||||
// Handle shifts of between 32 and 63 bits
|
||||
//
|
||||
MORE32:
|
||||
mov edx,eax
|
||||
xor eax,eax
|
||||
and cl,31
|
||||
shl edx,cl
|
||||
ret
|
||||
|
||||
//
|
||||
// return 0 in edx:eax
|
||||
//
|
||||
RETZERO:
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
ret
|
95
lib/sdk/crt/math/i386/allshr_asm.s
Normal file
95
lib/sdk/crt/math/i386/allshr_asm.s
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/allshr.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __allshr
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// llshr - long shift right
|
||||
//
|
||||
// Purpose:
|
||||
// Does a signed Long Shift Right
|
||||
// Shifts a long right any number of bits.
|
||||
//
|
||||
// Entry:
|
||||
// EDX:EAX - long value to be shifted
|
||||
// CL - number of bits to shift by
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX - shifted value
|
||||
//
|
||||
// Uses:
|
||||
// CL is destroyed.
|
||||
//
|
||||
|
||||
__allshr:
|
||||
|
||||
//
|
||||
// Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
|
||||
// depends only on the high order bit of edx).
|
||||
//
|
||||
cmp cl,64
|
||||
jae short .RETSIGN
|
||||
|
||||
//
|
||||
// Handle shifts of between 0 and 31 bits
|
||||
//
|
||||
cmp cl, 32
|
||||
jae short .MORE32
|
||||
shrd eax,edx,cl
|
||||
sar edx,cl
|
||||
ret
|
||||
|
||||
//
|
||||
// Handle shifts of between 32 and 63 bits
|
||||
//
|
||||
.MORE32:
|
||||
mov eax,edx
|
||||
sar edx,31
|
||||
and cl,31
|
||||
sar eax,cl
|
||||
ret
|
||||
|
||||
//
|
||||
// Return double precision 0 or -1, depending on the sign of edx
|
||||
//
|
||||
.RETSIGN:
|
||||
sar edx,31
|
||||
mov eax,edx
|
||||
ret
|
27
lib/sdk/crt/math/i386/atan2.c
Normal file
27
lib/sdk/crt/math/i386/atan2.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
double atan2 (double __y, double __x);
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double atan2 (double __y, double __x)
|
||||
{
|
||||
register double __val;
|
||||
#ifdef __GNUC__
|
||||
__asm __volatile__
|
||||
("fpatan\n\t"
|
||||
"fld %%st(0)"
|
||||
: "=t" (__val) : "0" (__x), "u" (__y));
|
||||
#else
|
||||
__asm
|
||||
{
|
||||
fld __y
|
||||
fld __x
|
||||
fpatan
|
||||
fstp __val
|
||||
}
|
||||
#endif /*__GNUC__*/
|
||||
return __val;
|
||||
}
|
50
lib/sdk/crt/math/i386/atan_asm.s
Normal file
50
lib/sdk/crt/math/i386/atan_asm.s
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/atan.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _atan
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_atan:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fld1 // Load constant 1
|
||||
fpatan // Take the arctangent
|
||||
pop ebp
|
||||
ret
|
179
lib/sdk/crt/math/i386/aulldiv_asm.s
Normal file
179
lib/sdk/crt/math/i386/aulldiv_asm.s
Normal file
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/aulldiv_asm.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __aulldiv
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// ulldiv - unsigned long divide
|
||||
//
|
||||
// Purpose:
|
||||
// Does a unsigned long divide of the arguments. Arguments are
|
||||
// not changed.
|
||||
//
|
||||
// Entry:
|
||||
// Arguments are passed on the stack:
|
||||
// 1st pushed: divisor (QWORD)
|
||||
// 2nd pushed: dividend (QWORD)
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX contains the quotient (dividend/divisor)
|
||||
// NOTE: this routine removes the parameters from the stack.
|
||||
//
|
||||
// Uses:
|
||||
// ECX
|
||||
//
|
||||
|
||||
__aulldiv:
|
||||
|
||||
push ebx
|
||||
push esi
|
||||
|
||||
// Set up the local stack and save the index registers. When this is done
|
||||
// the stack frame will look as follows (assuming that the expression a/b will
|
||||
// generate a call to uldiv(a, b)):
|
||||
//
|
||||
// -----------------
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--divisor (b)--|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--dividend (a)-|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | return addr** |
|
||||
// |---------------|
|
||||
// | EBX |
|
||||
// |---------------|
|
||||
// ESP---->| ESI |
|
||||
// -----------------
|
||||
//
|
||||
|
||||
#undef DVNDLO
|
||||
#undef DVNDHI
|
||||
#undef DVSRLO
|
||||
#undef DVSRHI
|
||||
#define DVNDLO [esp + 12] // stack address of dividend (a)
|
||||
#define DVNDHI [esp + 16] // stack address of dividend (a)
|
||||
#define DVSRLO [esp + 20] // stack address of divisor (b)
|
||||
#define DVSRHI [esp + 24] // stack address of divisor (b)
|
||||
|
||||
//
|
||||
// Now do the divide. First look to see if the divisor is less than 4194304K.
|
||||
// If so, then we can use a simple algorithm with word divides, otherwise
|
||||
// things get a little more complex.
|
||||
//
|
||||
|
||||
mov eax,DVSRHI // check to see if divisor < 4194304K
|
||||
or eax,eax
|
||||
jnz short ..L1 // nope, gotta do this the hard way
|
||||
mov ecx,DVSRLO // load divisor
|
||||
mov eax,DVNDHI // load high word of dividend
|
||||
xor edx,edx
|
||||
div ecx // get high order bits of quotient
|
||||
mov ebx,eax // save high bits of quotient
|
||||
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
|
||||
div ecx // get low order bits of quotient
|
||||
mov edx,ebx // edx:eax <- quotient hi:quotient lo
|
||||
jmp short ..L2 // restore stack and return
|
||||
|
||||
//
|
||||
// Here we do it the hard way. Remember, eax contains DVSRHI
|
||||
//
|
||||
|
||||
..L1:
|
||||
mov ecx,eax // ecx:ebx <- divisor
|
||||
mov ebx,DVSRLO
|
||||
mov edx,DVNDHI // edx:eax <- dividend
|
||||
mov eax,DVNDLO
|
||||
..L3:
|
||||
shr ecx,1 // shift divisor right one bit// hi bit <- 0
|
||||
rcr ebx,1
|
||||
shr edx,1 // shift dividend right one bit// hi bit <- 0
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jnz short ..L3 // loop until divisor < 4194304K
|
||||
div ebx // now divide, ignore remainder
|
||||
mov esi,eax // save quotient
|
||||
|
||||
//
|
||||
// We may be off by one, so to check, we will multiply the quotient
|
||||
// by the divisor and check the result against the orignal dividend
|
||||
// Note that we must also check for overflow, which can occur if the
|
||||
// dividend is close to 2**64 and the quotient is off by 1.
|
||||
//
|
||||
|
||||
mul dword ptr DVSRHI // QUOT * DVSRHI
|
||||
mov ecx,eax
|
||||
mov eax,DVSRLO
|
||||
mul esi // QUOT * DVSRLO
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jc short ..L4 // carry means Quotient is off by 1
|
||||
|
||||
//
|
||||
// do long compare here between original dividend and the result of the
|
||||
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
|
||||
// subtract one (1) from the quotient.
|
||||
//
|
||||
|
||||
cmp edx,DVNDHI // compare hi words of result and original
|
||||
ja short ..L4 // if result > original, do subtract
|
||||
jb short ..L5 // if result < original, we are ok
|
||||
cmp eax,DVNDLO // hi words are equal, compare lo words
|
||||
jbe short ..L5 // if less or equal we are ok, else subtract
|
||||
..L4:
|
||||
dec esi // subtract 1 from quotient
|
||||
..L5:
|
||||
xor edx,edx // edx:eax <- quotient
|
||||
mov eax,esi
|
||||
|
||||
//
|
||||
// Just the cleanup left to do. edx:eax contains the quotient.
|
||||
// Restore the saved registers and return.
|
||||
//
|
||||
|
||||
..L2:
|
||||
|
||||
pop esi
|
||||
pop ebx
|
||||
|
||||
ret 16
|
204
lib/sdk/crt/math/i386/aulldvrm_asm.s
Normal file
204
lib/sdk/crt/math/i386/aulldvrm_asm.s
Normal file
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/aulldvrm.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __aulldvrm
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
__aulldvrm:
|
||||
|
||||
// ulldvrm - unsigned long divide and remainder
|
||||
//
|
||||
// Purpose:
|
||||
// Does a unsigned long divide and remainder of the arguments. Arguments
|
||||
// are not changed.
|
||||
//
|
||||
// Entry:
|
||||
// Arguments are passed on the stack:
|
||||
// 1st pushed: divisor (QWORD)
|
||||
// 2nd pushed: dividend (QWORD)
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX contains the quotient (dividend/divisor)
|
||||
// EBX:ECX contains the remainder (divided % divisor)
|
||||
// NOTE: this routine removes the parameters from the stack.
|
||||
//
|
||||
// Uses:
|
||||
// ECX
|
||||
//
|
||||
push esi
|
||||
|
||||
// Set up the local stack and save the index registers. When this is done
|
||||
// the stack frame will look as follows (assuming that the expression a/b will
|
||||
// generate a call to aulldvrm(a, b)):
|
||||
//
|
||||
// -----------------
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--divisor (b)--|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--dividend (a)-|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | return addr** |
|
||||
// |---------------|
|
||||
// ESP---->| ESI |
|
||||
// -----------------
|
||||
//
|
||||
|
||||
#undef DVNDLO
|
||||
#undef DVNDHI
|
||||
#undef DVSRLO
|
||||
#undef DVSRHI
|
||||
#define DVNDLO [esp + 8] // stack address of dividend (a)
|
||||
#define DVNDHI [esp + 12] // stack address of dividend (a)
|
||||
#define DVSRLO [esp + 16] // stack address of divisor (b)
|
||||
#define DVSRHI [esp + 20] // stack address of divisor (b)
|
||||
|
||||
//
|
||||
// Now do the divide. First look to see if the divisor is less than 4194304K.
|
||||
// If so, then we can use a simple algorithm with word divides, otherwise
|
||||
// things get a little more complex.
|
||||
//
|
||||
|
||||
mov eax,DVSRHI // check to see if divisor < 4194304K
|
||||
or eax,eax
|
||||
jnz short .....L1 // nope, gotta do this the hard way
|
||||
mov ecx,DVSRLO // load divisor
|
||||
mov eax,DVNDHI // load high word of dividend
|
||||
xor edx,edx
|
||||
div ecx // get high order bits of quotient
|
||||
mov ebx,eax // save high bits of quotient
|
||||
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
|
||||
div ecx // get low order bits of quotient
|
||||
mov esi,eax // ebx:esi <- quotient
|
||||
|
||||
//
|
||||
// Now we need to do a multiply so that we can compute the remainder.
|
||||
//
|
||||
mov eax,ebx // set up high word of quotient
|
||||
mul dword ptr DVSRLO // HIWORD(QUOT) * DVSR
|
||||
mov ecx,eax // save the result in ecx
|
||||
mov eax,esi // set up low word of quotient
|
||||
mul dword ptr DVSRLO // LOWORD(QUOT) * DVSR
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jmp short .....L2 // complete remainder calculation
|
||||
|
||||
//
|
||||
// Here we do it the hard way. Remember, eax contains DVSRHI
|
||||
//
|
||||
|
||||
.....L1:
|
||||
mov ecx,eax // ecx:ebx <- divisor
|
||||
mov ebx,DVSRLO
|
||||
mov edx,DVNDHI // edx:eax <- dividend
|
||||
mov eax,DVNDLO
|
||||
.....L3:
|
||||
shr ecx,1 // shift divisor right one bit// hi bit <- 0
|
||||
rcr ebx,1
|
||||
shr edx,1 // shift dividend right one bit// hi bit <- 0
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jnz short .....L3 // loop until divisor < 4194304K
|
||||
div ebx // now divide, ignore remainder
|
||||
mov esi,eax // save quotient
|
||||
|
||||
//
|
||||
// We may be off by one, so to check, we will multiply the quotient
|
||||
// by the divisor and check the result against the orignal dividend
|
||||
// Note that we must also check for overflow, which can occur if the
|
||||
// dividend is close to 2**64 and the quotient is off by 1.
|
||||
//
|
||||
|
||||
mul dword ptr DVSRHI // QUOT * DVSRHI
|
||||
mov ecx,eax
|
||||
mov eax,DVSRLO
|
||||
mul esi // QUOT * DVSRLO
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jc short .....L4 // carry means Quotient is off by 1
|
||||
|
||||
//
|
||||
// do long compare here between original dividend and the result of the
|
||||
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
|
||||
// subtract one (1) from the quotient.
|
||||
//
|
||||
|
||||
cmp edx,DVNDHI // compare hi words of result and original
|
||||
ja short .....L4 // if result > original, do subtract
|
||||
jb short .....L5 // if result < original, we are ok
|
||||
cmp eax,DVNDLO // hi words are equal, compare lo words
|
||||
jbe short .....L5 // if less or equal we are ok, else subtract
|
||||
.....L4:
|
||||
dec esi // subtract 1 from quotient
|
||||
sub eax,DVSRLO // subtract divisor from result
|
||||
sbb edx,DVSRHI
|
||||
.....L5:
|
||||
xor ebx,ebx // ebx:esi <- quotient
|
||||
|
||||
.....L2:
|
||||
//
|
||||
// Calculate remainder by subtracting the result from the original dividend.
|
||||
// Since the result is already in a register, we will do the subtract in the
|
||||
// opposite direction and negate the result.
|
||||
//
|
||||
|
||||
sub eax,DVNDLO // subtract dividend from result
|
||||
sbb edx,DVNDHI
|
||||
neg edx // otherwise, negate the result
|
||||
neg eax
|
||||
sbb edx,0
|
||||
|
||||
//
|
||||
// Now we need to get the quotient into edx:eax and the remainder into ebx:ecx.
|
||||
//
|
||||
mov ecx,edx
|
||||
mov edx,ebx
|
||||
mov ebx,ecx
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
//
|
||||
// Just the cleanup left to do. edx:eax contains the quotient.
|
||||
// Restore the saved registers and return.
|
||||
//
|
||||
|
||||
pop esi
|
||||
|
||||
ret 16
|
184
lib/sdk/crt/math/i386/aullrem_asm.s
Normal file
184
lib/sdk/crt/math/i386/aullrem_asm.s
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/aullrem.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __aullrem
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// ullrem - unsigned long remainder
|
||||
//
|
||||
// Purpose:
|
||||
// Does a unsigned long remainder of the arguments. Arguments are
|
||||
// not changed.
|
||||
//
|
||||
// Entry:
|
||||
// Arguments are passed on the stack:
|
||||
// 1st pushed: divisor (QWORD)
|
||||
// 2nd pushed: dividend (QWORD)
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX contains the remainder (dividend%divisor)
|
||||
// NOTE: this routine removes the parameters from the stack.
|
||||
//
|
||||
// Uses:
|
||||
// ECX
|
||||
//
|
||||
|
||||
__aullrem:
|
||||
|
||||
push ebx
|
||||
|
||||
// Set up the local stack and save the index registers. When this is done
|
||||
// the stack frame will look as follows (assuming that the expression a%b will
|
||||
// generate a call to ullrem(a, b)):
|
||||
//
|
||||
// -----------------
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--divisor (b)--|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | |
|
||||
// |--dividend (a)-|
|
||||
// | |
|
||||
// |---------------|
|
||||
// | return addr** |
|
||||
// |---------------|
|
||||
// ESP---->| EBX |
|
||||
// -----------------
|
||||
//
|
||||
|
||||
#undef DVNDLO
|
||||
#undef DVNDHI
|
||||
#undef DVSRLO
|
||||
#undef DVSRHI
|
||||
#define DVNDLO [esp + 8] // stack address of dividend (a)
|
||||
#define DVNDHI [esp + 12] // stack address of dividend (a)
|
||||
#define DVSRLO [esp + 16] // stack address of divisor (b)
|
||||
#define DVSRHI [esp + 20] // stack address of divisor (b)
|
||||
|
||||
// Now do the divide. First look to see if the divisor is less than 4194304K.
|
||||
// If so, then we can use a simple algorithm with word divides, otherwise
|
||||
// things get a little more complex.
|
||||
//
|
||||
|
||||
mov eax,DVSRHI // check to see if divisor < 4194304K
|
||||
or eax,eax
|
||||
jnz short ...L1 // nope, gotta do this the hard way
|
||||
mov ecx,DVSRLO // load divisor
|
||||
mov eax,DVNDHI // load high word of dividend
|
||||
xor edx,edx
|
||||
div ecx // edx <- remainder, eax <- quotient
|
||||
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
|
||||
div ecx // edx <- final remainder
|
||||
mov eax,edx // edx:eax <- remainder
|
||||
xor edx,edx
|
||||
jmp short ...L2 // restore stack and return
|
||||
|
||||
//
|
||||
// Here we do it the hard way. Remember, eax contains DVSRHI
|
||||
//
|
||||
|
||||
...L1:
|
||||
mov ecx,eax // ecx:ebx <- divisor
|
||||
mov ebx,DVSRLO
|
||||
mov edx,DVNDHI // edx:eax <- dividend
|
||||
mov eax,DVNDLO
|
||||
...L3:
|
||||
shr ecx,1 // shift divisor right one bit// hi bit <- 0
|
||||
rcr ebx,1
|
||||
shr edx,1 // shift dividend right one bit// hi bit <- 0
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jnz short ...L3 // loop until divisor < 4194304K
|
||||
div ebx // now divide, ignore remainder
|
||||
|
||||
//
|
||||
// We may be off by one, so to check, we will multiply the quotient
|
||||
// by the divisor and check the result against the orignal dividend
|
||||
// Note that we must also check for overflow, which can occur if the
|
||||
// dividend is close to 2**64 and the quotient is off by 1.
|
||||
//
|
||||
|
||||
mov ecx,eax // save a copy of quotient in ECX
|
||||
mul dword ptr DVSRHI
|
||||
xchg ecx,eax // put partial product in ECX, get quotient in EAX
|
||||
mul dword ptr DVSRLO
|
||||
add edx,ecx // EDX:EAX = QUOT * DVSR
|
||||
jc short ...L4 // carry means Quotient is off by 1
|
||||
|
||||
//
|
||||
// do long compare here between original dividend and the result of the
|
||||
// multiply in edx:eax. If original is larger or equal, we're ok, otherwise
|
||||
// subtract the original divisor from the result.
|
||||
//
|
||||
|
||||
cmp edx,DVNDHI // compare hi words of result and original
|
||||
ja short ...L4 // if result > original, do subtract
|
||||
jb short ...L5 // if result < original, we're ok
|
||||
cmp eax,DVNDLO // hi words are equal, compare lo words
|
||||
jbe short ...L5 // if less or equal we're ok, else subtract
|
||||
...L4:
|
||||
sub eax,DVSRLO // subtract divisor from result
|
||||
sbb edx,DVSRHI
|
||||
...L5:
|
||||
|
||||
//
|
||||
// Calculate remainder by subtracting the result from the original dividend.
|
||||
// Since the result is already in a register, we will perform the subtract in
|
||||
// the opposite direction and negate the result to make it positive.
|
||||
//
|
||||
|
||||
sub eax,DVNDLO // subtract original dividend from result
|
||||
sbb edx,DVNDHI
|
||||
neg edx // and negate it
|
||||
neg eax
|
||||
sbb edx,0
|
||||
|
||||
//
|
||||
// Just the cleanup left to do. dx:ax contains the remainder.
|
||||
// Restore the saved registers and return.
|
||||
//
|
||||
|
||||
...L2:
|
||||
|
||||
pop ebx
|
||||
|
||||
ret 16
|
95
lib/sdk/crt/math/i386/aullshr_asm.s
Normal file
95
lib/sdk/crt/math/i386/aullshr_asm.s
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/uallshr.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __aullshr
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
//
|
||||
// ullshr - long shift right
|
||||
//
|
||||
// Purpose:
|
||||
// Does a unsigned Long Shift Right
|
||||
// Shifts a long right any number of bits.
|
||||
//
|
||||
// Entry:
|
||||
// EDX:EAX - long value to be shifted
|
||||
// CL - number of bits to shift by
|
||||
//
|
||||
// Exit:
|
||||
// EDX:EAX - shifted value
|
||||
//
|
||||
// Uses:
|
||||
// CL is destroyed.
|
||||
//
|
||||
|
||||
__aullshr:
|
||||
|
||||
//
|
||||
// Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
|
||||
// depends only on the high order bit of edx).
|
||||
//
|
||||
cmp cl,64
|
||||
jae short ..RETZERO
|
||||
|
||||
//
|
||||
// Handle shifts of between 0 and 31 bits
|
||||
//
|
||||
cmp cl, 32
|
||||
jae short ..MORE32
|
||||
shrd eax,edx,cl
|
||||
shr edx,cl
|
||||
ret
|
||||
|
||||
//
|
||||
// Handle shifts of between 32 and 63 bits
|
||||
//
|
||||
..MORE32:
|
||||
mov eax,edx
|
||||
xor edx,edx
|
||||
and cl,31
|
||||
shr eax,cl
|
||||
ret
|
||||
|
||||
//
|
||||
// return 0 in edx:eax
|
||||
//
|
||||
..RETZERO:
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
ret
|
57
lib/sdk/crt/math/i386/ceil_asm.s
Normal file
57
lib/sdk/crt/math/i386/ceil_asm.s
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/ceil.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _ceil
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_ceil:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
sub esp,4 // Allocate temporary space
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fstcw [ebp-2] // Save control word
|
||||
fclex // Clear exceptions
|
||||
mov word ptr [ebp-4],0xb63 // Rounding control word
|
||||
fldcw [ebp-4] // Set new rounding control
|
||||
frndint // Round to integer
|
||||
fclex // Clear exceptions
|
||||
fldcw [ebp-2] // Restore control word
|
||||
mov esp,ebp // Deallocate temporary space
|
||||
pop ebp
|
||||
ret
|
55
lib/sdk/crt/math/i386/ceilf.S
Normal file
55
lib/sdk/crt/math/i386/ceilf.S
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#include <_mingw_mac.h>
|
||||
|
||||
.file "ceilf.S"
|
||||
.text
|
||||
.align 4
|
||||
.globl __MINGW_USYMBOL(ceilf)
|
||||
.def __MINGW_USYMBOL(ceilf); .scl 2; .type 32; .endef
|
||||
__MINGW_USYMBOL(ceilf):
|
||||
#ifdef _WIN64
|
||||
subq $24,%rsp
|
||||
movss %xmm0,8(%rsp)
|
||||
flds 8(%rsp)
|
||||
|
||||
fstcw 4(%rsp) /* store fpu control word */
|
||||
|
||||
movl $0x0800,%edx /* round towards +oo */
|
||||
orl 4(%rsp),%edx
|
||||
andl $0xfbff,%edx
|
||||
movl %edx,(%rsp)
|
||||
fldcw (%rsp) /* load modified control word */
|
||||
|
||||
frndint /* round */
|
||||
|
||||
fldcw 4(%rsp) /* restore original control word */
|
||||
fstps 8(%rsp)
|
||||
movss 8(%rsp),%xmm0
|
||||
addq $24,%rsp
|
||||
ret
|
||||
#else
|
||||
flds 4(%esp)
|
||||
subl $8,%esp
|
||||
|
||||
fstcw 4(%esp) /* store fpu control word */
|
||||
|
||||
/* We use here %edx although only the low 1 bits are defined.
|
||||
But none of the operations should care and they are faster
|
||||
than the 16 bit operations. */
|
||||
movl $0x0800,%edx /* round towards +oo */
|
||||
orl 4(%esp),%edx
|
||||
andl $0xfbff,%edx
|
||||
movl %edx,(%esp)
|
||||
fldcw (%esp) /* load modified control word */
|
||||
|
||||
frndint /* round */
|
||||
|
||||
fldcw 4(%esp) /* restore original control word */
|
||||
|
||||
addl $8,%esp
|
||||
ret
|
||||
#endif
|
145
lib/sdk/crt/math/i386/ci.c
Normal file
145
lib/sdk/crt/math/i386/ci.c
Normal file
|
@ -0,0 +1,145 @@
|
|||
#include <precomp.h>
|
||||
#include <math.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define FPU_DOUBLE(var) double var; \
|
||||
__asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
|
||||
#define FPU_DOUBLES(var1,var2) double var1,var2; \
|
||||
__asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
|
||||
__asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
|
||||
#elif defined(_MSC_VER)
|
||||
#define FPU_DOUBLE(var) double var; \
|
||||
__asm { fstp [var] }; __asm { fwait };
|
||||
#define FPU_DOUBLES(var1,var2) double var1,var2; \
|
||||
__asm { fstp [var1] }; __asm { fwait }; \
|
||||
__asm { fstp [var2] }; __asm { fwait };
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIsin(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return sin(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIcos(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return cos(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CItan(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return tan(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIsinh(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return sinh(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIcosh(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return cosh(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CItanh(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return tanh(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIasin(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return asin(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIacos(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return acos(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIatan(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return atan(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIatan2(void)
|
||||
{
|
||||
FPU_DOUBLES(x, y);
|
||||
return atan2(x, y);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIexp(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return exp(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIlog(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return log(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIlog10(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return log10(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIpow(void)
|
||||
{
|
||||
FPU_DOUBLES(x, y);
|
||||
return pow(x, y);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIsqrt(void)
|
||||
{
|
||||
FPU_DOUBLE(x);
|
||||
return sqrt(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIfmod(void)
|
||||
{
|
||||
FPU_DOUBLES(x, y);
|
||||
return fmod(x, y);
|
||||
}
|
49
lib/sdk/crt/math/i386/cos_asm.s
Normal file
49
lib/sdk/crt/math/i386/cos_asm.s
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/cos.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _cos
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_cos:
|
||||
push ebp
|
||||
mov ebp,esp // Point to the stack frame
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fcos // Take the cosine
|
||||
pop ebp
|
||||
ret
|
64
lib/sdk/crt/math/i386/exp.c
Normal file
64
lib/sdk/crt/math/i386/exp.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* Math functions for i387.
|
||||
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
double exp (double __x);
|
||||
|
||||
double exp (double __x)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
register double __value, __exponent;
|
||||
__asm __volatile__
|
||||
("fldl2e # e^x = 2^(x * log2(e))\n\t"
|
||||
"fmul %%st(1) # x * log2(e)\n\t"
|
||||
"fst %%st(1)\n\t"
|
||||
"frndint # int(x * log2(e))\n\t"
|
||||
"fxch\n\t"
|
||||
"fsub %%st(1) # fract(x * log2(e))\n\t"
|
||||
"f2xm1 # 2^(fract(x * log2(e))) - 1\n\t"
|
||||
: "=t" (__value), "=u" (__exponent) : "0" (__x));
|
||||
__value += 1.0;
|
||||
__asm __volatile__
|
||||
("fscale"
|
||||
: "=t" (__value) : "0" (__value), "u" (__exponent));
|
||||
|
||||
return __value;
|
||||
#else
|
||||
register double __val;
|
||||
__asm
|
||||
{
|
||||
fld1 // store 1.0 for later use
|
||||
fld __x
|
||||
fldl2e // e^x = 2^(x * log2(e))
|
||||
fmul st,st(1) // x * log2(e)
|
||||
fld st(0)
|
||||
frndint // int(x * log2(e))
|
||||
fsub st,st(1) // fract(x * log2(e))
|
||||
fxch
|
||||
f2xm1 // 2^(fract(x * log2(e))) - 1
|
||||
fadd st,st(3) // + 1.0
|
||||
fscale
|
||||
fstp __val
|
||||
}
|
||||
return __val;
|
||||
#endif /*__GNUC__*/
|
||||
}
|
49
lib/sdk/crt/math/i386/fabs_asm.s
Normal file
49
lib/sdk/crt/math/i386/fabs_asm.s
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/fabs.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _fabs
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_fabs:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fabs // Take the absolute value
|
||||
pop ebp
|
||||
ret
|
57
lib/sdk/crt/math/i386/floor_asm.s
Normal file
57
lib/sdk/crt/math/i386/floor_asm.s
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/floor.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _floor
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_floor:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
sub esp,4 // Allocate temporary space
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fstcw [ebp-2] // Save control word
|
||||
fclex // Clear exceptions
|
||||
mov word ptr [ebp-4],0x763 // Rounding control word
|
||||
fldcw [ebp-4] // Set new rounding control
|
||||
frndint // Round to integer
|
||||
fclex // Clear exceptions
|
||||
fldcw [ebp-2] // Restore control word
|
||||
mov esp,ebp
|
||||
pop ebp
|
||||
ret
|
63
lib/sdk/crt/math/i386/floorf.S
Normal file
63
lib/sdk/crt/math/i386/floorf.S
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Written by J.T. Conklin <jtc@netbsd.org>.
|
||||
* Public domain.
|
||||
*
|
||||
* Changes for long double by Ulrich Drepper <drepper@cygnus.com>
|
||||
*
|
||||
* Removed header file dependency for use in libmingwex.a by
|
||||
* Danny Smith <dannysmith@users.sourceforge.net>
|
||||
*/
|
||||
#include <_mingw_mac.h>
|
||||
|
||||
.file "floorf.S"
|
||||
.text
|
||||
#ifdef _WIN64
|
||||
.align 8
|
||||
#else
|
||||
.align 4
|
||||
#endif
|
||||
.globl __MINGW_USYMBOL(floorf)
|
||||
.def __MINGW_USYMBOL(floorf); .scl 2; .type 32; .endef
|
||||
__MINGW_USYMBOL(floorf):
|
||||
#ifdef _WIN64
|
||||
subq $24,%rsp
|
||||
movss %xmm0,8(%rsp)
|
||||
flds 8(%rsp)
|
||||
|
||||
fstcw 4(%rsp) /* store fpu control word */
|
||||
movl $0x400,%edx /* round towards -oo */
|
||||
orl 4(%rsp),%edx
|
||||
andl $0xf7ff,%edx
|
||||
movl %edx,(%rsp)
|
||||
fldcw (%rsp) /* load modified control word */
|
||||
|
||||
frndint /* round */
|
||||
|
||||
fldcw 4(%rsp) /* restore original control word */
|
||||
|
||||
fstps 8(%rsp)
|
||||
movss 8(%rsp),%xmm0
|
||||
addq $24,%rsp
|
||||
ret
|
||||
#else
|
||||
flds 4(%esp)
|
||||
subl $8,%esp
|
||||
|
||||
fstcw 4(%esp) /* store fpu control word */
|
||||
|
||||
/* We use here %edx although only the low 1 bits are defined.
|
||||
But none of the operations should care and they are faster
|
||||
than the 16 bit operations. */
|
||||
movl $0x400,%edx /* round towards -oo */
|
||||
orl 4(%esp),%edx
|
||||
andl $0xf7ff,%edx
|
||||
movl %edx,(%esp)
|
||||
fldcw (%esp) /* load modified control word */
|
||||
|
||||
frndint /* round */
|
||||
|
||||
fldcw 4(%esp) /* restore original control word */
|
||||
|
||||
addl $8,%esp
|
||||
ret
|
||||
#endif
|
49
lib/sdk/crt/math/i386/fmod.c
Normal file
49
lib/sdk/crt/math/i386/fmod.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* Math functions for i387.
|
||||
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
double fmod (double __x, double __y);
|
||||
|
||||
double fmod (double __x, double __y)
|
||||
{
|
||||
register double __val;
|
||||
#ifdef __GNUC__
|
||||
__asm __volatile__
|
||||
("1: fprem\n\t"
|
||||
"fstsw %%ax\n\t"
|
||||
"sahf\n\t"
|
||||
"jp 1b"
|
||||
: "=t" (__val) : "0" (__x), "u" (__y) : "ax", "cc");
|
||||
#else
|
||||
__asm
|
||||
{
|
||||
fld __y
|
||||
fld __x
|
||||
L1: fprem1
|
||||
fstsw ax
|
||||
sahf
|
||||
jp L1
|
||||
fstp __val
|
||||
}
|
||||
#endif /*__GNUC__*/
|
||||
return __val;
|
||||
}
|
28
lib/sdk/crt/math/i386/fmodf.c
Normal file
28
lib/sdk/crt/math/i386/fmodf.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
/*
|
||||
* Written by J.T. Conklin <jtc@netbsd.org>.
|
||||
* Public domain.
|
||||
*
|
||||
* Adapted for float type by Danny Smith
|
||||
* <dannysmith@users.sourceforge.net>.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
float
|
||||
fmodf (float x, float y)
|
||||
{
|
||||
float res = 0.0F;
|
||||
|
||||
asm ("1:\tfprem\n\t"
|
||||
"fstsw %%ax\n\t"
|
||||
"sahf\n\t"
|
||||
"jp 1b\n\t"
|
||||
"fstp %%st(1)"
|
||||
: "=t" (res) : "0" (x), "u" (y) : "ax", "st(1)");
|
||||
return res;
|
||||
}
|
73
lib/sdk/crt/math/i386/ftol_asm.s
Normal file
73
lib/sdk/crt/math/i386/ftol_asm.s
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/ftol.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl __ftol
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
/*
|
||||
* This routine is called by MSVC-generated code to convert from floating point
|
||||
* to integer representation. The floating point number to be converted is
|
||||
* on the top of the floating point stack.
|
||||
*/
|
||||
__ftol:
|
||||
/* Set up stack frame */
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
/* Set "round towards zero" mode */
|
||||
fstcw [ebp-2]
|
||||
wait
|
||||
mov ax, [ebp-2]
|
||||
or ah, 0xC
|
||||
mov [ebp-4], ax
|
||||
fldcw [ebp-4]
|
||||
|
||||
/* Do the conversion */
|
||||
fistp qword ptr [ebp-12]
|
||||
|
||||
/* Restore rounding mode */
|
||||
fldcw [ebp-2]
|
||||
|
||||
/* Return value */
|
||||
mov eax, [ebp-12]
|
||||
mov edx, [ebp-8]
|
||||
|
||||
/* Remove stack frame and return*/
|
||||
leave
|
||||
ret
|
52
lib/sdk/crt/math/i386/ldexp.c
Normal file
52
lib/sdk/crt/math/i386/ldexp.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* Math functions for i387.
|
||||
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
double ldexp (double value, int exp)
|
||||
{
|
||||
register double result;
|
||||
#ifdef __GNUC__
|
||||
#if defined(__clang__)
|
||||
asm ("fild %[exp]\n"
|
||||
"fscale\n"
|
||||
"fstp %%st(1)\n"
|
||||
: [result] "=t" (result)
|
||||
: [value] "0" (value), [exp] "m" (exp));
|
||||
#else
|
||||
asm ("fscale"
|
||||
: "=t" (result)
|
||||
: "0" (value), "u" ((double)exp)
|
||||
: "1");
|
||||
#endif
|
||||
#else /* !__GNUC__ */
|
||||
register double __dy = (double)exp;
|
||||
__asm
|
||||
{
|
||||
fld __dy
|
||||
fld value
|
||||
fscale
|
||||
fstp result
|
||||
}
|
||||
#endif /* !__GNUC__ */
|
||||
return result;
|
||||
}
|
||||
|
27
lib/sdk/crt/math/i386/log10_asm.s
Normal file
27
lib/sdk/crt/math/i386/log10_asm.s
Normal file
|
@ -0,0 +1,27 @@
|
|||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE:
|
||||
* FILE:
|
||||
* PROGRAMER: Magnus Olsen (magnus@greatlord.com)
|
||||
*
|
||||
*/
|
||||
|
||||
.globl _log10
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_log10:
|
||||
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fldlg2 // Load log base 10 of 2
|
||||
fxch st(1) // Exchange st, st(1)
|
||||
fyl2x // Compute the log base 10(x)
|
||||
pop ebp
|
||||
ret
|
||||
|
51
lib/sdk/crt/math/i386/log_asm.s
Normal file
51
lib/sdk/crt/math/i386/log_asm.s
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/log.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _log
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_log:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fldln2 // Load log base e of 2
|
||||
fxch st(1) // Exchange st, st(1)
|
||||
fyl2x // Compute the natural log(x)
|
||||
pop ebp
|
||||
ret
|
368
lib/sdk/crt/math/i386/pow_asm.s
Normal file
368
lib/sdk/crt/math/i386/pow_asm.s
Normal file
|
@ -0,0 +1,368 @@
|
|||
/* ix87 specific implementation of pow function.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2001, 2004, 2005, 2007
|
||||
Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
/* Reacros modifications */
|
||||
#define ALIGNARG(log2) log2
|
||||
#define ASM_TYPE_DIRECTIVE(name,typearg)
|
||||
#define ASM_SIZE_DIRECTIVE(name)
|
||||
#define cfi_adjust_cfa_offset(x)
|
||||
#define ENTRY(x)
|
||||
#define END(x)
|
||||
.global _pow
|
||||
|
||||
.text
|
||||
|
||||
.align ALIGNARG(4)
|
||||
ASM_TYPE_DIRECTIVE(infinity,@object)
|
||||
inf_zero:
|
||||
infinity:
|
||||
.byte 0, 0, 0, 0, 0, 0, 0xf0, 0x7f
|
||||
ASM_SIZE_DIRECTIVE(infinity)
|
||||
ASM_TYPE_DIRECTIVE(zero,@object)
|
||||
zero: .double 0.0
|
||||
ASM_SIZE_DIRECTIVE(zero)
|
||||
ASM_TYPE_DIRECTIVE(minf_mzero,@object)
|
||||
minf_mzero:
|
||||
minfinity:
|
||||
.byte 0, 0, 0, 0, 0, 0, 0xf0, 0xff
|
||||
mzero:
|
||||
.byte 0, 0, 0, 0, 0, 0, 0, 0x80
|
||||
ASM_SIZE_DIRECTIVE(minf_mzero)
|
||||
ASM_TYPE_DIRECTIVE(one,@object)
|
||||
one: .double 1.0
|
||||
ASM_SIZE_DIRECTIVE(one)
|
||||
ASM_TYPE_DIRECTIVE(limit,@object)
|
||||
limit: .double 0.29
|
||||
ASM_SIZE_DIRECTIVE(limit)
|
||||
ASM_TYPE_DIRECTIVE(p63,@object)
|
||||
p63: .byte 0, 0, 0, 0, 0, 0, 0xe0, 0x43
|
||||
ASM_SIZE_DIRECTIVE(p63)
|
||||
|
||||
#ifdef PIC
|
||||
#define MO(op) op##@GOTOFF(%ecx)
|
||||
#define MOX(op,x,f) op##@GOTOFF(%ecx,x,f)
|
||||
#else
|
||||
#define MO(op) op
|
||||
#define MOX(op,x,f) op(,x,f)
|
||||
#endif
|
||||
|
||||
.text
|
||||
_pow:
|
||||
ENTRY(__ieee754_pow)
|
||||
fldl 12(%esp) // y
|
||||
fxam
|
||||
|
||||
#ifdef PIC
|
||||
LOAD_PIC_REG (cx)
|
||||
#endif
|
||||
|
||||
fnstsw
|
||||
movb %ah, %dl
|
||||
andb $0x45, %ah
|
||||
cmpb $0x40, %ah // is y == 0 ?
|
||||
je 11f
|
||||
|
||||
cmpb $0x05, %ah // is y == ±inf ?
|
||||
je 12f
|
||||
|
||||
cmpb $0x01, %ah // is y == NaN ?
|
||||
je 30f
|
||||
|
||||
fldl 4(%esp) // x : y
|
||||
|
||||
subl $8,%esp
|
||||
cfi_adjust_cfa_offset (8)
|
||||
|
||||
fxam
|
||||
fnstsw
|
||||
movb %ah, %dh
|
||||
andb $0x45, %ah
|
||||
cmpb $0x40, %ah
|
||||
je 20f // x is ±0
|
||||
|
||||
cmpb $0x05, %ah
|
||||
je 15f // x is ±inf
|
||||
|
||||
fxch // y : x
|
||||
|
||||
/* fistpll raises invalid exception for |y| >= 1L<<63. */
|
||||
fld %st // y : y : x
|
||||
fabs // |y| : y : x
|
||||
fcompl MO(p63) // y : x
|
||||
fnstsw
|
||||
sahf
|
||||
jnc 2f
|
||||
|
||||
/* First see whether `y' is a natural number. In this case we
|
||||
can use a more precise algorithm. */
|
||||
fld %st // y : y : x
|
||||
fistpll (%esp) // y : x
|
||||
fildll (%esp) // int(y) : y : x
|
||||
fucomp %st(1) // y : x
|
||||
fnstsw
|
||||
sahf
|
||||
jne 2f
|
||||
|
||||
/* OK, we have an integer value for y. */
|
||||
popl %eax
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
popl %edx
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
orl $0, %edx
|
||||
fstp %st(0) // x
|
||||
jns 4f // y >= 0, jump
|
||||
fdivrl MO(one) // 1/x (now referred to as x)
|
||||
negl %eax
|
||||
adcl $0, %edx
|
||||
negl %edx
|
||||
4: fldl MO(one) // 1 : x
|
||||
fxch
|
||||
|
||||
6: shrdl $1, %edx, %eax
|
||||
jnc 5f
|
||||
fxch
|
||||
fmul %st(1) // x : ST*x
|
||||
fxch
|
||||
5: fmul %st(0), %st // x*x : ST*x
|
||||
shrl $1, %edx
|
||||
movl %eax, %ecx
|
||||
orl %edx, %ecx
|
||||
jnz 6b
|
||||
fstp %st(0) // ST*x
|
||||
ret
|
||||
|
||||
/* y is ±NAN */
|
||||
30: fldl 4(%esp) // x : y
|
||||
fldl MO(one) // 1.0 : x : y
|
||||
fucomp %st(1) // x : y
|
||||
fnstsw
|
||||
sahf
|
||||
je 31f
|
||||
fxch // y : x
|
||||
31: fstp %st(1)
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
.align ALIGNARG(4)
|
||||
2: /* y is a real number. */
|
||||
fxch // x : y
|
||||
fldl MO(one) // 1.0 : x : y
|
||||
fldl MO(limit) // 0.29 : 1.0 : x : y
|
||||
fld %st(2) // x : 0.29 : 1.0 : x : y
|
||||
fsub %st(2) // x-1 : 0.29 : 1.0 : x : y
|
||||
fabs // |x-1| : 0.29 : 1.0 : x : y
|
||||
fucompp // 1.0 : x : y
|
||||
fnstsw
|
||||
fxch // x : 1.0 : y
|
||||
sahf
|
||||
ja 7f
|
||||
fsub %st(1) // x-1 : 1.0 : y
|
||||
fyl2xp1 // log2(x) : y
|
||||
jmp 8f
|
||||
|
||||
7: fyl2x // log2(x) : y
|
||||
8: fmul %st(1) // y*log2(x) : y
|
||||
fst %st(1) // y*log2(x) : y*log2(x)
|
||||
frndint // int(y*log2(x)) : y*log2(x)
|
||||
fsubr %st, %st(1) // int(y*log2(x)) : fract(y*log2(x))
|
||||
fxch // fract(y*log2(x)) : int(y*log2(x))
|
||||
f2xm1 // 2^fract(y*log2(x))-1 : int(y*log2(x))
|
||||
faddl MO(one) // 2^fract(y*log2(x)) : int(y*log2(x))
|
||||
fscale // 2^fract(y*log2(x))*2^int(y*log2(x)) : int(y*log2(x))
|
||||
addl $8, %esp
|
||||
cfi_adjust_cfa_offset (-8)
|
||||
fstp %st(1) // 2^fract(y*log2(x))*2^int(y*log2(x))
|
||||
ret
|
||||
|
||||
|
||||
// pow(x,±0) = 1
|
||||
.align ALIGNARG(4)
|
||||
11: fstp %st(0) // pop y
|
||||
fldl MO(one)
|
||||
ret
|
||||
|
||||
// y == ±inf
|
||||
.align ALIGNARG(4)
|
||||
12: fstp %st(0) // pop y
|
||||
fldl MO(one) // 1
|
||||
fldl 4(%esp) // x : 1
|
||||
fabs // abs(x) : 1
|
||||
fucompp // < 1, == 1, or > 1
|
||||
fnstsw
|
||||
andb $0x45, %ah
|
||||
cmpb $0x45, %ah
|
||||
je 13f // jump if x is NaN
|
||||
|
||||
cmpb $0x40, %ah
|
||||
je 14f // jump if |x| == 1
|
||||
|
||||
shlb $1, %ah
|
||||
xorb %ah, %dl
|
||||
andl $2, %edx
|
||||
fldl MOX(inf_zero, %edx, 4)
|
||||
ret
|
||||
|
||||
.align ALIGNARG(4)
|
||||
14: fldl MO(one)
|
||||
ret
|
||||
|
||||
.align ALIGNARG(4)
|
||||
13: fldl 4(%esp) // load x == NaN
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
.align ALIGNARG(4)
|
||||
// x is ±inf
|
||||
15: fstp %st(0) // y
|
||||
testb $2, %dh
|
||||
jz 16f // jump if x == +inf
|
||||
|
||||
// We must find out whether y is an odd integer.
|
||||
fld %st // y : y
|
||||
fistpll (%esp) // y
|
||||
fildll (%esp) // int(y) : y
|
||||
fucompp // <empty>
|
||||
fnstsw
|
||||
sahf
|
||||
jne 17f
|
||||
|
||||
// OK, the value is an integer, but is the number of bits small
|
||||
// enough so that all are coming from the mantissa?
|
||||
popl %eax
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
popl %edx
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
andb $1, %al
|
||||
jz 18f // jump if not odd
|
||||
movl %edx, %eax
|
||||
orl %edx, %edx
|
||||
jns 155f
|
||||
negl %eax
|
||||
155: cmpl $0x00200000, %eax
|
||||
ja 18f // does not fit in mantissa bits
|
||||
// It's an odd integer.
|
||||
shrl $31, %edx
|
||||
fldl MOX(minf_mzero, %edx, 8)
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
.align ALIGNARG(4)
|
||||
16: fcompl MO(zero)
|
||||
addl $8, %esp
|
||||
cfi_adjust_cfa_offset (-8)
|
||||
fnstsw
|
||||
shrl $5, %eax
|
||||
andl $8, %eax
|
||||
fldl MOX(inf_zero, %eax, 1)
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
.align ALIGNARG(4)
|
||||
17: shll $30, %edx // sign bit for y in right position
|
||||
addl $8, %esp
|
||||
cfi_adjust_cfa_offset (-8)
|
||||
18: shrl $31, %edx
|
||||
fldl MOX(inf_zero, %edx, 8)
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
.align ALIGNARG(4)
|
||||
// x is ±0
|
||||
20: fstp %st(0) // y
|
||||
testb $2, %dl
|
||||
jz 21f // y > 0
|
||||
|
||||
// x is ±0 and y is < 0. We must find out whether y is an odd integer.
|
||||
testb $2, %dh
|
||||
jz 25f
|
||||
|
||||
fld %st // y : y
|
||||
fistpll (%esp) // y
|
||||
fildll (%esp) // int(y) : y
|
||||
fucompp // <empty>
|
||||
fnstsw
|
||||
sahf
|
||||
jne 26f
|
||||
|
||||
// OK, the value is an integer, but is the number of bits small
|
||||
// enough so that all are coming from the mantissa?
|
||||
popl %eax
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
popl %edx
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
andb $1, %al
|
||||
jz 27f // jump if not odd
|
||||
cmpl $0xffe00000, %edx
|
||||
jbe 27f // does not fit in mantissa bits
|
||||
// It's an odd integer.
|
||||
// Raise divide-by-zero exception and get minus infinity value.
|
||||
fldl MO(one)
|
||||
fdivl MO(zero)
|
||||
fchs
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
25: fstp %st(0)
|
||||
26: addl $8, %esp
|
||||
cfi_adjust_cfa_offset (-8)
|
||||
27: // Raise divide-by-zero exception and get infinity value.
|
||||
fldl MO(one)
|
||||
fdivl MO(zero)
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
.align ALIGNARG(4)
|
||||
// x is ±0 and y is > 0. We must find out whether y is an odd integer.
|
||||
21: testb $2, %dh
|
||||
jz 22f
|
||||
|
||||
fld %st // y : y
|
||||
fistpll (%esp) // y
|
||||
fildll (%esp) // int(y) : y
|
||||
fucompp // <empty>
|
||||
fnstsw
|
||||
sahf
|
||||
jne 23f
|
||||
|
||||
// OK, the value is an integer, but is the number of bits small
|
||||
// enough so that all are coming from the mantissa?
|
||||
popl %eax
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
popl %edx
|
||||
cfi_adjust_cfa_offset (-4)
|
||||
andb $1, %al
|
||||
jz 24f // jump if not odd
|
||||
cmpl $0xffe00000, %edx
|
||||
jae 24f // does not fit in mantissa bits
|
||||
// It's an odd integer.
|
||||
fldl MO(mzero)
|
||||
ret
|
||||
|
||||
cfi_adjust_cfa_offset (8)
|
||||
22: fstp %st(0)
|
||||
23: addl $8, %esp // Don't use 2 x pop
|
||||
cfi_adjust_cfa_offset (-8)
|
||||
24: fldl MO(zero)
|
||||
ret
|
||||
|
||||
END(__ieee754_pow)
|
||||
|
||||
|
49
lib/sdk/crt/math/i386/sin_asm.s
Normal file
49
lib/sdk/crt/math/i386/sin_asm.s
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/sin.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _sin
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_sin:
|
||||
push ebp // Save register bp
|
||||
mov ebp,esp // Point to the stack frame
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fsin // Take the sine
|
||||
pop ebp // Restore register bp
|
||||
ret
|
49
lib/sdk/crt/math/i386/sqrt_asm.s
Normal file
49
lib/sdk/crt/math/i386/sqrt_asm.s
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/sqrt.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _sqrt
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_sqrt:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fsqrt // Take the square root
|
||||
pop ebp
|
||||
ret
|
12
lib/sdk/crt/math/i386/sqrtf.c
Normal file
12
lib/sdk/crt/math/i386/sqrtf.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
float
|
||||
sqrtf(float x)
|
||||
{
|
||||
return ((float)sqrt((double)x));
|
||||
}
|
52
lib/sdk/crt/math/i386/tan_asm.s
Normal file
52
lib/sdk/crt/math/i386/tan_asm.s
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* PURPOSE: Run-Time Library
|
||||
* FILE: lib/rtl/i386/tan.S
|
||||
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
|
||||
*
|
||||
* Copyright (C) 2002 Michael Ringgaard.
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.globl _tan
|
||||
|
||||
.intel_syntax noprefix
|
||||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
_tan:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
sub esp,4 // Allocate temporary space
|
||||
fld qword ptr [ebp+8] // Load real from stack
|
||||
fptan // Take the tangent
|
||||
fstp dword ptr [ebp-4] // Throw away the constant 1
|
||||
mov esp,ebp // Deallocate temporary space
|
||||
pop ebp
|
||||
ret
|
30
lib/sdk/crt/math/j0_y0.c
Normal file
30
lib/sdk/crt/math/j0_y0.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <math.h>
|
||||
|
||||
typedef int fpclass_t;
|
||||
fpclass_t _fpclass(double __d);
|
||||
int *_errno(void);
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
double _j0(double num)
|
||||
{
|
||||
/* FIXME: errno handling */
|
||||
return j0(num);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double _y0(double num)
|
||||
{
|
||||
double retval;
|
||||
if (!isfinite(num)) *_errno() = EDOM;
|
||||
retval = y0(num);
|
||||
if (_fpclass(retval) == _FPCLASS_NINF)
|
||||
{
|
||||
*_errno() = EDOM;
|
||||
retval = sqrt(-1);
|
||||
}
|
||||
return retval;
|
||||
}
|
30
lib/sdk/crt/math/j1_y1.c
Normal file
30
lib/sdk/crt/math/j1_y1.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <math.h>
|
||||
|
||||
typedef int fpclass_t;
|
||||
fpclass_t _fpclass(double __d);
|
||||
int *_errno(void);
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
double _j1(double num)
|
||||
{
|
||||
/* FIXME: errno handling */
|
||||
return j1(num);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double _y1(double num)
|
||||
{
|
||||
double retval;
|
||||
if (!isfinite(num)) *_errno() = EDOM;
|
||||
retval = y1(num);
|
||||
if (_fpclass(retval) == _FPCLASS_NINF)
|
||||
{
|
||||
*_errno() = EDOM;
|
||||
retval = sqrt(-1);
|
||||
}
|
||||
return retval;
|
||||
}
|
30
lib/sdk/crt/math/jn_yn.c
Normal file
30
lib/sdk/crt/math/jn_yn.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <math.h>
|
||||
|
||||
typedef int fpclass_t;
|
||||
fpclass_t _fpclass(double __d);
|
||||
int *_errno(void);
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
double _jn(int n, double num)
|
||||
{
|
||||
/* FIXME: errno handling */
|
||||
return jn(n, num);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double _yn(int order, double num)
|
||||
{
|
||||
double retval;
|
||||
if (!isfinite(num)) *_errno() = EDOM;
|
||||
retval = yn(order,num);
|
||||
if (_fpclass(retval) == _FPCLASS_NINF)
|
||||
{
|
||||
*_errno() = EDOM;
|
||||
retval = sqrt(-1);
|
||||
}
|
||||
return retval;
|
||||
}
|
10
lib/sdk/crt/math/labs.c
Normal file
10
lib/sdk/crt/math/labs.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
long
|
||||
labs(long j)
|
||||
{
|
||||
return j<0 ? -j : j;
|
||||
}
|
28
lib/sdk/crt/math/ldiv.c
Normal file
28
lib/sdk/crt/math/ldiv.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <precomp.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
ldiv_t
|
||||
ldiv(long num, long denom)
|
||||
{
|
||||
ldiv_t r;
|
||||
|
||||
if (num > 0 && denom < 0)
|
||||
{
|
||||
num = -num;
|
||||
denom = -denom;
|
||||
}
|
||||
r.quot = num / denom;
|
||||
r.rem = num % denom;
|
||||
if (num < 0 && denom > 0)
|
||||
{
|
||||
if (r.rem > 0)
|
||||
{
|
||||
r.quot++;
|
||||
r.rem -= denom;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
11
lib/sdk/crt/math/logf.c
Normal file
11
lib/sdk/crt/math/logf.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
float logf(float _X)
|
||||
{
|
||||
return ((float)log((double)_X));
|
||||
}
|
86
lib/sdk/crt/math/modf.c
Normal file
86
lib/sdk/crt/math/modf.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* @(#)s_modf.c 1.3 95/01/18 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunSoft, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
|
||||
//static const double one = 1.0;
|
||||
|
||||
|
||||
|
||||
long double modfl(long double __x, long double *__i)
|
||||
{
|
||||
union
|
||||
{
|
||||
long double* __x;
|
||||
long_double_s* x;
|
||||
} x;
|
||||
union
|
||||
{
|
||||
long double* __i;
|
||||
long_double_s* iptr;
|
||||
} iptr;
|
||||
|
||||
int j0;
|
||||
unsigned int i;
|
||||
|
||||
x.__x = &__x;
|
||||
iptr.__i = __i;
|
||||
|
||||
|
||||
j0 = x.x->exponent - 0x3fff; /* exponent of x */
|
||||
|
||||
if(j0<32) { /* integer part in high x */
|
||||
if(j0<0) { /* |x|<1 */
|
||||
*__i = 0.0L;
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
return __x;
|
||||
} else {
|
||||
|
||||
i = ((unsigned int)(0xffffffff))>>(j0+1);
|
||||
if ( x.x->mantissal == 0 && (x.x->mantissal & i) == 0 ) {
|
||||
*__i = __x;
|
||||
__x = 0.0L;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
iptr.iptr->exponent = x.x->exponent;
|
||||
iptr.iptr->mantissah = x.x->mantissah&((~i));
|
||||
iptr.iptr->mantissal = 0;
|
||||
|
||||
return __x - *__i;
|
||||
}
|
||||
} else if (j0>63) { /* no fraction part */
|
||||
*__i = __x;
|
||||
if ( _isnanl(__x) || _isinfl(__x) )
|
||||
return __x;
|
||||
|
||||
__x = 0.0L;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
} else { /* fraction part in low x */
|
||||
|
||||
i = ((unsigned int)(0xffffffff))>>(j0-32);
|
||||
if ( x.x->mantissal == 0 ) {
|
||||
*__i = __x;
|
||||
__x = 0.0L;
|
||||
x.x->sign = iptr.iptr->sign;
|
||||
return __x;
|
||||
}
|
||||
iptr.iptr->sign = x.x->sign;
|
||||
iptr.iptr->exponent = x.x->exponent;
|
||||
iptr.iptr->mantissah = x.x->mantissah;
|
||||
iptr.iptr->mantissal = x.x->mantissal&(~i);
|
||||
|
||||
return __x - *__i;
|
||||
}
|
||||
}
|
31
lib/sdk/crt/math/pow_asm.c
Normal file
31
lib/sdk/crt/math/pow_asm.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* Math functions for i387.
|
||||
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
|
||||
long double powl (long double __x,long double __y)
|
||||
{
|
||||
return pow(__x,__y/2)*pow(__x,__y/2);
|
||||
}
|
11
lib/sdk/crt/math/powf.c
Normal file
11
lib/sdk/crt/math/powf.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
float powf(float x, float y)
|
||||
{
|
||||
return (float)pow((double)x, (double)y);
|
||||
}
|
47
lib/sdk/crt/math/rand.c
Normal file
47
lib/sdk/crt/math/rand.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <precomp.h>
|
||||
#include <ntsecapi.h>
|
||||
#include <internal/tls.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int
|
||||
rand(void)
|
||||
{
|
||||
PTHREADDATA ThreadData = GetThreadData();
|
||||
|
||||
ThreadData->tnext = ThreadData->tnext * 0x5deece66dLL + 2531011;
|
||||
return (int)((ThreadData->tnext >> 16) & RAND_MAX);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void
|
||||
srand(unsigned int seed)
|
||||
{
|
||||
PTHREADDATA ThreadData = GetThreadData();
|
||||
|
||||
ThreadData->tnext = (ULONGLONG)seed;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* rand_s (MSVCRT.@)
|
||||
*/
|
||||
int CDECL rand_s(unsigned int *pval)
|
||||
{
|
||||
BOOLEAN (WINAPI *pSystemFunction036)(PVOID, ULONG); // RtlGenRandom
|
||||
HINSTANCE hadvapi32 = LoadLibraryA("advapi32.dll");
|
||||
pSystemFunction036 = (void*)GetProcAddress(hadvapi32, "SystemFunction036");
|
||||
#if 1
|
||||
if (!pval || (pSystemFunction036 && !pSystemFunction036(pval, sizeof(*pval))))
|
||||
{
|
||||
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
||||
*_errno() = EINVAL;
|
||||
return EINVAL;
|
||||
}
|
||||
#endif
|
||||
if(hadvapi32) FreeLibrary(hadvapi32);
|
||||
return 0;
|
||||
}
|
29
lib/sdk/crt/math/rand_nt.c
Normal file
29
lib/sdk/crt/math/rand_nt.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
static unsigned long long next = 0;
|
||||
#else
|
||||
static unsigned __int64 next = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int rand(void)
|
||||
{
|
||||
#if defined(__GNUC__)
|
||||
next = next * 0x5deece66dLL + 11;
|
||||
#else
|
||||
next = next * 0x5deece66di64 + 11;
|
||||
#endif
|
||||
return (int)((next >> 16) & RAND_MAX);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void srand(unsigned seed)
|
||||
{
|
||||
next = seed;
|
||||
}
|
194
lib/sdk/crt/math/s_modf.c
Normal file
194
lib/sdk/crt/math/s_modf.c
Normal file
|
@ -0,0 +1,194 @@
|
|||
|
||||
|
||||
/* @(#)s_modf.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.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
FUNCTION
|
||||
<<modf>>, <<modff>>---split fractional and integer parts
|
||||
|
||||
INDEX
|
||||
modf
|
||||
INDEX
|
||||
modff
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <math.h>
|
||||
double modf(double <[val]>, double *<[ipart]>);
|
||||
float modff(float <[val]>, float *<[ipart]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <math.h>
|
||||
double modf(<[val]>, <[ipart]>)
|
||||
double <[val]>;
|
||||
double *<[ipart]>;
|
||||
|
||||
float modff(<[val]>, <[ipart]>)
|
||||
float <[val]>;
|
||||
float *<[ipart]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<modf>> splits the double <[val]> apart into an integer part
|
||||
and a fractional part, returning the fractional part and
|
||||
storing the integer part in <<*<[ipart]>>>. No rounding
|
||||
whatsoever is done; the sum of the integer and fractional
|
||||
parts is guaranteed to be exactly equal to <[val]>. That
|
||||
is, if . <[realpart]> = modf(<[val]>, &<[intpart]>); then
|
||||
`<<<[realpart]>+<[intpart]>>>' is the same as <[val]>.
|
||||
<<modff>> is identical, save that it takes and returns
|
||||
<<float>> rather than <<double>> values.
|
||||
|
||||
RETURNS
|
||||
The fractional part is returned. Each result has the same
|
||||
sign as the supplied argument <[val]>.
|
||||
|
||||
PORTABILITY
|
||||
<<modf>> is ANSI C. <<modff>> is an extension.
|
||||
|
||||
QUICKREF
|
||||
modf ansi pure
|
||||
modff - pure
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* modf(double x, double *iptr)
|
||||
* return fraction part of x, and return x's integral part in *iptr.
|
||||
* Method:
|
||||
* Bit twiddling.
|
||||
*
|
||||
* Exception:
|
||||
* No exception.
|
||||
*/
|
||||
|
||||
|
||||
static const double one = 1.0;
|
||||
|
||||
#define __int32_t long
|
||||
#define __uint32_t unsigned long
|
||||
#define __IEEE_LITTLE_ENDIAN
|
||||
|
||||
#ifdef __IEEE_BIG_ENDIAN
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
__uint32_t msw;
|
||||
__uint32_t lsw;
|
||||
} parts;
|
||||
double value;
|
||||
} ieee_double_shape_type;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __IEEE_LITTLE_ENDIAN
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
__uint32_t lsw;
|
||||
__uint32_t msw;
|
||||
} parts;
|
||||
double value;
|
||||
} ieee_double_shape_type;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Get two 32 bit ints from a double. */
|
||||
|
||||
#define EXTRACT_WORDS(ix0,ix1,d) \
|
||||
do { \
|
||||
ieee_double_shape_type ew_u; \
|
||||
ew_u.value = (d); \
|
||||
(ix0) = ew_u.parts.msw; \
|
||||
(ix1) = ew_u.parts.lsw; \
|
||||
} while (0)
|
||||
|
||||
/* Get the more significant 32 bit int from a double. */
|
||||
|
||||
#define GET_HIGH_WORD(i,d) \
|
||||
do { \
|
||||
ieee_double_shape_type gh_u; \
|
||||
gh_u.value = (d); \
|
||||
(i) = gh_u.parts.msw; \
|
||||
} while (0)
|
||||
|
||||
/* Get the less significant 32 bit int from a double. */
|
||||
|
||||
#define GET_LOW_WORD(i,d) \
|
||||
do { \
|
||||
ieee_double_shape_type gl_u; \
|
||||
gl_u.value = (d); \
|
||||
(i) = gl_u.parts.lsw; \
|
||||
} while (0)
|
||||
|
||||
/* Set a double from two 32 bit ints. */
|
||||
|
||||
#define INSERT_WORDS(d,ix0,ix1) \
|
||||
do { \
|
||||
ieee_double_shape_type iw_u; \
|
||||
iw_u.parts.msw = (ix0); \
|
||||
iw_u.parts.lsw = (ix1); \
|
||||
(d) = iw_u.value; \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
|
||||
double modf(double x, double *iptr)
|
||||
{
|
||||
__int32_t i0,i1,j_0;
|
||||
__uint32_t i;
|
||||
EXTRACT_WORDS(i0,i1,x);
|
||||
j_0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
|
||||
if(j_0<20) { /* integer part in high x */
|
||||
if(j_0<0) { /* |x|<1 */
|
||||
INSERT_WORDS(*iptr,i0&0x80000000U,0); /* *iptr = +-0 */
|
||||
return x;
|
||||
} else {
|
||||
i = (0x000fffff)>>j_0;
|
||||
if(((i0&i)|i1)==0) { /* x is integral */
|
||||
__uint32_t high;
|
||||
*iptr = x;
|
||||
GET_HIGH_WORD(high,x);
|
||||
INSERT_WORDS(x,high&0x80000000U,0); /* return +-0 */
|
||||
return x;
|
||||
} else {
|
||||
INSERT_WORDS(*iptr,i0&(~i),0);
|
||||
return x - *iptr;
|
||||
}
|
||||
}
|
||||
} else if (j_0>51) { /* no fraction part */
|
||||
__uint32_t high;
|
||||
*iptr = x*one;
|
||||
GET_HIGH_WORD(high,x);
|
||||
INSERT_WORDS(x,high&0x80000000U,0); /* return +-0 */
|
||||
return x;
|
||||
} else { /* fraction part in low x */
|
||||
i = ((__uint32_t)(0xffffffffU))>>(j_0-20);
|
||||
if((i1&i)==0) { /* x is integral */
|
||||
__uint32_t high;
|
||||
*iptr = x;
|
||||
GET_HIGH_WORD(high,x);
|
||||
INSERT_WORDS(x,high&0x80000000U,0); /* return +-0 */
|
||||
return x;
|
||||
} else {
|
||||
INSERT_WORDS(*iptr,i0,i1&(~i));
|
||||
return x - *iptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#endif /* _DOUBLE_IS_32BITS */
|
89
lib/sdk/crt/math/sin.c
Normal file
89
lib/sdk/crt/math/sin.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS CRT
|
||||
* FILE: lib/crt/math/sin.c
|
||||
* PURPOSE: Generic C Implementation of sin
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#define PRECISION 9
|
||||
#define M_PI 3.141592653589793238462643
|
||||
|
||||
static double sin_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
|
||||
static double sin_sign_tbl[] = {1,-1,-1,1};
|
||||
|
||||
double
|
||||
sin(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 - 1) & 0x3;
|
||||
|
||||
/* Fixup value for the generic function */
|
||||
x += sin_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*19*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 *= sin_sign_tbl[quadrant];
|
||||
|
||||
return result;
|
||||
}
|
11
lib/sdk/crt/math/sinf.c
Normal file
11
lib/sdk/crt/math/sinf.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
float sinf(float _X)
|
||||
{
|
||||
return ((float) sin ((double) _X));
|
||||
}
|
19
lib/sdk/crt/math/sinh.c
Normal file
19
lib/sdk/crt/math/sinh.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double sinh(double x)
|
||||
{
|
||||
if(x >= 0.0)
|
||||
{
|
||||
const double epos = exp(x);
|
||||
return (epos - 1.0/epos) / 2.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const double eneg = exp(-x);
|
||||
return (1.0/eneg - eneg) / 2.0;
|
||||
}
|
||||
}
|
220
lib/sdk/crt/math/stubs.c
Normal file
220
lib/sdk/crt/math/stubs.c
Normal file
|
@ -0,0 +1,220 @@
|
|||
#include <precomp.h>
|
||||
#include <math.h>
|
||||
|
||||
double CDECL _CIsin(double x);
|
||||
double CDECL _CIcos(double x);
|
||||
double CDECL _CItan(double x);
|
||||
double CDECL _CIsinh(double x);
|
||||
double CDECL _CIcosh(double x);
|
||||
double CDECL _CItanh(double x);
|
||||
double CDECL _CIasin(double x);
|
||||
double CDECL _CIacos(double x);
|
||||
double CDECL _CIatan(double x);
|
||||
double CDECL _CIatan2(double y, double x);
|
||||
double CDECL _CIexp(double x);
|
||||
double CDECL _CIlog(double x);
|
||||
double CDECL _CIlog10(double x);
|
||||
double CDECL _CIpow(double x, double y);
|
||||
double CDECL _CIsqrt(double x);
|
||||
double CDECL _CIfmod(double x, double y);
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIsin(double x)
|
||||
{
|
||||
return sin(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIcos(double x)
|
||||
{
|
||||
return cos(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CItan(double x)
|
||||
{
|
||||
return tan(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIsinh(double x)
|
||||
{
|
||||
return sinh(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIcosh(double x)
|
||||
{
|
||||
return cosh(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CItanh(double x)
|
||||
{
|
||||
return tanh(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIasin(double x)
|
||||
{
|
||||
return asin(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIacos(double x)
|
||||
{
|
||||
return acos(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIatan(double x)
|
||||
{
|
||||
return atan(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIatan2(double x, double y)
|
||||
{
|
||||
return atan2(y, x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIexp(double x)
|
||||
{
|
||||
return exp(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIlog(double x)
|
||||
{
|
||||
return log(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIlog10(double x)
|
||||
{
|
||||
return log10(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIpow(double x, double y)
|
||||
{
|
||||
return pow(x, y);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIsqrt(double x)
|
||||
{
|
||||
return sqrt(x);
|
||||
}
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double CDECL _CIfmod(double x, double y)
|
||||
{
|
||||
return fmod(x, y);
|
||||
}
|
||||
|
||||
/* The following functions are likely workarounds for the pentium fdiv bug */
|
||||
void __stdcall _adj_fdiv_m32( unsigned int arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m32 stub\n");
|
||||
}
|
||||
void __stdcall _adj_fdiv_m32i( int arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m32i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m64 stub\n");
|
||||
}
|
||||
|
||||
void _adj_fdiv_r(void)
|
||||
{
|
||||
FIXME("_adj_fdiv_r stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m32( unsigned int arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m32i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m32i( int arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m32i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m64 stub\n");
|
||||
}
|
||||
|
||||
void _adj_fpatan(void)
|
||||
{
|
||||
FIXME("_adj_fpatan stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdiv_m16i( short arg )
|
||||
{
|
||||
FIXME("_adj_fdiv_m16i stub\n");
|
||||
}
|
||||
|
||||
void __stdcall _adj_fdivr_m16i( short arg )
|
||||
{
|
||||
FIXME("_adj_fdivr_m16i stub\n");
|
||||
}
|
||||
|
||||
void _adj_fprem(void)
|
||||
{
|
||||
FIXME("_adj_fprem stub\n");
|
||||
}
|
||||
|
||||
void _adj_fprem1(void)
|
||||
{
|
||||
FIXME("_adj_fprem1 stub\n");
|
||||
}
|
||||
|
||||
void _adj_fptan(void)
|
||||
{
|
||||
FIXME("_adj_fptan stub\n");
|
||||
}
|
||||
|
||||
void _safe_fdiv(void)
|
||||
{
|
||||
FIXME("_safe_fdiv stub\n");
|
||||
}
|
||||
|
||||
void _safe_fdivr(void)
|
||||
{
|
||||
FIXME("_safe_fdivr stub\n");
|
||||
}
|
||||
|
||||
void _safe_fprem(void)
|
||||
{
|
||||
FIXME("_safe_fprem stub\n");
|
||||
}
|
||||
|
||||
void _safe_fprem1(void)
|
||||
{
|
||||
FIXME("_safe_fprem1 stub\n");
|
||||
}
|
||||
|
||||
|
20
lib/sdk/crt/math/tanh.c
Normal file
20
lib/sdk/crt/math/tanh.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
double tanh(double x)
|
||||
{
|
||||
if (x > 50)
|
||||
return 1;
|
||||
else if (x < -50)
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
const double ebig = exp(x);
|
||||
const double esmall = 1.0/ebig;
|
||||
return (ebig - esmall) / (ebig + esmall);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue