ntdll: Reimplement _alldiv using 32-bit arithmetic.

Based on compiler-rt.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-06-08 18:12:21 +02:00 committed by Alexandre Julliard
parent 744843ed01
commit 8f144eb566
1 changed files with 6 additions and 1 deletions

View File

@ -736,7 +736,12 @@ static ULONGLONG udivmod(ULONGLONG a, ULONGLONG b, ULONGLONG *rem)
*/
LONGLONG WINAPI _alldiv( LONGLONG a, LONGLONG b )
{
return a / b;
LONGLONG s_a = a >> 63; /* s_a = a < 0 ? -1 : 0 */
LONGLONG s_b = b >> 63; /* s_b = b < 0 ? -1 : 0 */
a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
s_a ^= s_b; /* sign of quotient */
return (udivmod(a, b, NULL) ^ s_a) - s_a; /* negate if s_a == -1 */
}