From f1e2c6cbd0577a20f5938af67cb5f49b4dde380a Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 24 Jul 2021 11:41:06 +0200 Subject: [PATCH] [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) --- sdk/lib/crt/math/arm/__rt_div.c | 126 ------------------------- sdk/lib/crt/math/arm/__rt_div_worker.h | 24 +++-- sdk/lib/crt/math/arm/__rt_sdiv.c | 18 ++-- sdk/lib/crt/math/arm/__rt_sdiv64.s | 15 ++- sdk/lib/crt/math/arm/__rt_udiv.c | 15 +-- sdk/lib/crt/math/arm/__rt_udiv64.s | 15 ++- 6 files changed, 55 insertions(+), 158 deletions(-) delete mode 100644 sdk/lib/crt/math/arm/__rt_div.c diff --git a/sdk/lib/crt/math/arm/__rt_div.c b/sdk/lib/crt/math/arm/__rt_div.c deleted file mode 100644 index c59a701fecf..00000000000 --- a/sdk/lib/crt/math/arm/__rt_div.c +++ /dev/null @@ -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; -} diff --git a/sdk/lib/crt/math/arm/__rt_div_worker.h b/sdk/lib/crt/math/arm/__rt_div_worker.h index 035b3abd045..2b658415a3f 100644 --- a/sdk/lib/crt/math/arm/__rt_div_worker.h +++ b/sdk/lib/crt/math/arm/__rt_div_worker.h @@ -1,12 +1,20 @@ /* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * FILE: lib/sdk/crt/math/arm/__rt_div_worker.h - * PURPOSE: Implementation of __rt_udiv - * PROGRAMMER: Timo Kreuzer - * 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 + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __rt_div_worker + * COPYRIGHT: Copyright 2015 Timo Kreuzer + * Copyright 2021 Raman Masanin <36927roma@gmail.com> + */ + +/* + * 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_ diff --git a/sdk/lib/crt/math/arm/__rt_sdiv.c b/sdk/lib/crt/math/arm/__rt_sdiv.c index 302cec422a4..96e0eafe334 100644 --- a/sdk/lib/crt/math/arm/__rt_sdiv.c +++ b/sdk/lib/crt/math/arm/__rt_sdiv.c @@ -1,11 +1,9 @@ /* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * FILE: lib/sdk/crt/math/arm/__rt_sdiv.c - * PURPOSE: Implementation of __rt_sdiv - * 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 + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __rt_sdiv + * COPYRIGHT: Copyright 2015 Timo Kreuzer + * Copyright 2021 Raman Masanin <36927roma@gmail.com> */ #define __rt_div_worker __rt_sdiv_worker @@ -13,7 +11,10 @@ #include "__rt_div_worker.h" -unsigned long long +/* + * Returns quotient in R0, remainder in R1 + */ +long long __rt_sdiv( int divisor, int dividend) @@ -24,4 +25,3 @@ __rt_sdiv( return result.raw_data; } - diff --git a/sdk/lib/crt/math/arm/__rt_sdiv64.s b/sdk/lib/crt/math/arm/__rt_sdiv64.s index d3515a79729..57f21edcaef 100644 --- a/sdk/lib/crt/math/arm/__rt_sdiv64.s +++ b/sdk/lib/crt/math/arm/__rt_sdiv64.s @@ -1,8 +1,9 @@ /* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * PURPOSE: Implementation of __rt_sdiv64 - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __rt_sdiv64 + * COPYRIGHT: Copyright 2015 Timo Kreuzer + * Copyright 2021 Raman Masanin <36927roma@gmail.com> */ /* INCLUDES ******************************************************************/ @@ -15,6 +16,12 @@ TEXTAREA + /* + IN: r1:r0 = divisor + IN: r3:r2 = dividend + OUT: r1:r0 = quotient + OUT: r3:r2 = remainder + */ NESTED_ENTRY __rt_sdiv64 /* Allocate stack space and store parameters there */ diff --git a/sdk/lib/crt/math/arm/__rt_udiv.c b/sdk/lib/crt/math/arm/__rt_udiv.c index 2f47697d8ff..9863ce4d83d 100644 --- a/sdk/lib/crt/math/arm/__rt_udiv.c +++ b/sdk/lib/crt/math/arm/__rt_udiv.c @@ -1,16 +1,18 @@ /* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * 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 + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __rt_udiv + * COPYRIGHT: Copyright 2015 Timo Kreuzer + * Copyright 2021 Raman Masanin <36927roma@gmail.com> */ #define __rt_div_worker __rt_udiv_worker #include "__rt_div_worker.h" + /* + * Returns quotient in R0, remainder in R1 + */ unsigned long long __rt_udiv( unsigned int divisor, @@ -22,4 +24,3 @@ __rt_udiv( return result.raw_data; } - diff --git a/sdk/lib/crt/math/arm/__rt_udiv64.s b/sdk/lib/crt/math/arm/__rt_udiv64.s index d08a02fc463..182ff33595a 100644 --- a/sdk/lib/crt/math/arm/__rt_udiv64.s +++ b/sdk/lib/crt/math/arm/__rt_udiv64.s @@ -1,8 +1,9 @@ /* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * PURPOSE: Implementation of __rt_udiv64 - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __rt_udiv64 + * COPYRIGHT: Copyright 2015 Timo Kreuzer + * Copyright 2021 Raman Masanin <36927roma@gmail.com> */ /* INCLUDES ******************************************************************/ @@ -15,6 +16,12 @@ TEXTAREA + /* + IN: r1:r0 = divisor + IN: r3:r2 = dividend + OUT: r1:r0 = quotient + OUT: r3:r2 = remainder + */ NESTED_ENTRY __rt_udiv64 /* Allocate stack space and store parameters there */