Take the fix/amd-view-heap-clamp branch of triippywhale's fork (as one commit)
Every host view heap ends at a null slot that view indices past the heap read (a host that takes large heaps gets 2^21 views; one that caps them keeps the capped heap), the cache key includes that limit, and v_permlane16/x16 are lowered. Both forks lower v_cvt_f32_f64. The IEEE form with its test is the one in use; this branch's flush-to-zero form is kept beside it, unused, and its test is ignored until the console's float mode for the instruction is checked. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
3bff182ef4
commit
31714deb2d
6 files changed
+302
-49
No files matched your search
@@ -308,6 +308,110 @@ fn packed_add_selects_halves_of_inline_constants() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The float `v_cvt_f32_f64` gives for `x`: Rust's rounding (to nearest
|
||||
/// even), with results below the smallest normal float flushed to signed
|
||||
/// zero as the console's default float mode does.
|
||||
fn cvt_f32_f64_reference(x: f64) -> u32 {
|
||||
let r = x as f32;
|
||||
if r.is_subnormal() || (r == 0.0 && x != 0.0) {
|
||||
r.to_bits() & 0x8000_0000
|
||||
} else {
|
||||
r.to_bits()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "expects results below the smallest normal float flushed to zero; the IEEE lowering (v_cvt_f32_f64_matches_ieee754) is kept until the console's mode is checked"]
|
||||
fn v_cvt_f32_f64_rounds_to_nearest_even() {
|
||||
// v_cvt_f32_f64 v0, v[1:2] (VOP1 opcode 0x0f)
|
||||
let shader = build_valu_cs(&[vop1(0x00f, 0, vgpr(1))]);
|
||||
let tie_even = 1.0f64 + f64::from(f32::EPSILON) / 2.0; // ties to 1.0
|
||||
let tie_odd = 1.0f64 + 1.5 * f64::from(f32::EPSILON); // ties up to 1 + 2 ulp
|
||||
let values = [
|
||||
0.0,
|
||||
-0.0,
|
||||
1.0,
|
||||
-2.5,
|
||||
std::f64::consts::PI,
|
||||
1.0e-3,
|
||||
123_456_789.123,
|
||||
tie_even,
|
||||
tie_odd,
|
||||
1.0 + f64::from(f32::EPSILON) * 0.75,
|
||||
f64::from(f32::MAX),
|
||||
f64::from(f32::MAX) * 1.000_000_1, // rounds to infinity
|
||||
1.0e300,
|
||||
-1.0e300,
|
||||
1.0e-40, // a float denormal: flushed
|
||||
-1.0e-300,
|
||||
f64::from(f32::MIN_POSITIVE),
|
||||
f64::INFINITY,
|
||||
f64::NEG_INFINITY,
|
||||
f64::NAN,
|
||||
];
|
||||
let inputs: Vec<[u32; 4]> = values
|
||||
.iter()
|
||||
.map(|x| {
|
||||
let b = x.to_bits();
|
||||
[b as u32, (b >> 32) as u32, 0, 0]
|
||||
})
|
||||
.collect();
|
||||
run_cases(&shader, &inputs, |backend, i, _, got| {
|
||||
let x = values[i];
|
||||
if x.is_nan() {
|
||||
assert!(f32::from_bits(got).is_nan(), "{backend}: cvt({x}) = {got:#010x}, want NaN");
|
||||
return;
|
||||
}
|
||||
let want = cvt_f32_f64_reference(x);
|
||||
assert_eq!(got, want, "{backend}: cvt({x:e}) = {got:#010x}, want {want:#010x}");
|
||||
});
|
||||
}
|
||||
|
||||
/// The lane `v_permlane16_b32` (`cross` false) or `v_permlanex16_b32` reads
|
||||
/// for `lane`, with selector dwords `s1` (lanes 0-7 of a row) and `s2`.
|
||||
fn permlane_source(lane: u32, s1: u32, s2: u32, cross: bool) -> u32 {
|
||||
let sel = u64::from(s1) | u64::from(s2) << 32;
|
||||
let pick = (sel >> (4 * (lane & 15)) & 15) as u32;
|
||||
let row = if cross {
|
||||
(lane & !31) | ((lane & 16) ^ 16)
|
||||
} else {
|
||||
lane & !15
|
||||
};
|
||||
row | pick
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v_permlane16_and_x16_read_the_lanes_their_selectors_pick() {
|
||||
// 32 lanes, each with its lane number in v0; v1 = permute(v0, s0, s1);
|
||||
// lane `read` of v1 into s12, then into v0 for the store.
|
||||
let selectors: [(u32, u32); 3] = [
|
||||
(0x7654_3210, 0xfedc_ba98), // identity within the row
|
||||
(0x89ab_cdef, 0x0123_4567), // reversed
|
||||
(0x1111_1111, 0xf0f0_f0f0), // repeats
|
||||
];
|
||||
for (op, cross) in [(0x377u16, false), (0x378, true)] {
|
||||
for read in [0u8, 5, 15, 16, 22, 31] {
|
||||
let mut body = Vec::new();
|
||||
body.extend_from_slice(&vop3(op, 1, vgpr(0), sgpr(0), sgpr(1)));
|
||||
// v_readlane_b32 s12, v1, read (inline constant 128 + read)
|
||||
body.extend_from_slice(&vop3(0x360, 12, vgpr(1), 128 + u16::from(read), 0));
|
||||
body.push(vop1(0x001, 0, sgpr(12))); // v_mov_b32 v0, s12
|
||||
let shader = build_cs(&body, 32, 0);
|
||||
let inputs: Vec<[u32; 4]> = selectors.iter().map(|&(a, b)| [a, b, 0, 0]).collect();
|
||||
// Cross-lane code declares WaveSize(32), which WARP's pipeline
|
||||
// creation refuses: hardware only.
|
||||
run_cases_on(&shader, &inputs, &[("hardware", false)], |backend, i, inp, got| {
|
||||
let want = permlane_source(u32::from(read), inp[0], inp[1], cross);
|
||||
assert_eq!(
|
||||
got, want,
|
||||
"{backend}: op {op:#x} selectors {:08x?}, lane {read}",
|
||||
selectors[i]
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v_med3_f32_matches_rdna2_with_nan() {
|
||||
// v_med3_f32 v0, v1, v2, v3 (VOP3 opcode 0x157)
|
||||
|
||||
Reference in new issue
Block a user