Skip to content

Commit 07e4d28

Browse files
committed
Translate Wasm narrow instructions to CLIF's snarrow and unarrow
In order to make it more clear what the incoming types are for this translation (e.g. two `I32X4`s narrow to an `I16X8`), this change explicitly sets the type to which to bitcast (if necessary) the incoming values.
1 parent 31237d6 commit 07e4d28

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

cranelift/wasm/src/code_translator.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,11 +1559,23 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
15591559
let a = pop1_with_bitcast(state, F32X4, builder);
15601560
state.push1(builder.ins().fcvt_to_sint_sat(I32X4, a))
15611561
}
1562+
Operator::I8x16NarrowI16x8S => {
1563+
let (a, b) = pop2_with_bitcast(state, I16X8, builder);
1564+
state.push1(builder.ins().snarrow(a, b))
1565+
}
1566+
Operator::I16x8NarrowI32x4S => {
1567+
let (a, b) = pop2_with_bitcast(state, I32X4, builder);
1568+
state.push1(builder.ins().snarrow(a, b))
1569+
}
1570+
Operator::I8x16NarrowI16x8U => {
1571+
let (a, b) = pop2_with_bitcast(state, I16X8, builder);
1572+
state.push1(builder.ins().unarrow(a, b))
1573+
}
1574+
Operator::I16x8NarrowI32x4U => {
1575+
let (a, b) = pop2_with_bitcast(state, I32X4, builder);
1576+
state.push1(builder.ins().unarrow(a, b))
1577+
}
15621578
Operator::I32x4TruncSatF32x4U
1563-
| Operator::I8x16NarrowI16x8S { .. }
1564-
| Operator::I8x16NarrowI16x8U { .. }
1565-
| Operator::I16x8NarrowI32x4S { .. }
1566-
| Operator::I16x8NarrowI32x4U { .. }
15671579
| Operator::I16x8WidenLowI8x16S { .. }
15681580
| Operator::I16x8WidenHighI8x16S { .. }
15691581
| Operator::I16x8WidenLowI8x16U { .. }

0 commit comments

Comments
 (0)