mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
wasm_module, wasm_interp: fix SLEB-128 encoding for i64
This commit is contained in:
parent
0dc3441301
commit
9ea2176db8
2 changed files with 2 additions and 5 deletions
|
@ -276,21 +276,18 @@ fn test_i64shl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore] // TODO: i64.const is encoding the wrong LEB bytes
|
|
||||||
fn test_i64shrs() {
|
fn test_i64shrs() {
|
||||||
test_u64_binop(I64SHRS, 0xffff_ffff_0000_0000, 8, 0xffff_ffff_ff00_0000);
|
test_u64_binop(I64SHRS, 0xffff_ffff_0000_0000, 8, 0xffff_ffff_ff00_0000);
|
||||||
test_u64_binop(I64SHRS, 0xffff_ffff_0000_0000, 72, 0xffff_ffff_ff00_0000);
|
test_u64_binop(I64SHRS, 0xffff_ffff_0000_0000, 72, 0xffff_ffff_ff00_0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore] // TODO: i64.const is encoding the wrong LEB bytes
|
|
||||||
fn test_i64shru() {
|
fn test_i64shru() {
|
||||||
test_u64_binop(I64SHRU, 0xffff_ffff_0000_0000, 8, 0x00ff_ffff_ff00_0000);
|
test_u64_binop(I64SHRU, 0xffff_ffff_0000_0000, 8, 0x00ff_ffff_ff00_0000);
|
||||||
test_u64_binop(I64SHRU, 0xffff_ffff_0000_0000, 72, 0x00ff_ffff_ff00_0000);
|
test_u64_binop(I64SHRU, 0xffff_ffff_0000_0000, 72, 0x00ff_ffff_ff00_0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore] // TODO: i64.const is encoding the wrong LEB bytes
|
|
||||||
fn test_i64rotl() {
|
fn test_i64rotl() {
|
||||||
test_u64_binop(I64ROTL, 0xff00_0000_0000_0000, 4, 0xf000_0000_0000_000f);
|
test_u64_binop(I64ROTL, 0xff00_0000_0000_0000, 4, 0xf000_0000_0000_000f);
|
||||||
test_u64_binop(I64ROTL, 0xff00_0000_0000_0000, 68, 0xf000_0000_0000_000f);
|
test_u64_binop(I64ROTL, 0xff00_0000_0000_0000, 68, 0xf000_0000_0000_000f);
|
||||||
|
|
|
@ -99,14 +99,14 @@ fn decode_i64(bytes: &[u8]) -> Result<(i64, usize), ()> {
|
||||||
let mut shift = 0;
|
let mut shift = 0;
|
||||||
for (i, byte) in bytes.iter().take(MAX_SIZE_ENCODED_U64).enumerate() {
|
for (i, byte) in bytes.iter().take(MAX_SIZE_ENCODED_U64).enumerate() {
|
||||||
value |= ((byte & 0x7f) as i64) << shift;
|
value |= ((byte & 0x7f) as i64) << shift;
|
||||||
|
shift += 7;
|
||||||
if (byte & 0x80) == 0 {
|
if (byte & 0x80) == 0 {
|
||||||
let is_negative = byte & 0x40 != 0;
|
let is_negative = byte & 0x40 != 0;
|
||||||
if shift < MAX_SIZE_ENCODED_U64 && is_negative {
|
if shift < 64 && is_negative {
|
||||||
value |= -1 << shift;
|
value |= -1 << shift;
|
||||||
}
|
}
|
||||||
return Ok((value, i + 1));
|
return Ok((value, i + 1));
|
||||||
}
|
}
|
||||||
shift += 7;
|
|
||||||
}
|
}
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue