From 66818a8566f8cb9ba5873daee13b6c71f111aeb2 Mon Sep 17 00:00:00 2001 From: Rerumu Date: Thu, 20 Jan 2022 04:44:18 -0500 Subject: [PATCH] Add small Luau optimizations --- wasm/runtime/luau.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wasm/runtime/luau.lua b/wasm/runtime/luau.lua index 094e63d..db4b9ee 100644 --- a/wasm/runtime/luau.lua +++ b/wasm/runtime/luau.lua @@ -1,13 +1,17 @@ local module = {} +local math_floor = math.floor +local math_ceil = math.ceil + local bit32 = bit32 +local bit_band = bit32.band local function no_op(x) return x end local function to_u32(x) - return bit32.band(x, 0xFFFFFFFF) + return bit_band(x, 0xFFFFFFFF) end local function to_i32(x) @@ -19,14 +23,14 @@ local function to_i32(x) end local function wrap_i32(x) - return to_i32(to_u32(x) % 0x100000000) + return to_i32(to_u32(x)) end local function truncate(num) if num >= 0 then - return math.floor(num) + return math_floor(num) else - return math.ceil(num) + return math_ceil(num) end end