Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions crates/xcl/src/gpu/dxil/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ impl Lw {
if self.live_exec == Some((lo, hi)) {
return self.b(true);
}
if self.wave64 {
match (self.s.m.const_u64(lo), self.s.m.const_u64(hi)) {
(Some(0xFFFF_FFFF), Some(0xFFFF_FFFF)) => return self.b(true),
(Some(0), Some(0)) => return self.b(false),
_ => {}
}
} else {
match self.s.m.const_u64(lo) {
Some(0xFFFF_FFFF) => return self.b(true),
Some(0) => return self.b(false),
_ => {}
}
}
let key = (self.cur(), lo, hi);
if let Some(&v) = self.exec_cache.get(&key) {
return v;
Expand All @@ -210,6 +223,14 @@ impl Lw {
} else {
lo
};
if let Some(k) = self.s.m.const_u64(w) {
if k == 0xFFFF_FFFF {
return self.b(true);
}
if k == 0 {
return self.b(false);
}
}
let l = self.lane31;
let sh = self.bin(BinOp::LShr, w, l);
let b = self.andc(sh, 1);
Expand Down Expand Up @@ -1145,14 +1166,17 @@ mod ps_ballot_tests {
ins(if wave64 { "S_MOV_B64" } else { "S_MOV_B32" }, "ENC_SOP1", &[("SDST", 10), ("SSRC0", 126)]),
ins(if wave64 { "S_WQM_B64" } else { "S_WQM_B32" }, "ENC_SOP1", &[("SDST", 126), ("SSRC0", 126)]),
ins("V_CMP_LT_F32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 2)]),
// Split basic block so block-local CSE keeps `op`'s live-lane ballot distinct from entry EXEC.
// Split basic block so block-local CSE keeps `op`'s live-lane ballot distinct from entry EXEC
// (the skipped s14 is exported: a dead block would be merged away and the two
// identical ballots folded once the optimizer runs again)
ins("S_CMP_EQ_U32", "ENC_SOPC", &[("SSRC0", 10), ("SSRC1", 128)]),
ins("S_CBRANCH_SCC1", "ENC_SOPP", &[("SIMM16", 1)]),
ins("S_ADD_U32", "ENC_SOP2", &[("SDST", 14), ("SSRC0", 14), ("SSRC1", 129)]),
ins(op, "ENC_SOP2", &[("SDST", dst), ("SSRC0", s0), ("SSRC1", s1)]),
ins("S_CSELECT_B32", "ENC_SOP2", &[("SDST", 11), ("SSRC0", 129), ("SSRC1", 128)]),
ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 4), ("SRC0", 11)]),
ins("EXP", "ENC_EXP", &[("TGT", 0), ("EN", 0xF), ("VSRC0", 4), ("VSRC1", 3), ("VSRC2", 2), ("VSRC3", 3), ("DONE", 1), ("VM", 1)]),
ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 5), ("SRC0", 14)]),
ins("EXP", "ENC_EXP", &[("TGT", 0), ("EN", 0xF), ("VSRC0", 4), ("VSRC1", 3), ("VSRC2", 2), ("VSRC3", 5), ("DONE", 1), ("VM", 1)]),
ins("S_ENDPGM", "ENC_SOPP", &[]),
].concat();
let k = kernel::translate_pixel(&c, KernelOptions { wave64, split: false, mem_windows: 1, sampler_base: 0 }, &psi).expect("translate PS");
Expand Down
25 changes: 24 additions & 1 deletion crates/xcl/src/gpu/dxil/lower_valu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,31 @@ impl Lw {
})
}

/// The recompiler's `float_compare`: NaN tested explicitly.
/// Float compare: single-instruction IEEE-754 ordered/unordered `fcmp` for `f32`,
/// explicit `isnan_d` for `f64`.
pub fn float_compare(&mut self, opn: &str, a: Value, b: Value) -> Option<Value> {
let is_f32 = self.s.m.type_of(a) == self.s.m.f32();
if is_f32 {
return Some(match opn {
"f" => self.b(false),
"t" | "tru" => self.b(true),
"lt" => self.fcmp(Pred::FOLt, a, b),
"eq" => self.fcmp(Pred::FOEq, a, b),
"le" => self.fcmp(Pred::FOLe, a, b),
"gt" => self.fcmp(Pred::FOGt, a, b),
"ge" => self.fcmp(Pred::FOGe, a, b),
"lg" => self.fcmp(Pred::FONe, a, b),
"o" => self.fcmp(Pred::FOrd, a, b),
"u" => self.fcmp(Pred::FUno, a, b),
"nlt" => self.fcmp(Pred::FUGe, a, b),
"neq" => self.fcmp(Pred::FUNe, a, b),
"nle" => self.fcmp(Pred::FUGt, a, b),
"ngt" => self.fcmp(Pred::FULe, a, b),
"nge" => self.fcmp(Pred::FULt, a, b),
"nlg" => self.fcmp(Pred::FUEq, a, b),
_ => return None,
});
}
let rel = |s: &mut Self, r: &str| -> Option<Value> {
Some(match r {
"lt" => s.fcmp(Pred::FOLt, a, b),
Expand Down
16 changes: 16 additions & 0 deletions crates/xcl/src/gpu/dxil/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,22 @@ impl Module {
}
(has_double_fma, has_res_heap, has_smp_heap, has_i64_atomic_gs, has_i64_atomic_res, has_uav_tex_load)
}
/// The `f32` value of a float constant (also unwraps `bitcast i32_const to float`).
pub fn const_f32(&self, v: Value) -> Option<f32> {
match v {
Value::Const(c) => match &self.consts[c as usize] {
ConstDef::Float(t, bits) if matches!(self.types[t.0 as usize], TypeDef::Float) => Some(f32::from_bits(*bits as u32)),
_ => None,
},
Value::Inst(i) => match self.insts[i as usize].op {
Op::Cast(CastOp::BitCast, src, to) if matches!(self.types[to.0 as usize], TypeDef::Float) => {
self.const_u64(src).map(|b| f32::from_bits(b as u32))
}
_ => None,
},
_ => None,
}
}
/// The integer value of a constant (zero-extended from its width).
pub fn const_u64(&self, v: Value) -> Option<u64> {
match v {
Expand Down
Loading
Loading