From 62f41eac17f7c361e346c13a676ab2870494a4ef Mon Sep 17 00:00:00 2001 From: Rerumu Date: Sun, 26 Jun 2022 01:51:37 -0400 Subject: [PATCH] Fix `i32` bit shifting --- codegen/luau/runtime/runtime.lua | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/codegen/luau/runtime/runtime.lua b/codegen/luau/runtime/runtime.lua index a5b5a50..ce624d7 100644 --- a/codegen/luau/runtime/runtime.lua +++ b/codegen/luau/runtime/runtime.lua @@ -285,16 +285,34 @@ do local rotl = {} local rotr = {} - rotl.i32 = bit32.lrotate + local bit_arshift = bit32.arshift + local bit_lrotate = bit32.lrotate + local bit_rrotate = bit32.rrotate - rotr.i32 = bit32.rrotate + function rotl.i32(lhs, rhs) + return bit_lrotate(lhs, rhs % 32) + end + + function rotr.i32(lhs, rhs) + return bit_rrotate(lhs, rhs % 32) + end + + function shl.i32(lhs, rhs) + return bit_lshift(lhs, rhs % 32) + end - shl.i32 = bit_lshift shl.i64 = I64.shift_left - shr.i32 = bit32.arshift + function shr.i32(lhs, rhs) + return bit_arshift(lhs, rhs % 32) + end + shr.i64 = I64.shift_right_signed - shr.u32 = bit_rshift + + function shr.u32(lhs, rhs) + return bit_rshift(lhs, rhs % 32) + end + shr.u64 = I64.shift_right_unsigned module.shl = shl