mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-21 21:08:23 +02:00
kraid: Add alloc_vec utility
Signed-off-by: Lorenzo Rossi <lorenzo.rossi@collabora.com> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/42189>
This commit is contained in:
parent
18b425ede5
commit
cbf450c7ff
2 changed files with 23 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,6 +126,19 @@ impl SSARef {
|
|||
self.as_mut_slice().iter_mut()
|
||||
}
|
||||
|
||||
pub fn from_iter(it: impl ExactSizeIterator<Item = SSAValue>) -> 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)]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue