Skip to content

Commit da93f64

Browse files
authored
pulley: Fill out lowerings for {s,u}{min,max} (#9819)
Gets another `*.wast` test passing cc #9783
1 parent b4a6d99 commit da93f64

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

cranelift/codegen/src/isa/pulley_shared/lower.isle

+20
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@
240240
(rule 1 (lower (has_type $I64 (bnot a)))
241241
(pulley_xbnot64 a))
242242

243+
;;;; Rules for `umin` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
244+
245+
(rule (lower (has_type $I32 (umin a b))) (pulley_xmin32_u a b))
246+
(rule (lower (has_type $I64 (umin a b))) (pulley_xmin64_u a b))
247+
248+
;;;; Rules for `smin` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249+
250+
(rule (lower (has_type $I32 (smin a b))) (pulley_xmin32_s a b))
251+
(rule (lower (has_type $I64 (smin a b))) (pulley_xmin64_s a b))
252+
253+
;;;; Rules for `umax` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254+
255+
(rule (lower (has_type $I32 (umax a b))) (pulley_xmax32_u a b))
256+
(rule (lower (has_type $I64 (umax a b))) (pulley_xmax64_u a b))
257+
258+
;;;; Rules for `smax` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259+
260+
(rule (lower (has_type $I32 (smax a b))) (pulley_xmax32_s a b))
261+
(rule (lower (has_type $I64 (smax a b))) (pulley_xmax64_s a b))
262+
243263
;;;; Rules for `ctz` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
244264

245265
(rule (lower (has_type $I32 (ctz a))) (pulley_xctz32 a))

crates/wast-util/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ impl WastTest {
400400
"misc_testsuite/memory-combos.wast",
401401
"misc_testsuite/memory64/simd.wast",
402402
"misc_testsuite/memory64/threads.wast",
403-
"misc_testsuite/rust_fannkuch.wast",
404403
"misc_testsuite/simd/almost-extmul.wast",
405404
"misc_testsuite/simd/canonicalize-nan.wast",
406405
"misc_testsuite/simd/cvt-from-uint.wast",

pulley/src/interp.rs

+56
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,62 @@ impl OpVisitor for Interpreter<'_> {
18141814
ControlFlow::Continue(())
18151815
}
18161816

1817+
fn xmin32_u(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1818+
let a = self.state[operands.src1].get_u32();
1819+
let b = self.state[operands.src2].get_u32();
1820+
self.state[operands.dst].set_u32(a.min(b));
1821+
ControlFlow::Continue(())
1822+
}
1823+
1824+
fn xmin32_s(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1825+
let a = self.state[operands.src1].get_i32();
1826+
let b = self.state[operands.src2].get_i32();
1827+
self.state[operands.dst].set_i32(a.min(b));
1828+
ControlFlow::Continue(())
1829+
}
1830+
1831+
fn xmax32_u(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1832+
let a = self.state[operands.src1].get_u32();
1833+
let b = self.state[operands.src2].get_u32();
1834+
self.state[operands.dst].set_u32(a.max(b));
1835+
ControlFlow::Continue(())
1836+
}
1837+
1838+
fn xmax32_s(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1839+
let a = self.state[operands.src1].get_i32();
1840+
let b = self.state[operands.src2].get_i32();
1841+
self.state[operands.dst].set_i32(a.max(b));
1842+
ControlFlow::Continue(())
1843+
}
1844+
1845+
fn xmin64_u(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1846+
let a = self.state[operands.src1].get_u64();
1847+
let b = self.state[operands.src2].get_u64();
1848+
self.state[operands.dst].set_u64(a.min(b));
1849+
ControlFlow::Continue(())
1850+
}
1851+
1852+
fn xmin64_s(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1853+
let a = self.state[operands.src1].get_i64();
1854+
let b = self.state[operands.src2].get_i64();
1855+
self.state[operands.dst].set_i64(a.min(b));
1856+
ControlFlow::Continue(())
1857+
}
1858+
1859+
fn xmax64_u(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1860+
let a = self.state[operands.src1].get_u64();
1861+
let b = self.state[operands.src2].get_u64();
1862+
self.state[operands.dst].set_u64(a.max(b));
1863+
ControlFlow::Continue(())
1864+
}
1865+
1866+
fn xmax64_s(&mut self, operands: BinaryOperands<XReg>) -> ControlFlow<Done> {
1867+
let a = self.state[operands.src1].get_i64();
1868+
let b = self.state[operands.src2].get_i64();
1869+
self.state[operands.dst].set_i64(a.max(b));
1870+
ControlFlow::Continue(())
1871+
}
1872+
18171873
fn fconst32(&mut self, dst: FReg, bits: u32) -> ControlFlow<Done> {
18181874
self.state[dst].set_f32(f32::from_bits(bits));
18191875
ControlFlow::Continue(())

pulley/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,23 @@ macro_rules! for_each_op {
401401
/// `dst = !src1`
402402
xbnot64 = XBnot64 { dst: XReg, src: XReg };
403403

404+
/// `low32(dst) = min(low32(src1), low32(src2))` (unsigned)
405+
xmin32_u = Xmin32U { operands: BinaryOperands<XReg> };
406+
/// `low32(dst) = min(low32(src1), low32(src2))` (signed)
407+
xmin32_s = Xmin32S { operands: BinaryOperands<XReg> };
408+
/// `low32(dst) = max(low32(src1), low32(src2))` (unsigned)
409+
xmax32_u = Xmax32U { operands: BinaryOperands<XReg> };
410+
/// `low32(dst) = max(low32(src1), low32(src2))` (signed)
411+
xmax32_s = Xmax32S { operands: BinaryOperands<XReg> };
412+
/// `dst = min(src1, src2)` (unsigned)
413+
xmin64_u = Xmin64U { operands: BinaryOperands<XReg> };
414+
/// `dst = min(src1, src2)` (signed)
415+
xmin64_s = Xmin64S { operands: BinaryOperands<XReg> };
416+
/// `dst = max(src1, src2)` (unsigned)
417+
xmax64_u = Xmax64U { operands: BinaryOperands<XReg> };
418+
/// `dst = max(src1, src2)` (signed)
419+
xmax64_s = Xmax64S { operands: BinaryOperands<XReg> };
420+
404421
/// `low32(dst) = bits`
405422
fconst32 = FConst32 { dst: FReg, bits: u32 };
406423
/// `dst = bits`

0 commit comments

Comments
 (0)