Merge PR 40

This commit is contained in:
local committed 2026-11-24 15:30:10 -06:00
commit d0f3fee60d
3 files changed
+332

No files matched your search

+76
View File
@@ -1262,6 +1262,7 @@ impl<'a> Lower<'a> {
let n = i.name();
n.starts_with("ds_swizzle")
|| n.contains("permute")
|| n.starts_with("v_permlane")
|| n.starts_with("v_mbcnt")
|| matches!(n, "v_readlane_b32" | "v_writelane_b32")
|| matches!(&i.fields, Fields::Valu(v) if v.dpp.is_some())
@@ -7382,6 +7383,81 @@ impl<'a> Lower<'a> {
}
Ok(())
}
"v_permlane16_b32" | "v_permlanex16_b32" => {
// RDNA2 ISA 12.12: each nibble of {src2, src1} selects a lane
// in this row of 16, or the other row of the same 32-lane half.
// OP_SEL[0:1] are fetch-inactive and bound-control, not half selects.
if v.abs != 0 || v.neg != 0 || v.opsel & !3 != 0 {
return Err("permlane input modifiers");
}
self.cross_lane(false)?;
let fetch_inactive = v.opsel & 1 != 0;
if fetch_inactive
&& !all_lane_blocks(self.x.st).is_some_and(|all| all[self.cur_ir])
{
// DXIL cannot read the last VGPR value of a host invocation
// that has left through a lane branch. A guard keeps it here.
return Err("a permlane fetch from lanes outside the host branch");
}
let (x, lo, hi) = (s(self, 0)?, s(self, 1)?, s(self, 2)?);
let lane = self.lane_index();
let (k7, k8, k15, k16, k31, k32, k4, one, zero) = (
self.s.m.i32(7),
self.s.m.i32(8),
self.s.m.i32(15),
self.s.m.i32(16),
self.s.m.i32(31),
self.s.m.i32(32),
self.s.m.i32(4),
self.s.m.i32(1),
self.s.m.i32(0),
);
let pos = self.s.m.bin(c, Bin::And, lane, k15);
let lower = self.s.m.cmp(c, pred::IULT, pos, k8);
let packed = self.s.m.select(c, lower, lo, hi);
let shift = self.s.m.bin(c, Bin::And, pos, k7);
let shift = self.s.m.bin(c, Bin::Mul, shift, k4);
let pick = self.s.m.bin(c, Bin::LShr, packed, shift);
let pick = self.s.m.bin(c, Bin::And, pick, k15);
let not15 = self.s.m.i32(!15);
let mut row = self.s.m.bin(c, Bin::And, lane, not15);
if name == "v_permlanex16_b32" {
row = self.s.m.bin(c, Bin::Xor, row, k16);
}
let src = self.s.m.bin(c, Bin::Or, row, pick);
let r = if fetch_inactive {
self.read_lane(x, src)
} else {
// Ballot the console EXEC guard as well as the host's active
// invocations. Never shuffle from an inactive host lane.
let enabled = guard.unwrap_or_else(|| self.s.m.bool(true));
let i32t = self.s.t.i32;
let four = self.s.m.named_struct("dx.types.fouri32", vec![i32t; 4]);
let mask = self.s.op(
c, "waveActiveBallot", Attr::NoUnwind, four, 116, &[enabled],
);
let lo = self.s.m.extract(c, mask, 0);
let hi = self.s.m.extract(c, mask, 1);
let lower = self.s.m.cmp(c, pred::IULT, src, k32);
let word = self.s.m.select(c, lower, lo, hi);
let bit = self.s.m.bin(c, Bin::And, src, k31);
let bit = self.s.m.bin(c, Bin::LShr, word, bit);
let bit = self.s.m.bin(c, Bin::And, bit, one);
let active = self.s.m.cmp(c, pred::NE, bit, zero);
let safe = self.s.m.select(c, active, src, lane);
let read = self.read_lane(x, safe);
let fallback = if v.opsel & 2 != 0 {
zero
} else {
let Some(Operand::Vector { reg, .. }) = v.dst else {
return Err("a permlane result outside a VGPR");
};
self.i32_of(inst.read(Reg::V(reg)).ok_or("a permlane old value")?)?
};
self.s.m.select(c, active, read, fallback)
};
int(self, r)
}
"v_readlane_b32" => {
let (a, lane) = (s(self, 0)?, s(self, 1)?);
// A computed lane in a pixel or vertex program is a host lane