Skip to content

Commit cd02ec7

Browse files
committed
fix: working for aligned memcpy; still needs to modify design for small source values
1 parent 0f3052b commit cd02ec7

File tree

1 file changed

+21
-65
lines changed

1 file changed

+21
-65
lines changed

extensions/memcpy/circuit/src/iteration.rs

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,6 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
144144
let prev_len = prev.len[0]
145145
+ prev.len[1] * AB::Expr::from_canonical_u32(1 << (2 * MEMCPY_LOOP_LIMB_BITS));
146146

147-
// write_data =
148-
// (local.data_1[shift..4], prev.data_4[0..shift]),
149-
// (local.data_2[shift..4], local.data_1[0..shift]),
150-
// (local.data_3[shift..4], local.data_2[0..shift]),
151-
// (local.data_4[shift..4], local.data_3[0..shift])
152-
// local.data-1 = tracing_read data
153147
let write_data_pairs = [
154148
(prev.data_4, local.data_1),
155149
(local.data_1, local.data_2),
@@ -308,11 +302,15 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
308302
// Read data from memory
309303
let read_data = [local.data_1, local.data_2, local.data_3, local.data_4];
310304

305+
eprintln!(
306+
"starting timestamp: {:?}",
307+
timestamp * AB::Expr::from_canonical_u32(1)
308+
);
311309
read_data.iter().enumerate().for_each(|(idx, data)| {
312310
// is valid read of entire 16 block chunk?
313311
let is_valid_read = if idx == 3 {
314312
// will always be a valid read
315-
AB::Expr::ONE * (local.is_shift_non_zero_or_not_start)
313+
AB::Expr::ONE * (local.is_valid)
316314
} else {
317315
// if idx < 3, its not an entire block read, if its the first block
318316
AB::Expr::ONE * (local.is_valid_not_start)
@@ -329,10 +327,12 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
329327
)
330328
.eval(builder, is_valid_read.clone());
331329
eprintln!(
332-
"local.source: {:?}, data: {:?}, local.source - AB::Expr::from_canonical_usize(16 - idx * 4): {:?}",
330+
"local.source: {:?}, data: {:?}, local.source - AB::Expr::from_canonical_usize(16 - idx * 4): {:?}, timestamp_pp: {:?}, is_valid_read: {:?}",
333331
local.source * AB::Expr::from_canonical_u32(1),
334332
data.clone().map(|x| x * (AB::Expr::from_canonical_u32(1))),
335-
local.source - AB::Expr::from_canonical_usize(16 - idx * 4) * AB::Expr::from_canonical_u32(1)
333+
local.source - AB::Expr::from_canonical_usize(16 - idx * 4) * AB::Expr::from_canonical_u32(1),
334+
timestamp_pp(AB::Expr::ZERO),
335+
is_valid_read.clone()
336336
);
337337
});
338338
/*
@@ -359,45 +359,7 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
359359
// error seems to be off by one for timestamp again, or off by 17 or 21??
360360
// timestamps are inconsistent everywhere...
361361

362-
/*
363-
heres the plan:
364-
identify everywhere where timeststamps are used; where theyre written to (tracing_read) etc.
365-
walk through each component, and take notes about how timestamp is incrementing in each portion
366-
*/
367-
368-
/*
369-
off by one:
370-
between memcpyiter Air and itself
371-
372-
off by 16:
373-
memcpyiter air and itself
374-
off by 17:
375-
between memoryDummyAir and accessAdapterAir
376-
377-
off by 21:
378-
memcpyiterAir and itself
379-
memory dummy and access adapter air
380-
381-
bruh, seems that everything is wrong... WHATS WRONG WITH THE TIMESTAMPS MAN
382-
*/
383-
384-
// eprintln!(
385-
// "memory bridge data write_data: {:?}",
386-
// write_data
387-
// .iter()
388-
// .map(|x| x.clone().map(|y| y * (AB::Expr::from_canonical_u32(1))))
389-
// .collect::<Vec<_>>()
390-
// );
391-
// Write final data to registers
392-
// write_data_pairs.iter().for_each(|(prev_data, next_data)| {
393-
// eprintln!(
394-
// "prev_data: {:?}, next_data: {:?}",
395-
// prev_data.map(|x| x * (AB::Expr::from_canonical_u32(1))),
396-
// next_data.map(|x| x * (AB::Expr::from_canonical_u32(1))),
397-
// );
398-
// });
399-
400-
// is timestamping off, is it pointer is off?
362+
// is timestamping off, is it pointer is off, for small source values
401363
write_data.iter().enumerate().for_each(|(idx, data)| {
402364
self.memory_bridge
403365
.write(
@@ -609,6 +571,7 @@ where
609571
record.inner.shift = shift;
610572
record.inner.from_pc = *state.pc;
611573
record.inner.from_timestamp = state.memory.timestamp;
574+
eprintln!("state.memory.timestamp: {:?}", state.memory.timestamp);
612575
record.inner.dest = dest;
613576
record.inner.source = source;
614577
record.inner.len = len;
@@ -631,24 +594,17 @@ where
631594
// we have saturating sub, which isnt a perfect sub,
632595
// 0, 4, 20
633596
// source is tOO SMALL, SO READING SAME DATA TWICE??
634-
if shift != 0 {
635-
record.var[0].data[3] = tracing_read(
636-
state.memory,
637-
RV32_MEMORY_AS,
638-
source - 4 * (source >= 4) as u32,
639-
&mut record.var[0].read_aux[3].prev_timestamp,
640-
);
641-
} else {
642-
record.var[0].data[3] = tracing_read(
643-
state.memory,
644-
RV32_MEMORY_AS,
645-
source - 4 * (source >= 4) as u32, // what happens when we read same memory twice? is it bc not constraining properly? since its the same piece of memory; this error will still happen, if source < 4? since no "previous" word
646-
&mut record.var[0].read_aux[3].prev_timestamp,
647-
);
648-
}
597+
598+
record.var[0].data[3] = tracing_read(
599+
state.memory,
600+
RV32_MEMORY_AS,
601+
source - 4 * (source >= 4) as u32,
602+
&mut record.var[0].read_aux[3].prev_timestamp,
603+
);
604+
649605
eprintln!(
650-
"record.var[0].read_aux[3].prev_timestamp: {:?}",
651-
record.var[0].read_aux[3].prev_timestamp
606+
"record.var[0].read_aux[3].prev_timestamp: {:?}, record.var[0].data[3]: {:?}",
607+
record.var[0].read_aux[3].prev_timestamp, record.var[0].data[3]
652608
);
653609

654610
// Fill record.var for the rest of the rows of iteration trace

0 commit comments

Comments
 (0)