Skip to content

Commit dc91af6

Browse files
authored
[simd] Correctly shift alignment_log2 (#1699)
The alignment value in binary format is log2, so we need to shift it in binary-reader-ir before it is validated (since validation requires that it is shifted to be the number of bytes). We correctly did that for some Simd instructions (like load splat) but did not do it for load/store lane. Fixes #1674.
1 parent a92466a commit dc91af6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/binary-reader-ir.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,15 +1086,15 @@ Result BinaryReaderIR::OnSimdLoadLaneExpr(Opcode opcode,
10861086
Address offset,
10871087
uint64_t value) {
10881088
return AppendExpr(
1089-
MakeUnique<SimdLoadLaneExpr>(opcode, alignment_log2, offset, value));
1089+
MakeUnique<SimdLoadLaneExpr>(opcode, 1 << alignment_log2, offset, value));
10901090
}
10911091

10921092
Result BinaryReaderIR::OnSimdStoreLaneExpr(Opcode opcode,
10931093
Address alignment_log2,
10941094
Address offset,
10951095
uint64_t value) {
10961096
return AppendExpr(
1097-
MakeUnique<SimdStoreLaneExpr>(opcode, alignment_log2, offset, value));
1097+
MakeUnique<SimdStoreLaneExpr>(opcode, 1 << alignment_log2, offset, value));
10981098
}
10991099

11001100
Result BinaryReaderIR::OnSimdShuffleOpExpr(Opcode opcode, v128 value) {

test/regress/regress-1674.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
;;; TOOL: wat2wasm
2+
;;; ARGS: --enable-simd
3+
(module
4+
(memory 1)
5+
(func
6+
i32.const 0
7+
v128.const i32x4 0 0 0 0
8+
v128.load32_lane align=1 0
9+
drop
10+
)
11+
)

0 commit comments

Comments
 (0)