nak: Implement Foldable for OpPrmt

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30275>
This commit is contained in:
Faith Ekstrand 2024-07-19 19:38:56 -05:00 committed by Marge Bot
parent cac3ff011b
commit ebc1c052ab
2 changed files with 35 additions and 1 deletions

View file

@ -565,3 +565,14 @@ fn test_op_iadd3x() {
}
}
}
#[test]
fn test_op_prmt() {
let op = OpPrmt {
dst: Dst::None,
srcs: [0.into(), 0.into()],
sel: 0.into(),
mode: PrmtMode::Index,
};
test_foldable_op(op);
}

View file

@ -4078,7 +4078,7 @@ impl fmt::Display for PrmtMode {
}
#[repr(C)]
#[derive(SrcsAsSlice, DstsAsSlice)]
#[derive(Clone, SrcsAsSlice, DstsAsSlice)]
/// Permutes `srcs` into `dst` using `selection`.
pub struct OpPrmt {
#[dst_type(GPR)]
@ -4128,6 +4128,29 @@ impl OpPrmt {
}
}
impl Foldable for OpPrmt {
fn fold(&self, _sm: &dyn ShaderModel, f: &mut OpFoldData<'_>) {
let srcs = [
f.get_u32_src(self, &self.srcs[0]),
f.get_u32_src(self, &self.srcs[1]),
];
let sel = f.get_u32_src(self, &self.sel);
assert!(self.mode == PrmtMode::Index);
let sel = PrmtSel(sel as u16);
let mut dst = 0_u32;
for b in 0..4 {
let sel_byte = sel.get(b);
let src = srcs[sel_byte.src()];
let sb = sel_byte.fold_u32(src);
dst |= u32::from(sb) << (b * 8);
}
f.set_u32_dst(self, &self.dst, dst);
}
}
impl DisplayOp for OpPrmt {
fn fmt_op(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(