Skip to content

Commit

Permalink
pulley: Get strings.wast test passing
Browse files Browse the repository at this point in the history
Needed the `imul` CLIF instruction to get implemented so 32/64-bit
multiplication have now been added.

cc bytecodealliance#9783
  • Loading branch information
alexcrichton committed Dec 11, 2024
1 parent afb87ab commit e2c3054
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
14 changes: 14 additions & 0 deletions cranelift/codegen/src/isa/pulley_shared/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@
(rule (lower (has_type $I64 (isub a b)))
(pulley_xsub64 a b))

;;;; Rules for `imul` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(rule (lower (has_type $I8 (imul a b)))
(pulley_xmul32 a b))

(rule (lower (has_type $I16 (imul a b)))
(pulley_xmul32 a b))

(rule (lower (has_type $I32 (imul a b)))
(pulley_xmul32 a b))

(rule (lower (has_type $I64 (imul a b)))
(pulley_xmul64 a b))

;;;; Rules for `sdiv` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(rule (lower (has_type $I32 (sdiv a b))) (pulley_xdiv32_s a b))
Expand Down
10 changes: 0 additions & 10 deletions crates/wast-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ impl WastTest {
// features in Pulley are implemented.
if config.compiler == Compiler::CraneliftPulley {
let unsupported = [
"misc_testsuite/component-model/strings.wast",
"misc_testsuite/embenchen_fannkuch.wast",
"misc_testsuite/embenchen_fasta.wast",
"misc_testsuite/embenchen_ifs.wast",
Expand Down Expand Up @@ -433,8 +432,6 @@ impl WastTest {
"misc_testsuite/winch/_simd_load.wast",
"misc_testsuite/winch/_simd_multivalue.wast",
"misc_testsuite/winch/_simd_store.wast",
"misc_testsuite/winch/global.wast",
"misc_testsuite/winch/select.wast",
"spec_testsuite/call.wast",
"spec_testsuite/call_indirect.wast",
"spec_testsuite/conversions.wast",
Expand All @@ -444,22 +441,17 @@ impl WastTest {
"spec_testsuite/f64.wast",
"spec_testsuite/f64_bitwise.wast",
"spec_testsuite/f64_cmp.wast",
"spec_testsuite/fac.wast",
"spec_testsuite/float_exprs.wast",
"spec_testsuite/float_misc.wast",
"spec_testsuite/global.wast",
"spec_testsuite/i32.wast",
"spec_testsuite/i64.wast",
"spec_testsuite/if.wast",
"spec_testsuite/imports.wast",
"spec_testsuite/int_exprs.wast",
"spec_testsuite/labels.wast",
"spec_testsuite/local_get.wast",
"spec_testsuite/local_set.wast",
"spec_testsuite/local_tee.wast",
"spec_testsuite/loop.wast",
"spec_testsuite/proposals/annotations/simd_lane.wast",
"spec_testsuite/proposals/extended-const/global.wast",
"spec_testsuite/proposals/multi-memory/float_exprs0.wast",
"spec_testsuite/proposals/multi-memory/float_exprs1.wast",
"spec_testsuite/proposals/multi-memory/imports.wast",
Expand All @@ -473,7 +465,6 @@ impl WastTest {
"spec_testsuite/proposals/relaxed-simd/relaxed_min_max.wast",
"spec_testsuite/proposals/threads/atomic.wast",
"spec_testsuite/proposals/threads/imports.wast",
"spec_testsuite/select.wast",
"spec_testsuite/simd_address.wast",
"spec_testsuite/simd_align.wast",
"spec_testsuite/simd_bit_shift.wast",
Expand Down Expand Up @@ -530,7 +521,6 @@ impl WastTest {
"spec_testsuite/simd_store32_lane.wast",
"spec_testsuite/simd_store64_lane.wast",
"spec_testsuite/simd_store8_lane.wast",
"spec_testsuite/stack.wast",
"spec_testsuite/switch.wast",
"spec_testsuite/traps.wast",
];
Expand Down
14 changes: 14 additions & 0 deletions pulley/src/interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,20 @@ impl OpVisitor for Interpreter<'_> {
ControlFlow::Continue(())
}

fn xmul32(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
let a = self.state[operands.src1].get_u32();
let b = self.state[operands.src2].get_u32();
self.state[operands.dst].set_u32(a.wrapping_mul(b));
ControlFlow::Continue(())
}

fn xmul64(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
let a = self.state[operands.src1].get_u64();
let b = self.state[operands.src2].get_u64();
self.state[operands.dst].set_u64(a.wrapping_mul(b));
ControlFlow::Continue(())
}

fn xshl32(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
let a = self.state[operands.src1].get_u32();
let b = self.state[operands.src2].get_u32();
Expand Down
6 changes: 6 additions & 0 deletions pulley/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ macro_rules! for_each_op {
/// 64-bit wrapping subtraction: `dst = src1 - src2`.
xsub64 = Xsub64 { operands: BinaryOperands<XReg> };

/// `low32(dst) = low32(src1) * low32(src2)`
xmul32 = XMul32 { operands: BinaryOperands<XReg> };

/// `dst = src1 * src2`
xmul64 = XMul64 { operands: BinaryOperands<XReg> };

/// `low32(dst) = trailing_zeros(low32(src))`
xctz32 = Xctz32 { dst: XReg, src: XReg };
/// `dst = trailing_zeros(src)`
Expand Down
2 changes: 1 addition & 1 deletion pulley/src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ macro_rules! define_opcode {

impl Opcode {
/// The value of the maximum defined opcode.
pub const MAX: u8 = define_opcode!( @max $( $name )* ) + 1;
pub const MAX: u8 = Opcode::ExtendedOp as u8;
}
};

Expand Down

0 comments on commit e2c3054

Please sign in to comment.