wasm_module, wasm_interp: fix SLEB-128 encoding for i64

This commit is contained in:
Brian Carroll 2022-11-28 17:39:13 +00:00
parent 0dc3441301
commit 9ea2176db8
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
2 changed files with 2 additions and 5 deletions

View file

@ -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);

View file

@ -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(())
} }