diff --git a/codegen/luajit/runtime/runtime.lua b/codegen/luajit/runtime/runtime.lua index d6d1af0..39e963a 100644 --- a/codegen/luajit/runtime/runtime.lua +++ b/codegen/luajit/runtime/runtime.lua @@ -11,10 +11,10 @@ local math_ceil = math.ceil local math_floor = math.floor local to_number = tonumber -local ID_ZERO = i64(0) -local ID_ONE = i64(1) +local NUM_ZERO = i64(0) +local NUM_ONE = i64(1) -local function truncate(num) +local function truncate_f64(num) if num >= 0 then return (math_floor(num)) else @@ -62,13 +62,13 @@ do end function mul.i32(lhs, rhs) - return (to_signed(ID_ONE * lhs * rhs)) + return (to_signed(NUM_ONE * lhs * rhs)) end function div.i32(lhs, rhs) assert(rhs ~= 0, "division by zero") - return (truncate(lhs / rhs)) + return (truncate_f64(lhs / rhs)) end function div.u32(lhs, rhs) @@ -257,38 +257,38 @@ do function clz.i64(num) if num == 0 then - return 64 * ID_ONE + return 64 * NUM_ONE end - local count = ID_ZERO + local count = NUM_ZERO - if bit_rshift(num, 32) == ID_ZERO then + if bit_rshift(num, 32) == NUM_ZERO then num = bit_lshift(num, 32) count = count + 32 end - if bit_rshift(num, 48) == ID_ZERO then + if bit_rshift(num, 48) == NUM_ZERO then num = bit_lshift(num, 16) count = count + 16 end - if bit_rshift(num, 56) == ID_ZERO then + if bit_rshift(num, 56) == NUM_ZERO then num = bit_lshift(num, 8) count = count + 8 end - if bit_rshift(num, 60) == ID_ZERO then + if bit_rshift(num, 60) == NUM_ZERO then num = bit_lshift(num, 4) count = count + 4 end - if bit_rshift(num, 62) == ID_ZERO then + if bit_rshift(num, 62) == NUM_ZERO then num = bit_lshift(num, 2) count = count + 2 end - if bit_rshift(num, 63) == ID_ZERO then - count = count + ID_ONE + if bit_rshift(num, 63) == NUM_ZERO then + count = count + NUM_ONE end return count @@ -296,49 +296,49 @@ do function ctz.i64(num) if num == 0 then - return 64 * ID_ONE + return 64 * NUM_ONE end - local count = ID_ZERO + local count = NUM_ZERO - if bit_lshift(num, 32) == ID_ZERO then + if bit_lshift(num, 32) == NUM_ZERO then num = bit_rshift(num, 32) count = count + 32 end - if bit_lshift(num, 48) == ID_ZERO then + if bit_lshift(num, 48) == NUM_ZERO then num = bit_rshift(num, 16) count = count + 16 end - if bit_lshift(num, 56) == ID_ZERO then + if bit_lshift(num, 56) == NUM_ZERO then num = bit_rshift(num, 8) count = count + 8 end - if bit_lshift(num, 60) == ID_ZERO then + if bit_lshift(num, 60) == NUM_ZERO then num = bit_rshift(num, 4) count = count + 4 end - if bit_lshift(num, 62) == ID_ZERO then + if bit_lshift(num, 62) == NUM_ZERO then num = bit_rshift(num, 2) count = count + 2 end - if bit_lshift(num, 63) == ID_ZERO then - count = count + ID_ONE + if bit_lshift(num, 63) == NUM_ZERO then + count = count + NUM_ONE end return count end function popcnt.i64(num) - local count = ID_ZERO + local count = NUM_ZERO - while num ~= ID_ZERO do - num = bit_and(num, num - ID_ONE) - count = count + ID_ONE + while num ~= NUM_ZERO do + num = bit_and(num, num - NUM_ONE) + count = count + NUM_ONE end return count @@ -395,7 +395,7 @@ end do local wrap = {} - local trunc = {} + local truncate = {} local extend = {} local convert = {} local promote = {} @@ -419,14 +419,14 @@ do return RE_INSTANCE.i32 end - trunc.i32_f32 = truncate - trunc.i32_f64 = truncate - trunc.i64_f32 = i64 - trunc.i64_f64 = i64 - trunc.u64_f32 = i64 - trunc.u64_f64 = i64 - trunc.f32 = truncate - trunc.f64 = truncate + truncate.i32_f32 = truncate_f64 + truncate.i32_f64 = truncate_f64 + truncate.i64_f32 = i64 + truncate.i64_f64 = i64 + truncate.u64_f32 = i64 + truncate.u64_f64 = i64 + truncate.f32 = truncate_f64 + truncate.f64 = truncate_f64 function extend.i32_n8(num) num = bit_and(num, 0xFF) @@ -481,7 +481,7 @@ do extend.i64_i32 = i64 function extend.i64_u32(num) - RE_INSTANCE.i64 = ID_ZERO + RE_INSTANCE.i64 = NUM_ZERO RE_INSTANCE.i32 = num return RE_INSTANCE.i64 @@ -544,7 +544,7 @@ do end module.wrap = wrap - module.trunc = trunc + module.truncate = truncate module.extend = extend module.convert = convert module.demote = demote diff --git a/codegen/luajit/src/translator.rs b/codegen/luajit/src/translator.rs index b5fbcba..343770f 100644 --- a/codegen/luajit/src/translator.rs +++ b/codegen/luajit/src/translator.rs @@ -227,7 +227,6 @@ fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<() ("shr", "u32" | "u64") => write!(w, "bit.rshift "), ("rotl", _) => write!(w, "bit.rol "), ("rotr", _) => write!(w, "bit.ror "), - ("trunc", "u32_f32" | "u32_f64") => write!(w, "math.floor "), ("convert", "f32_i64" | "f64_i64") => write!(w, "tonumber "), _ => write!(w, "rt.{head}.{tail} "), } diff --git a/codegen/luau/runtime/runtime.lua b/codegen/luau/runtime/runtime.lua index 91c9cc5..5992716 100644 --- a/codegen/luau/runtime/runtime.lua +++ b/codegen/luau/runtime/runtime.lua @@ -363,7 +363,7 @@ end do local wrap = {} - local trunc = {} + local truncate = {} local extend = {} local convert = {} local demote = {} @@ -388,12 +388,12 @@ do return data_1 end - trunc.i32_f32 = to_u32 - trunc.i32_f64 = to_u32 - trunc.u32_f32 = no_op - trunc.u32_f64 = no_op + truncate.i32_f32 = to_u32 + truncate.i32_f64 = to_u32 + truncate.u32_f32 = no_op + truncate.u32_f64 = no_op - function trunc.i64_f32(num) + function truncate.i64_f32(num) if num < 0 then local temp = num_from_u64(-math_ceil(num)) @@ -405,7 +405,7 @@ do end end - function trunc.i64_f64(num) + function truncate.i64_f64(num) if num < 0 then local temp = num_from_u64(-math_ceil(num)) @@ -417,10 +417,10 @@ do end end - trunc.u64_f32 = num_from_u64 - trunc.u64_f64 = num_from_u64 + truncate.u64_f32 = num_from_u64 + truncate.u64_f64 = num_from_u64 - function trunc.f32(num) + function truncate.f32(num) if num >= 0 then return math_floor(num) else @@ -428,7 +428,7 @@ do end end - trunc.f64 = trunc.f32 + truncate.f64 = truncate.f32 function extend.i32_n8(num) num = bit_and(num, 0xFF) @@ -564,7 +564,7 @@ do end module.wrap = wrap - module.trunc = trunc + module.truncate = truncate module.extend = extend module.convert = convert module.demote = demote @@ -856,7 +856,7 @@ do store_i64(memory, addr, reinterpret_i64_f64(value)) end - function store.string(memory, offset, data, len) + function store.string(memory, addr, data, len) len = len or #data local rem = len % 4 @@ -864,13 +864,13 @@ do for i = 1, len - rem, 4 do local v = string_unpack(" ("neg", "f32"), Self::Ceil_F32 => ("ceil", "f32"), Self::Floor_F32 => ("floor", "f32"), - Self::Trunc_F32 => ("trunc", "f32"), + Self::Truncate_F32 => ("truncate", "f32"), Self::Nearest_F32 => ("nearest", "f32"), Self::Sqrt_F32 => ("sqrt", "f32"), Self::Abs_F64 => ("abs", "f64"), Self::Neg_F64 => ("neg", "f64"), Self::Ceil_F64 => ("ceil", "f64"), Self::Floor_F64 => ("floor", "f64"), - Self::Trunc_F64 => ("trunc", "f64"), + Self::Truncate_F64 => ("truncate", "f64"), Self::Nearest_F64 => ("nearest", "f64"), Self::Sqrt_F64 => ("sqrt", "f64"), Self::Wrap_I32_I64 => ("wrap", "i32_i64"), - Self::Trunc_I32_F32 => ("trunc", "i32_f32"), - Self::Trunc_U32_F32 => ("trunc", "u32_f32"), - Self::Trunc_I32_F64 => ("trunc", "i32_f64"), - Self::Trunc_U32_F64 => ("trunc", "u32_f64"), + Self::Truncate_I32_F32 => ("truncate", "i32_f32"), + Self::Truncate_I32_F64 => ("truncate", "i32_f64"), + Self::Truncate_U32_F32 => ("truncate", "u32_f32"), + Self::Truncate_U32_F64 => ("truncate", "u32_f64"), + Self::Truncate_I64_F32 => ("truncate", "i64_f32"), + Self::Truncate_I64_F64 => ("truncate", "i64_f64"), + Self::Truncate_U64_F32 => ("truncate", "u64_f32"), + Self::Truncate_U64_F64 => ("truncate", "u64_f64"), Self::Extend_I32_N8 => ("extend", "i32_n8"), Self::Extend_I32_N16 => ("extend", "i32_n16"), Self::Extend_I64_N8 => ("extend", "i64_n8"), @@ -214,10 +218,6 @@ impl UnOpType { Self::Extend_I64_N32 => ("extend", "i64_n32"), Self::Extend_I64_I32 => ("extend", "i64_i32"), Self::Extend_I64_U32 => ("extend", "i64_u32"), - Self::Trunc_I64_F32 => ("trunc", "i64_f32"), - Self::Trunc_U64_F32 => ("trunc", "u64_f32"), - Self::Trunc_I64_F64 => ("trunc", "i64_f64"), - Self::Trunc_U64_F64 => ("trunc", "u64_f64"), Self::Convert_F32_I32 => ("convert", "f32_i32"), Self::Convert_F32_U32 => ("convert", "f32_u32"), Self::Convert_F32_I64 => ("convert", "f32_i64"), @@ -251,21 +251,25 @@ impl TryFrom<&Operator<'_>> for UnOpType { Operator::F32Neg => Self::Neg_F32, Operator::F32Ceil => Self::Ceil_F32, Operator::F32Floor => Self::Floor_F32, - Operator::F32Trunc => Self::Trunc_F32, + Operator::F32Trunc => Self::Truncate_F32, Operator::F32Nearest => Self::Nearest_F32, Operator::F32Sqrt => Self::Sqrt_F32, Operator::F64Abs => Self::Abs_F64, Operator::F64Neg => Self::Neg_F64, Operator::F64Ceil => Self::Ceil_F64, Operator::F64Floor => Self::Floor_F64, - Operator::F64Trunc => Self::Trunc_F64, + Operator::F64Trunc => Self::Truncate_F64, Operator::F64Nearest => Self::Nearest_F64, Operator::F64Sqrt => Self::Sqrt_F64, Operator::I32WrapI64 => Self::Wrap_I32_I64, - Operator::I32TruncF32S => Self::Trunc_I32_F32, - Operator::I32TruncF32U => Self::Trunc_U32_F32, - Operator::I32TruncF64S => Self::Trunc_I32_F64, - Operator::I32TruncF64U => Self::Trunc_U32_F64, + Operator::I32TruncF32S => Self::Truncate_I32_F32, + Operator::I32TruncF64S => Self::Truncate_I32_F64, + Operator::I32TruncF32U => Self::Truncate_U32_F32, + Operator::I32TruncF64U => Self::Truncate_U32_F64, + Operator::I64TruncF32S => Self::Truncate_I64_F32, + Operator::I64TruncF64S => Self::Truncate_I64_F64, + Operator::I64TruncF32U => Self::Truncate_U64_F32, + Operator::I64TruncF64U => Self::Truncate_U64_F64, Operator::I32Extend8S => Self::Extend_I32_N8, Operator::I32Extend16S => Self::Extend_I32_N16, Operator::I64Extend8S => Self::Extend_I64_N8, @@ -273,10 +277,6 @@ impl TryFrom<&Operator<'_>> for UnOpType { Operator::I64Extend32S => Self::Extend_I64_N32, Operator::I64ExtendI32S => Self::Extend_I64_I32, Operator::I64ExtendI32U => Self::Extend_I64_U32, - Operator::I64TruncF32S => Self::Trunc_I64_F32, - Operator::I64TruncF32U => Self::Trunc_U64_F32, - Operator::I64TruncF64S => Self::Trunc_I64_F64, - Operator::I64TruncF64U => Self::Trunc_U64_F64, Operator::F32ConvertI32S => Self::Convert_F32_I32, Operator::F32ConvertI32U => Self::Convert_F32_U32, Operator::F32ConvertI64S => Self::Convert_F32_I64,