Fix inconsistencies
Addendum to truncation rename Rename constants for consistency
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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} "),
|
||||
}
|
||||
|
||||
@@ -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("<I4", data, i)
|
||||
|
||||
store_i32(memory, offset + i - 1, v)
|
||||
store_i32(memory, addr + i - 1, v)
|
||||
end
|
||||
|
||||
for i = len - rem + 1, len do
|
||||
local v = string_byte(data, i)
|
||||
|
||||
store_i8(memory, offset + i - 1, v)
|
||||
store_i8(memory, addr + i - 1, v)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user