remove examples, simplify type flattening for known indices
This commit is contained in:
parent
7ab7fecf4f
commit
f00966a433
3 changed files with 61 additions and 53 deletions
|
@ -12,5 +12,5 @@ def bubblesort<N>(u32[N] a) -> u32[N]:
|
|||
endfor
|
||||
return a
|
||||
|
||||
def main(u32[10] a) -> u32[10]:
|
||||
def main(u32[2] a) -> u32[2]:
|
||||
return bubblesort(a)
|
1
changelogs/unreleased/930-schaeff
Normal file
1
changelogs/unreleased/930-schaeff
Normal file
|
@ -0,0 +1 @@
|
|||
Reduce cost of variable memory access
|
|
@ -577,60 +577,67 @@ fn fold_select_expression<'ast, T: Field, E>(
|
|||
let array = f.fold_array_expression(statements_buffer, *select.array);
|
||||
let index = f.fold_uint_expression(statements_buffer, *select.index);
|
||||
|
||||
array
|
||||
.chunks(size)
|
||||
.fold(vec![vec![]; size], |mut acc, e| {
|
||||
acc = acc
|
||||
.into_iter()
|
||||
.zip(e)
|
||||
.map(|(mut a, e)| {
|
||||
a.push(e);
|
||||
a
|
||||
})
|
||||
.collect();
|
||||
acc
|
||||
})
|
||||
.into_iter()
|
||||
.map(|a| {
|
||||
use crate::zir::Typed;
|
||||
match index.as_inner() {
|
||||
zir::UExpressionInner::Value(v) => {
|
||||
let v = *v as usize;
|
||||
|
||||
let ty = a[0].get_type();
|
||||
array[v * size..(v + 1) * size].to_vec()
|
||||
}
|
||||
_ => array
|
||||
.chunks(size)
|
||||
.fold(vec![vec![]; size], |mut acc, e| {
|
||||
acc = acc
|
||||
.into_iter()
|
||||
.zip(e)
|
||||
.map(|(mut a, e)| {
|
||||
a.push(e);
|
||||
a
|
||||
})
|
||||
.collect();
|
||||
acc
|
||||
})
|
||||
.into_iter()
|
||||
.map(|a| {
|
||||
use crate::zir::Typed;
|
||||
|
||||
match ty {
|
||||
zir::Type::Boolean => zir::BooleanExpression::Select(
|
||||
a.into_iter()
|
||||
.map(|e| match e {
|
||||
zir::ZirExpression::Boolean(e) => e.clone(),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect(),
|
||||
box index.clone(),
|
||||
)
|
||||
.into(),
|
||||
zir::Type::FieldElement => zir::FieldElementExpression::Select(
|
||||
a.into_iter()
|
||||
.map(|e| match e {
|
||||
zir::ZirExpression::FieldElement(e) => e.clone(),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect(),
|
||||
box index.clone(),
|
||||
)
|
||||
.into(),
|
||||
zir::Type::Uint(bitwidth) => zir::UExpressionInner::Select(
|
||||
a.into_iter()
|
||||
.map(|e| match e {
|
||||
zir::ZirExpression::Uint(e) => e.clone(),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect(),
|
||||
box index.clone(),
|
||||
)
|
||||
.annotate(bitwidth)
|
||||
.into(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
let ty = a[0].get_type();
|
||||
|
||||
match ty {
|
||||
zir::Type::Boolean => zir::BooleanExpression::Select(
|
||||
a.into_iter()
|
||||
.map(|e| match e {
|
||||
zir::ZirExpression::Boolean(e) => e.clone(),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect(),
|
||||
box index.clone(),
|
||||
)
|
||||
.into(),
|
||||
zir::Type::FieldElement => zir::FieldElementExpression::Select(
|
||||
a.into_iter()
|
||||
.map(|e| match e {
|
||||
zir::ZirExpression::FieldElement(e) => e.clone(),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect(),
|
||||
box index.clone(),
|
||||
)
|
||||
.into(),
|
||||
zir::Type::Uint(bitwidth) => zir::UExpressionInner::Select(
|
||||
a.into_iter()
|
||||
.map(|e| match e {
|
||||
zir::ZirExpression::Uint(e) => e.clone(),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect(),
|
||||
box index.clone(),
|
||||
)
|
||||
.annotate(bitwidth)
|
||||
.into(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_if_else_expression<'ast, T: Field, E: Flatten<'ast, T>>(
|
||||
|
|
Loading…
Reference in a new issue