ntdll: Correctly handle shift greater than the type width in 64-bit shift functions.

Based on a patch by Zhao Yi.
This commit is contained in:
Zebediah Figura 2022-07-03 20:27:12 -05:00 committed by Alexandre Julliard
parent 9ef7246243
commit bc270a5432
2 changed files with 17 additions and 8 deletions

View file

@ -817,7 +817,10 @@ LONGLONG __stdcall __regs__allshl( LONGLONG a, unsigned char b )
if (b >= 32)
{
ret.HighPart = x.LowPart << (b & 31);
if (b >= 64)
ret.HighPart = 0;
else
ret.HighPart = x.LowPart << (b & 31);
ret.LowPart = 0;
}
else
@ -847,7 +850,10 @@ LONGLONG __stdcall __regs__allshr( LONGLONG a, unsigned char b )
if (b >= 32)
{
ret.HighPart = x.HighPart >> 31;
ret.LowPart = x.HighPart >> (b & 31);
if (b >= 64)
ret.LowPart = x.HighPart >> 31;
else
ret.LowPart = x.HighPart >> (b & 31);
}
else
{
@ -876,7 +882,10 @@ ULONGLONG __stdcall __regs__aullshr( ULONGLONG a, unsigned char b )
if (b >= 32)
{
ret.HighPart = 0;
ret.LowPart = x.HighPart >> (b & 31);
if (b >= 64)
ret.LowPart = 0;
else
ret.LowPart = x.HighPart >> (b & 31);
}
else
{

View file

@ -526,10 +526,10 @@ static void test_builtins(void)
ok(l == 0xbcdef00000000000ll, "got %#I64x\n", l);
l = call_shift_func(p_allshl, 0x0123456789abcdefll, 88);
todo_wine ok(!l, "got %#I64x\n", l);
ok(!l, "got %#I64x\n", l);
l = call_shift_func(p_allshl, 0x0123456789abcdefll, 0x88);
todo_wine ok(!l, "got %#I64x\n", l);
ok(!l, "got %#I64x\n", l);
l = call_shift_func(p_allshl, 0x0123456789abcdefll, 0x108);
ok(l == 0x23456789abcdef00ll, "got %#I64x\n", l);
@ -541,7 +541,7 @@ static void test_builtins(void)
ok(l == 0x01234ll, "got %#I64x\n", l);
l = call_shift_func(p_allshr, 0x0123456789abcdefll, 88);
todo_wine ok(!l, "got %#I64x\n", l);
ok(!l, "got %#I64x\n", l);
l = call_shift_func(p_allshr, 0x8123456789abcdefll, 12);
ok(l == 0xfff8123456789abcll, "got %#I64x\n", l);
@ -550,7 +550,7 @@ static void test_builtins(void)
ok(l == 0xfffffffffff81234ll, "got %#I64x\n", l);
l = call_shift_func(p_allshr, 0x8123456789abcdefll, 88);
todo_wine ok(l == -1ll, "got %#I64x\n", l);
ok(l == -1ll, "got %#I64x\n", l);
l = call_shift_func(p_allshr, 0x8123456789abcdefll, 0x108);
ok(l == 0xff8123456789abcdll, "got %#I64x\n", l);
@ -562,7 +562,7 @@ static void test_builtins(void)
ok(l == 0x81234ll, "got %#I64x\n", l);
l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 88);
todo_wine ok(!l, "got %#I64x\n", l);
ok(!l, "got %#I64x\n", l);
l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 0x108);
ok(l == 0x8123456789abcdll, "got %#I64x\n", l);