From 07e4d28b2f4e6ae9d684909769e4cc4f3b4d526f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 1 Jul 2020 10:56:49 -0700 Subject: [PATCH] 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. --- cranelift/wasm/src/code_translator.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index 023961035b6e..c62d29e60198 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -1559,11 +1559,23 @@ pub fn translate_operator( let a = pop1_with_bitcast(state, F32X4, builder); state.push1(builder.ins().fcvt_to_sint_sat(I32X4, a)) } + Operator::I8x16NarrowI16x8S => { + let (a, b) = pop2_with_bitcast(state, I16X8, builder); + state.push1(builder.ins().snarrow(a, b)) + } + Operator::I16x8NarrowI32x4S => { + let (a, b) = pop2_with_bitcast(state, I32X4, builder); + state.push1(builder.ins().snarrow(a, b)) + } + Operator::I8x16NarrowI16x8U => { + let (a, b) = pop2_with_bitcast(state, I16X8, builder); + state.push1(builder.ins().unarrow(a, b)) + } + Operator::I16x8NarrowI32x4U => { + let (a, b) = pop2_with_bitcast(state, I32X4, builder); + state.push1(builder.ins().unarrow(a, b)) + } Operator::I32x4TruncSatF32x4U - | Operator::I8x16NarrowI16x8S { .. } - | Operator::I8x16NarrowI16x8U { .. } - | Operator::I16x8NarrowI32x4S { .. } - | Operator::I16x8NarrowI32x4U { .. } | Operator::I16x8WidenLowI8x16S { .. } | Operator::I16x8WidenHighI8x16S { .. } | Operator::I16x8WidenLowI8x16U { .. }