From 3576d8c5bb135c8a44ca6595ad041f84be11246f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 7 Jul 2020 16:54:18 -0700 Subject: [PATCH] Translate Wasm's `widen` instructions to Cranelift's `[u|s]widen_[low|high]` --- cranelift/wasm/src/code_translator.rs | 44 ++++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index 64556bdddb..79eae5c2a6 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -1582,17 +1582,39 @@ pub fn translate_operator( let (a, b) = pop2_with_bitcast(state, I32X4, builder); state.push1(builder.ins().unarrow(a, b)) } - Operator::I16x8WidenLowI8x16S { .. } - | Operator::I16x8WidenHighI8x16S { .. } - | Operator::I16x8WidenLowI8x16U { .. } - | Operator::I16x8WidenHighI8x16U { .. } - | Operator::I32x4WidenLowI16x8S { .. } - | Operator::I32x4WidenHighI16x8S { .. } - | Operator::I32x4WidenLowI16x8U { .. } - | Operator::I32x4WidenHighI16x8U { .. } - | Operator::I8x16Bitmask - | Operator::I16x8Bitmask - | Operator::I32x4Bitmask => { + Operator::I16x8WidenLowI8x16S => { + let a = pop1_with_bitcast(state, I8X16, builder); + state.push1(builder.ins().swiden_low(a)) + } + Operator::I16x8WidenHighI8x16S => { + let a = pop1_with_bitcast(state, I8X16, builder); + state.push1(builder.ins().swiden_high(a)) + } + Operator::I16x8WidenLowI8x16U => { + let a = pop1_with_bitcast(state, I8X16, builder); + state.push1(builder.ins().uwiden_low(a)) + } + Operator::I16x8WidenHighI8x16U => { + let a = pop1_with_bitcast(state, I8X16, builder); + state.push1(builder.ins().uwiden_high(a)) + } + Operator::I32x4WidenLowI16x8S => { + let a = pop1_with_bitcast(state, I16X8, builder); + state.push1(builder.ins().swiden_low(a)) + } + Operator::I32x4WidenHighI16x8S => { + let a = pop1_with_bitcast(state, I16X8, builder); + state.push1(builder.ins().swiden_high(a)) + } + Operator::I32x4WidenLowI16x8U => { + let a = pop1_with_bitcast(state, I16X8, builder); + state.push1(builder.ins().uwiden_low(a)) + } + Operator::I32x4WidenHighI16x8U => { + let a = pop1_with_bitcast(state, I16X8, builder); + state.push1(builder.ins().uwiden_high(a)) + } + Operator::I8x16Bitmask | Operator::I16x8Bitmask | Operator::I32x4Bitmask => { return Err(wasm_unsupported!("proposed SIMD operator {:?}", op)); }