From ef45379bfa6e4e33b020ad02d0177d511bcad5e2 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 10 Apr 2023 17:23:26 -0500 Subject: [PATCH] nak: Add an SSAComp struct This is useful in RA for referring to a single component of an SSA value. Part-of: --- src/nouveau/compiler/nak_ir.rs | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/nouveau/compiler/nak_ir.rs b/src/nouveau/compiler/nak_ir.rs index 1c04e9b3192..4d4e1f2df8f 100644 --- a/src/nouveau/compiler/nak_ir.rs +++ b/src/nouveau/compiler/nak_ir.rs @@ -105,6 +105,16 @@ impl SSAValue { pub fn comps(&self) -> u8 { (((self.packed >> 27) & 0x7) + 1).try_into().unwrap() } + + pub fn comp(&self, comp: u8) -> SSAComp { + assert!(comp < self.comps()); + SSAComp::new(self.file(), self.idx(), comp) + } + + pub fn as_comp(&self) -> SSAComp { + assert!(self.comps() == 1); + SSAComp::new(self.file(), self.idx(), 0) + } } impl HasRegFile for SSAValue { @@ -123,6 +133,33 @@ impl fmt::Display for SSAValue { } } +#[derive(Clone, Copy, Eq, Hash, PartialEq)] +pub struct SSAComp { + v: SSAValue, +} + +impl SSAComp { + pub fn new(file: RegFile, idx: u32, comp: u8) -> SSAComp { + SSAComp { + v: SSAValue::new(file, idx, comp + 1), + } + } + + pub fn idx(&self) -> u32 { + self.v.idx() + } + + pub fn comp(&self) -> u8 { + self.v.comps() - 1 + } +} + +impl HasRegFile for SSAComp { + fn file(&self) -> RegFile { + self.v.file() + } +} + pub struct SSAValueAllocator { count: u32, }