Create a branch for network fixes.

svn path=/branches/aicom-network-fixes/; revision=34994
This commit is contained in:
Art Yerkes 2008-08-01 11:32:26 +00:00
parent 0e213bbc00
commit c501d8112c
18148 changed files with 0 additions and 860488 deletions

13
lib/sdk/crt/math/abs.c Normal file
View file

@ -0,0 +1,13 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
/*
* @implemented
*/
#ifndef _MSC_VER
int
abs(int j)
{
return j<0 ? -j : j;
}
#endif

27
lib/sdk/crt/math/acos.c Normal file
View file

@ -0,0 +1,27 @@
/* 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 Library General Public License as
published by the Free Software Foundation; either version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <math.h>
double acos(double __x)
{
return atan2(sqrt(1.0 - __x * __x), __x);
}

View file

@ -0,0 +1,7 @@
/* $Id$
*
*/
int _adjust_fdiv = 0;
/* EOF */

27
lib/sdk/crt/math/asin.c Normal file
View file

@ -0,0 +1,27 @@
/* 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 Library General Public License as
published by the Free Software Foundation; either version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, 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
View 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);
}

12
lib/sdk/crt/math/cosh.c Normal file
View 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
View 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;
}

29
lib/sdk/crt/math/frexp.c Normal file
View 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_t* x;
} x;
x.__x = &__x;
if ( exptr != NULL )
*exptr = x.x->exponent - 0x3FE;
x.x->exponent = 0x3FE;
return __x;
}

View file

@ -0,0 +1,6 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <internal/ieee.h>
#undef _HUGE
double_t _HUGE = { 0x00000, 0x00000, 0x7ff, 0x0 };

98
lib/sdk/crt/math/hypot.c Normal file
View 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

View 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

View 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

View 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,AHI
mul ecx
ret 16 // callee restores the stack
hard:
push ebx
// must redefine A and B since esp has been altered
#define A2LO [esp + 4] // stack address of a
#define A2HI [esp + 8] // stack address of a
#define B2LO [esp + 12] // stack address of b
#define B2HI [esp + 16] // 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

View 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

View 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

View 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

View file

@ -0,0 +1,21 @@
#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
__val = linkme_atan2(__x, __y);
#endif /*__GNUC__*/
return __val;
}

View 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

View 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

View 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 + 8] // 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

View 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 + 8] // 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

View 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

View 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

View 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

View file

@ -0,0 +1,47 @@
/* 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 Library General Public License as
published by the Free Software Foundation; either version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, 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
return linkme_exp(__x);
#endif /*__GNUC__*/
}

View 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

View 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

View file

@ -0,0 +1,39 @@
/* 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 Library General Public License as
published by the Free Software Foundation; either version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, 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
__val = linkme_fmod(__x, __y);
#endif /*__GNUC__*/
return __val;
}

View 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

View file

@ -0,0 +1,36 @@
/* 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 Library General Public License as
published by the Free Software Foundation; either version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <math.h>
double ldexp (double __x, int __y);
double ldexp (double __x, int __y)
{
register double __val;
#ifdef __GNUC__
__asm __volatile__
("fscale"
: "=t" (__val) : "0" (__x), "u" ((double) __y));
#else
__val = linkme_ldexp(__x, __y);
#endif /*__GNUC__*/
return __val;
}

View 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

View 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

View file

@ -0,0 +1,139 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/pow.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 _pow
/* DATA ********************************************************************/
fzero:
.long 0 // Floating point zero
.long 0 // Floating point zero
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_pow:
push ebp
mov ebp,esp
sub esp,12 // Allocate temporary space
push edi // Save register edi
push eax // Save register eax
mov dword ptr [ebp-12],0 // Set negation flag to zero
fld qword ptr [ebp+16] // Load real from stack
fld qword ptr [ebp+8] // Load real from stack
mov edi,offset flat:fzero // Point to real zero
fcom qword ptr [edi] // Compare x with zero
fstsw ax // Get the FPU status word
mov al,ah // Move condition flags to AL
lahf // Load Flags into AH
and al, 0b01000101 // Isolate C0, C2 and C3
and ah, 0b10111010 // Turn off CF, PF and ZF
or ah,al // Set new CF, PF and ZF
sahf // Store AH into Flags
jb __fpow1 // Re-direct if x < 0
ja __fpow3 // Re-direct if x > 0
fxch // Swap st, st(1)
fcom qword ptr [edi] // Compare y with zero
fxch // Restore x as top of stack
fstsw ax // Get the FPU status word
mov al,ah // Move condition flags to AL
lahf // Load Flags into AH
and al, 0b01000101 // Isolate C0, C2 and C3
and ah, 0b10111010 // Turn off CF, PF and ZF
or ah,al // Set new CF, PF and ZF
sahf // Store AH into Flags
ja __fpow3 // Re-direct if y > 0
fstp st(1) // Set new stack top and pop
mov eax,1 // Set domain error (EDOM)
jmp __fpow5 // End of case
__fpow1: fxch // Put y on top of stack
fld st // Duplicate y as st(1)
frndint // Round to integer
fxch // Put y on top of stack
fcomp // y = int(y) ?
fstsw ax // Get the FPU status word
mov al,ah // Move condition flags to AL
lahf // Load Flags into AH
and al, 0b01000101 // Isolate C0, C2 and C3
and ah, 0b10111010 // Turn off CF, PF and ZF
or ah,al // Set new CF, PF and ZF
sahf // Store AH into Flags
je __fpow2 // Proceed if y = int(y)
fstp st(1) // Set new stack top and pop
fldz // Set result to zero
fstp st(1) // Set new stack top and pop
mov eax,1 // Set domain error (EDOM)
jmp __fpow5 // End of case
__fpow2: fist dword ptr [ebp-12] // Store y as integer
and dword ptr [ebp-12],1 // Set bit if y is odd
fxch // Put x on top of stack
fabs // x = |x|
__fpow3: fldln2 // Load log base e of 2
fxch st(1) // Exchange st, st(1)
fyl2x // Compute the natural log(x)
fmulp // Compute y * ln(x)
fldl2e // Load log base 2(e)
fmulp st(1),st // Multiply x * log base 2(e)
fst st(1) // Push result
frndint // Round to integer
fsub st(1),st // Subtract
fxch // Exchange st, st(1)
f2xm1 // Compute 2 to the (x - 1)
fld1 // Load real number 1
faddp // 2 to the x
fscale // Scale by power of 2
fstp st(1) // Set new stack top and pop
test dword ptr [ebp-12],1 // Negation required ?
jz __fpow4 // No, re-direct
fchs // Negate the result
__fpow4: fstp qword ptr [ebp-8] // Save (double)pow(x, y)
fld qword ptr [ebp-8] // Load (double)pow(x, y)
fxam // Examine st
fstsw ax // Get the FPU status word
cmp ah,5 // Infinity ?
jne __fpow6 // No, end of case
mov eax,2 // Set range error (ERANGE)
// Get errno pointer offset
__fpow5: int 3
mov edi,0 // TODO: offset flat:__crt_errno
mov edi,[edi] // Get C errno variable pointer
mov dword ptr [edi],eax // Set errno
__fpow6: pop eax // Restore register eax
pop edi // Restore register edi
mov esp,ebp // Deallocate temporary space
pop ebp
ret

View 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

View 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

View 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

18
lib/sdk/crt/math/j0_y0.c Normal file
View file

@ -0,0 +1,18 @@
#include <math.h>
/*
* @unimplemented
*/
double _j0(double x)
{
return x;
}
/*
* @unimplemented
*/
double _y0(double x)
{
return x;
}

18
lib/sdk/crt/math/j1_y1.c Normal file
View file

@ -0,0 +1,18 @@
#include <math.h>
/*
* @unimplemented
*/
double _j1(double x)
{
return x;
}
/*
* @unimplemented
*/
double _y1(double x)
{
return x;
}

18
lib/sdk/crt/math/jn_yn.c Normal file
View file

@ -0,0 +1,18 @@
#include <math.h>
/*
* @unimplemented
*/
double _jn(int n, double x)
{
return x;
}
/*
* @unimplemented
*/
double _yn(int n, double x)
{
return x;
}

13
lib/sdk/crt/math/labs.c Normal file
View file

@ -0,0 +1,13 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
#ifndef _MSC_VER
long
labs(long j)
{
return j<0 ? -j : j;
}
#endif

28
lib/sdk/crt/math/ldiv.c Normal file
View 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;
}

86
lib/sdk/crt/math/modf.c Normal file
View 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_t* x;
} x;
union
{
long double* __i;
long_double_t* 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;
}
}

View file

@ -0,0 +1,30 @@
/* 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 Library General Public License as
published by the Free Software Foundation; either version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <math.h>
/*
* @implemented
*/
long double powl (long double __x,long double __y)
{
return pow(__x,__y/2)*pow(__x,__y/2);
}

27
lib/sdk/crt/math/rand.c Normal file
View file

@ -0,0 +1,27 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.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;
}

View 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
View 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 */

19
lib/sdk/crt/math/sinh.c Normal file
View 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
View file

@ -0,0 +1,220 @@
#include <precomp.h>
#include <math.h>
double _CIsin(double x);
double _CIcos(double x);
double _CItan(double x);
double _CIsinh(double x);
double _CIcosh(double x);
double _CItanh(double x);
double _CIasin(double x);
double _CIacos(double x);
double _CIatan(double x);
double _CIatan2(double y, double x);
double _CIexp(double x);
double _CIlog(double x);
double _CIlog10(double x);
double _CIpow(double x, double y);
double _CIsqrt(double x);
double _CIfmod(double x, double y);
/*
* @implemented
*/
double _CIsin(double x)
{
return sin(x);
}
/*
* @implemented
*/
double _CIcos(double x)
{
return cos(x);
}
/*
* @implemented
*/
double _CItan(double x)
{
return tan(x);
}
/*
* @implemented
*/
double _CIsinh(double x)
{
return sinh(x);
}
/*
* @implemented
*/
double _CIcosh(double x)
{
return cosh(x);
}
/*
* @implemented
*/
double _CItanh(double x)
{
return tanh(x);
}
/*
* @implemented
*/
double _CIasin(double x)
{
return asin(x);
}
/*
* @implemented
*/
double _CIacos(double x)
{
return acos(x);
}
/*
* @implemented
*/
double _CIatan(double x)
{
return atan(x);
}
/*
* @implemented
*/
double _CIatan2(double y, double x)
{
return atan2(y, x);
}
/*
* @implemented
*/
double _CIexp(double x)
{
return exp(x);
}
/*
* @implemented
*/
double _CIlog(double x)
{
return log(x);
}
/*
* @implemented
*/
double _CIlog10(double x)
{
return log10(x);
}
/*
* @implemented
*/
double _CIpow(double x, double y)
{
return pow(x, y);
}
/*
* @implemented
*/
double _CIsqrt(double x)
{
return sqrt(x);
}
/*
* @implemented
*/
double _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
View 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);
}
}