mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
[CRT/arm] Update file headers to new format and change license to MIT
* Add Raman Masanin to copyrights * Add some comments * Return long long from __rt_sdiv (no functional difference, just for clarity)
This commit is contained in:
parent
9a42267b06
commit
f1e2c6cbd0
6 changed files with 55 additions and 158 deletions
|
@ -1,126 +0,0 @@
|
||||||
/*
|
|
||||||
* COPYRIGHT: BSD - See COPYING.ARM in the top level directory
|
|
||||||
* PROJECT: ReactOS CRT library
|
|
||||||
* FILE: lib/sdk/crt/math/arm/__rt_div.c
|
|
||||||
* PURPOSE: Implementation of __rt_udiv
|
|
||||||
* PROGRAMMER: Timo Kreuzer
|
|
||||||
* REFERENCE: http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_div10.s.htm
|
|
||||||
* http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_udiv.c.htm
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct _ARM_UDIVRESULT
|
|
||||||
{
|
|
||||||
unsigned int quotient; /* to be returned in R0 */
|
|
||||||
unsigned int modulus; /* to be returned in R1 */
|
|
||||||
} ARM_UDIVRESULT;
|
|
||||||
|
|
||||||
__forceinline
|
|
||||||
void
|
|
||||||
__brkdiv0(void)
|
|
||||||
{
|
|
||||||
__emit(0xDEF9);
|
|
||||||
}
|
|
||||||
|
|
||||||
__forceinline
|
|
||||||
void
|
|
||||||
__rt_udiv_internal(
|
|
||||||
ARM_UDIVRESULT *result,
|
|
||||||
unsigned int divisor,
|
|
||||||
unsigned int dividend)
|
|
||||||
{
|
|
||||||
unsigned int shift;
|
|
||||||
unsigned int mask;
|
|
||||||
unsigned int quotient;
|
|
||||||
|
|
||||||
if (divisor == 0)
|
|
||||||
{
|
|
||||||
/* Raise divide by zero error */
|
|
||||||
__brkdiv0();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (divisor > dividend)
|
|
||||||
{
|
|
||||||
result->quotient = 0;
|
|
||||||
result->modulus = divisor;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the difference in count of leading zeros between dividend and divisor */
|
|
||||||
shift = _CountLeadingZeros(divisor);
|
|
||||||
shift -= _CountLeadingZeros(dividend);
|
|
||||||
|
|
||||||
/* Shift the divisor to the left, so that it's highest bit is the same
|
|
||||||
as the highest bit of the dividend */
|
|
||||||
divisor <<= shift;
|
|
||||||
|
|
||||||
mask = 1 << shift;
|
|
||||||
|
|
||||||
quotient = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (dividend >= divisor)
|
|
||||||
{
|
|
||||||
quotient |= mask;
|
|
||||||
dividend -= divisor;
|
|
||||||
}
|
|
||||||
divisor >>= 1;
|
|
||||||
mask >>= 1;
|
|
||||||
}
|
|
||||||
while (mask);
|
|
||||||
|
|
||||||
result->quotient = quotient;
|
|
||||||
result->modulus = dividend;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ARM_UDIVRESULT
|
|
||||||
__rt_udiv(
|
|
||||||
unsigned int divisor,
|
|
||||||
unsigned int dividend)
|
|
||||||
{
|
|
||||||
ARM_UDIVRESULT result;
|
|
||||||
|
|
||||||
__rt_udiv_internal(&result, divisor, dividend);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct _ARM_SDIVRESULT
|
|
||||||
{
|
|
||||||
int quotient; /* to be returned in R0 */
|
|
||||||
int modulus; /* to be returned in R1 */
|
|
||||||
} ARM_SDIVRESULT;
|
|
||||||
|
|
||||||
ARM_SDIVRESULT
|
|
||||||
__rt_sdiv(
|
|
||||||
int divisor,
|
|
||||||
int dividend)
|
|
||||||
{
|
|
||||||
ARM_SDIVRESULT result;
|
|
||||||
int divisor_sign, dividend_sign;
|
|
||||||
|
|
||||||
dividend_sign = divisor & 0x80000000;
|
|
||||||
if (dividend_sign)
|
|
||||||
{
|
|
||||||
dividend = -dividend;
|
|
||||||
}
|
|
||||||
|
|
||||||
divisor_sign = divisor & 0x80000000;
|
|
||||||
if (divisor_sign)
|
|
||||||
{
|
|
||||||
divisor = -divisor;
|
|
||||||
}
|
|
||||||
|
|
||||||
__rt_udiv_internal((ARM_UDIVRESULT*)&result, divisor, dividend);
|
|
||||||
|
|
||||||
if (dividend_sign ^ divisor_sign)
|
|
||||||
{
|
|
||||||
result.quotient = -result.quotient;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dividend_sign)
|
|
||||||
{
|
|
||||||
result.modulus = -result.modulus;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
|
@ -1,12 +1,20 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: BSD - See COPYING.ARM in the top level directory
|
* PROJECT: ReactOS CRT library
|
||||||
* PROJECT: ReactOS CRT library
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||||
* FILE: lib/sdk/crt/math/arm/__rt_div_worker.h
|
* PURPOSE: Implementation of __rt_div_worker
|
||||||
* PURPOSE: Implementation of __rt_udiv
|
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||||
* PROGRAMMER: Timo Kreuzer
|
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||||
* REFERENCE: http://research.microsoft.com/pubs/70645/tr-2008-141.pdf
|
*/
|
||||||
* http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_div10.s.htm
|
|
||||||
* http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_udiv.c.htm
|
/*
|
||||||
|
* See also:
|
||||||
|
* http://research.microsoft.com/pubs/70645/tr-2008-141.pdf
|
||||||
|
* https://web.archive.org/web/20100110044008/http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_div10.s.htm
|
||||||
|
* https://github.com/bawoodruff/BeagleBoard/blob/2731e3174af6daefe4a287a6be82e5ff9c46c99a/OS/BootLoader/Runtime/_udiv.c
|
||||||
|
* https://github.com/bawoodruff/BeagleBoard/blob/2731e3174af6daefe4a287a6be82e5ff9c46c99a/OS/BootLoader/Runtime/arm/_udivsi3.s
|
||||||
|
* https://github.com/bawoodruff/BeagleBoard/blob/2731e3174af6daefe4a287a6be82e5ff9c46c99a/OS/BootLoader/Runtime/arm/divide.s
|
||||||
|
* https://github.com/qemu/edk2/blob/e3c7db50cac9125607df49d5873991df6df11eae/ArmPkg/Library/CompilerIntrinsicsLib/Arm/uldiv.asm
|
||||||
|
* https://github.com/jmonesti/qemu-4.1.1/blob/55fb6a81039a62174c2763759324c43a67d752a1/roms/ipxe/src/arch/arm32/libgcc/lldivmod.S
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _USE_64_BITS_
|
#ifdef _USE_64_BITS_
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: BSD - See COPYING.ARM in the top level directory
|
* PROJECT: ReactOS CRT library
|
||||||
* PROJECT: ReactOS CRT library
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||||
* FILE: lib/sdk/crt/math/arm/__rt_sdiv.c
|
* PURPOSE: Implementation of __rt_sdiv
|
||||||
* PURPOSE: Implementation of __rt_sdiv
|
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||||
* PROGRAMMER: Timo Kreuzer
|
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||||
* REFERENCE: http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_div10.s.htm
|
|
||||||
* http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_udiv.c.htm
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define __rt_div_worker __rt_sdiv_worker
|
#define __rt_div_worker __rt_sdiv_worker
|
||||||
|
@ -13,7 +11,10 @@
|
||||||
|
|
||||||
#include "__rt_div_worker.h"
|
#include "__rt_div_worker.h"
|
||||||
|
|
||||||
unsigned long long
|
/*
|
||||||
|
* Returns quotient in R0, remainder in R1
|
||||||
|
*/
|
||||||
|
long long
|
||||||
__rt_sdiv(
|
__rt_sdiv(
|
||||||
int divisor,
|
int divisor,
|
||||||
int dividend)
|
int dividend)
|
||||||
|
@ -24,4 +25,3 @@ __rt_sdiv(
|
||||||
|
|
||||||
return result.raw_data;
|
return result.raw_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: BSD - See COPYING.ARM in the top level directory
|
* PROJECT: ReactOS CRT library
|
||||||
* PROJECT: ReactOS CRT library
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||||
* PURPOSE: Implementation of __rt_sdiv64
|
* PURPOSE: Implementation of __rt_sdiv64
|
||||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||||
|
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES ******************************************************************/
|
/* INCLUDES ******************************************************************/
|
||||||
|
@ -15,6 +16,12 @@
|
||||||
|
|
||||||
TEXTAREA
|
TEXTAREA
|
||||||
|
|
||||||
|
/*
|
||||||
|
IN: r1:r0 = divisor
|
||||||
|
IN: r3:r2 = dividend
|
||||||
|
OUT: r1:r0 = quotient
|
||||||
|
OUT: r3:r2 = remainder
|
||||||
|
*/
|
||||||
NESTED_ENTRY __rt_sdiv64
|
NESTED_ENTRY __rt_sdiv64
|
||||||
|
|
||||||
/* Allocate stack space and store parameters there */
|
/* Allocate stack space and store parameters there */
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: BSD - See COPYING.ARM in the top level directory
|
* PROJECT: ReactOS CRT library
|
||||||
* PROJECT: ReactOS CRT library
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||||
* PURPOSE: Implementation of __rt_udiv
|
* PURPOSE: Implementation of __rt_udiv
|
||||||
* PROGRAMMER: Timo Kreuzer
|
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||||
* REFERENCE: http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_div10.s.htm
|
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||||
* http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/arm/_udiv.c.htm
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define __rt_div_worker __rt_udiv_worker
|
#define __rt_div_worker __rt_udiv_worker
|
||||||
|
|
||||||
#include "__rt_div_worker.h"
|
#include "__rt_div_worker.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns quotient in R0, remainder in R1
|
||||||
|
*/
|
||||||
unsigned long long
|
unsigned long long
|
||||||
__rt_udiv(
|
__rt_udiv(
|
||||||
unsigned int divisor,
|
unsigned int divisor,
|
||||||
|
@ -22,4 +24,3 @@ __rt_udiv(
|
||||||
|
|
||||||
return result.raw_data;
|
return result.raw_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: BSD - See COPYING.ARM in the top level directory
|
* PROJECT: ReactOS CRT library
|
||||||
* PROJECT: ReactOS CRT library
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||||
* PURPOSE: Implementation of __rt_udiv64
|
* PURPOSE: Implementation of __rt_udiv64
|
||||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||||
|
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES ******************************************************************/
|
/* INCLUDES ******************************************************************/
|
||||||
|
@ -15,6 +16,12 @@
|
||||||
|
|
||||||
TEXTAREA
|
TEXTAREA
|
||||||
|
|
||||||
|
/*
|
||||||
|
IN: r1:r0 = divisor
|
||||||
|
IN: r3:r2 = dividend
|
||||||
|
OUT: r1:r0 = quotient
|
||||||
|
OUT: r3:r2 = remainder
|
||||||
|
*/
|
||||||
NESTED_ENTRY __rt_udiv64
|
NESTED_ENTRY __rt_udiv64
|
||||||
|
|
||||||
/* Allocate stack space and store parameters there */
|
/* Allocate stack space and store parameters there */
|
||||||
|
|
Loading…
Reference in a new issue