Skip to content

Commit

Permalink
opt: try removing get_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-sun committed Jan 8, 2025
1 parent 00f66dc commit 2e42e24
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions extensions/native/compiler/src/ir/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ impl<C: Config> Builder<C> {
builder.set(&state, i, C::F::ZERO);
});

let address = self.get_ref(&state, 0).ptr.address;
let address = match state {
Array::Fixed(_) => panic!("Poseidon2 hash is not allowed on fixed arrays"),
Array::Dyn(ptr, _) => ptr.address,
};
let idx: Var<_> = self.eval(C::N::ZERO);
self.iter(&array).for_each(|subarray, builder| {
builder.iter(&subarray).for_each(|element, builder| {
Expand All @@ -151,7 +154,12 @@ impl<C: Config> Builder<C> {
.if_eq(idx, C::N::from_canonical_usize(HASH_RATE))
.then(|builder| {
builder.poseidon2_permute_mut(&state);
let start = builder.get_ref(&state, 0).ptr.address;
let start = match state {
Array::Fixed(_) => {
panic!("Poseidon2 hash is not allowed on fixed arrays")
}
Array::Dyn(ptr, _) => ptr.address,
};
builder.assign(&address, start);
builder.assign(&idx, C::N::ZERO);
});
Expand Down

0 comments on commit 2e42e24

Please sign in to comment.