Skip to content

Commit d2ae0fc

Browse files
committed
simplification
1 parent 4c399b1 commit d2ae0fc

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

crates/vm/src/bytecode/instruction.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ impl Instruction {
155155
state[DIMENSION..].copy_from_slice(&b);
156156
p16.permute_mut(&mut state);
157157

158-
let out0: [F; DIMENSION] = state[..DIMENSION].try_into().unwrap();
159-
let out1: [F; DIMENSION] = state[DIMENSION..].try_into().unwrap();
160-
memory.set_vector(r_ptr, out0)?;
161-
memory.set_vector(r_ptr + 1, out1)?;
158+
memory.set_vectorized_slice(r_ptr, &state)?;
162159
*pc += 1;
163160
}
164161

@@ -179,8 +176,7 @@ impl Instruction {
179176
state[2 * DIMENSION..].copy_from_slice(&b);
180177
p24.permute_mut(&mut state);
181178

182-
let out: [F; DIMENSION] = state[2 * DIMENSION..].try_into().unwrap();
183-
memory.set_vector(r_ptr, out)?;
179+
memory.set_vectorized_slice(r_ptr, &state[2 * DIMENSION..])?;
184180
*pc += 1;
185181
}
186182

@@ -196,17 +192,8 @@ impl Instruction {
196192
let p1 = arg1.read_value(memory, *fp)?.to_usize();
197193
let pr = res.read_value(memory, *fp)?.to_usize();
198194

199-
// leverage Memory helper if you have it; otherwise map manually
200-
let s0 = (0..*size)
201-
.map(|i| {
202-
Ok(EF::from_basis_coefficients_slice(&memory.get_vector(p0 + i)?).unwrap())
203-
})
204-
.collect::<Result<Vec<_>, RunnerError>>()?;
205-
let s1 = (0..*size)
206-
.map(|i| {
207-
Ok(EF::from_basis_coefficients_slice(&memory.get_vector(p1 + i)?).unwrap())
208-
})
209-
.collect::<Result<Vec<_>, RunnerError>>()?;
195+
let s0 = memory.get_vectorized_slice_extension::<EF>(p0, *size)?;
196+
let s1 = memory.get_vectorized_slice_extension::<EF>(p1, *size)?;
210197

211198
let dp: [F; DIMENSION] = dot_product::<EF, _, _>(s0.into_iter(), s1.into_iter())
212199
.as_basis_coefficients_slice()
@@ -230,18 +217,8 @@ impl Instruction {
230217

231218
let start = pcf << *n_vars;
232219
let len = 1usize << *n_vars;
233-
let coeffs = (0..len)
234-
.map(|i| memory.get(start + i))
235-
.collect::<Result<Vec<_>, _>>()?;
236-
237-
let point = (0..*n_vars)
238-
.map(|i| {
239-
Ok(
240-
EF::from_basis_coefficients_slice(&memory.get_vector(ppt + i)?)
241-
.unwrap(),
242-
)
243-
})
244-
.collect::<Result<Vec<_>, RunnerError>>()?;
220+
let coeffs = memory.slice(start, len)?;
221+
let point = memory.get_vectorized_slice_extension::<EF>(ppt, *n_vars)?;
245222

246223
let eval = coeffs.evaluate(&MultilinearPoint(point));
247224
let out: [F; DIMENSION] = eval.as_basis_coefficients_slice().try_into().unwrap();

0 commit comments

Comments
 (0)