Skip to content

Commit 82e0d6c

Browse files
committed
Reapply "fix: working for aligned memcpy; still needs to modify design for small source values"
This reverts commit a6b334e.
1 parent a6b334e commit 82e0d6c

File tree

1 file changed

+31
-87
lines changed

1 file changed

+31
-87
lines changed

extensions/memcpy/circuit/src/iteration.rs

Lines changed: 31 additions & 87 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)
@@ -328,12 +326,14 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
328326
&local.read_aux[idx],
329327
)
330328
.eval(builder, is_valid_read.clone());
331-
eprintln!(
332-
"local.source: {:?}, data: {:?}, local.source - AB::Expr::from_canonical_usize(16 - idx * 4): {:?}",
333-
local.source * AB::Expr::from_canonical_u32(1),
334-
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)
336-
);
329+
// eprintln!(
330+
// "local.source: {:?}, data: {:?}, local.source - AB::Expr::from_canonical_usize(16 - idx * 4): {:?}, timestamp_pp: {:?}, is_valid_read: {:?}",
331+
// local.source * AB::Expr::from_canonical_u32(1),
332+
// data.clone().map(|x| x * (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()
336+
// );
337337
});
338338

339339
write_data.iter().enumerate().for_each(|(idx, data)| {
@@ -379,63 +379,7 @@ impl<AB: InteractionBuilder> Air<AB> for MemcpyIterAir {
379379
// error seems to be off by one for timestamp again, or off by 17 or 21??
380380
// timestamps are inconsistent everywhere...
381381

382-
/*
383-
heres the plan:
384-
identify everywhere where timeststamps are used; where theyre written to (tracing_read) etc.
385-
walk through each component, and take notes about how timestamp is incrementing in each portion
386-
*/
387-
388-
/*
389-
off by one:
390-
between memcpyiter Air and itself
391-
392-
off by 16:
393-
memcpyiter air and itself
394-
off by 17:
395-
between memoryDummyAir and accessAdapterAir
396-
397-
off by 21:
398-
memcpyiterAir and itself
399-
memory dummy and access adapter air
400-
401-
bruh, seems that everything is wrong... WHATS WRONG WITH THE TIMESTAMPS MAN
402-
*/
403-
404-
// eprintln!(
405-
// "memory bridge data write_data: {:?}",
406-
// write_data
407-
// .iter()
408-
// .map(|x| x.clone().map(|y| y * (AB::Expr::from_canonical_u32(1))))
409-
// .collect::<Vec<_>>()
410-
// );
411-
// Write final data to registers
412-
// write_data_pairs.iter().for_each(|(prev_data, next_data)| {
413-
// eprintln!(
414-
// "prev_data: {:?}, next_data: {:?}",
415-
// prev_data.map(|x| x * (AB::Expr::from_canonical_u32(1))),
416-
// next_data.map(|x| x * (AB::Expr::from_canonical_u32(1))),
417-
// );
418-
// });
419-
420-
// is timestamping off, is it pointer is off?
421-
write_data.iter().enumerate().for_each(|(idx, data)| {
422-
self.memory_bridge
423-
.write(
424-
MemoryAddress::new(
425-
AB::Expr::from_canonical_u32(RV32_MEMORY_AS),
426-
local.dest - AB::Expr::from_canonical_usize(16 - idx * 4),
427-
),
428-
data.clone(),
429-
timestamp_pp(AB::Expr::ONE * (local.is_valid_not_start)),
430-
&local.write_aux[idx],
431-
)
432-
.eval(builder, local.is_valid_not_start);
433-
// eprintln!(
434-
// "Eval: write_data: {:?}, timestamp_pp: {:?}",
435-
// data.clone().map(|x| x * (AB::Expr::from_canonical_u32(1))),
436-
// timestamp_pp(AB::Expr::ZERO * (local.is_valid_not_start))
437-
// );
438-
});
382+
// is timestamping off, is it pointer is off, for small source values
439383

440384
// Range check len
441385
let len_bits_limit = [
@@ -651,25 +595,25 @@ where
651595
// we have saturating sub, which isnt a perfect sub,
652596
// 0, 4, 20
653597
// source is tOO SMALL, SO READING SAME DATA TWICE??
654-
if shift != 0 {
655-
record.var[0].data[3] = tracing_read(
656-
state.memory,
657-
RV32_MEMORY_AS,
658-
source - 4 * (source >= 4) as u32,
659-
&mut record.var[0].read_aux[3].prev_timestamp,
660-
);
661-
} else {
662-
record.var[0].data[3] = tracing_read(
663-
state.memory,
664-
RV32_MEMORY_AS,
665-
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
666-
&mut record.var[0].read_aux[3].prev_timestamp,
598+
599+
record.var[0].data[3] = tracing_read(
600+
state.memory,
601+
RV32_MEMORY_AS,
602+
source - 4 * (source >= 4) as u32,
603+
&mut record.var[0].read_aux[3].prev_timestamp,
604+
);
605+
if source < 4 {
606+
eprintln!("preflight shift: {:?}", shift);
607+
eprintln!("preflight, before saturating sub source: {:?}", source);
608+
eprintln!("preflight, after saturating sub source: {:?}", source);
609+
}
610+
if record.var[0].read_aux[3].prev_timestamp == 0 {
611+
eprintln!(
612+
"preflight, record.var[0].read_aux[3].prev_timestamp: {:?}",
613+
record.var[0].read_aux[3].prev_timestamp
667614
);
615+
eprintln!("source: {:?}, dest: {:?}, shift: {:?}", source, dest, shift);
668616
}
669-
eprintln!(
670-
"record.var[0].read_aux[3].prev_timestamp: {:?}",
671-
record.var[0].read_aux[3].prev_timestamp
672-
);
673617

674618
// Fill record.var for the rest of the rows of iteration trace
675619
let mut idx = 1;

0 commit comments

Comments
 (0)