diff --git a/src/panfrost/compiler/kraid/builder.rs b/src/panfrost/compiler/kraid/builder.rs index 89b902cf458..3c51bf61ab0 100644 --- a/src/panfrost/compiler/kraid/builder.rs +++ b/src/panfrost/compiler/kraid/builder.rs @@ -36,6 +36,8 @@ pub trait Builder { pub trait SSABuilder: Builder { fn alloc_ssa(&mut self, bits: u8) -> SSAValue; + fn alloc_vec(&mut self, comps: u8) -> SSARef; + fn copy_i8(&mut self, src: Src) -> SSAValue { let def = self.alloc_ssa(8); self.copy_i8_to(def.into(), src); @@ -164,4 +166,8 @@ impl SSABuilder for SSAInstrBuilder<'_> { fn alloc_ssa(&mut self, bits: u8) -> SSAValue { self.alloc.alloc(bits) } + + fn alloc_vec(&mut self, comps: u8) -> SSARef { + self.alloc.alloc_vec(comps) + } } diff --git a/src/panfrost/compiler/kraid/ssa_value.rs b/src/panfrost/compiler/kraid/ssa_value.rs index 42bd306729a..25f2fa2fa7d 100644 --- a/src/panfrost/compiler/kraid/ssa_value.rs +++ b/src/panfrost/compiler/kraid/ssa_value.rs @@ -126,6 +126,19 @@ impl SSARef { self.as_mut_slice().iter_mut() } + pub fn from_iter(it: impl ExactSizeIterator) -> Self { + let len = it.len(); + + let inner = if len <= SSARefInnerShort::MAX_LEN { + SSARefInner::Short(it.map(|x| x.packed).collect()) + } else { + assert!(len <= SSARefInnerLong::MAX_LEN); + SSARefInner::Long(Box::new(it.map(|x| x.packed).collect())) + }; + + Self { v: inner } + } + #[cold] #[inline] fn cold() {} @@ -271,6 +284,10 @@ impl SSAValueAllocator { self.count += 1; SSAValue::new(idx, bits) } + + pub fn alloc_vec(&mut self, comps: u8) -> SSARef { + SSARef::from_iter((0..comps).map(|_| self.alloc(32))) + } } #[cfg(test)]