Skip to content

Commit

Permalink
removed last eq lookup in comparison instructions (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
quangvdao authored Sep 30, 2024
1 parent 7625b1d commit 6dac58c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/bge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<const WORD_SIZE: usize> JoltInstruction for BGEInstruction<WORD_SIZE> {
(Box::new(LeftMSBSubtable::new()), SubtableIndices::from(0)),
(Box::new(RightMSBSubtable::new()), SubtableIndices::from(0)),
(Box::new(LtuSubtable::new()), SubtableIndices::from(1..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(1..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(1..C - 1)),
(Box::new(LtAbsSubtable::new()), SubtableIndices::from(0)),
(Box::new(EqAbsSubtable::new()), SubtableIndices::from(0)),
]
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/instruction/bgeu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<const WORD_SIZE: usize> JoltInstruction for BGEUInstruction<WORD_SIZE> {
) -> Vec<(Box<dyn LassoSubtable<F>>, SubtableIndices)> {
vec![
(Box::new(LtuSubtable::new()), SubtableIndices::from(0..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(0..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(0..C - 1)),
]
}

Expand Down
10 changes: 6 additions & 4 deletions jolt-core/src/jolt/instruction/slt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ impl<const WORD_SIZE: usize> JoltInstruction for SLTInstruction<WORD_SIZE> {
// Accumulator for EQ(x_{<s}, y_{<s})
let mut eq_prod = eq_abs[0];

for (ltu_i, eq_i) in ltu.iter().zip(eq) {
ltu_sum += *ltu_i * eq_prod;
eq_prod *= *eq_i;
for i in 0..C - 2 {
ltu_sum += ltu[i] * eq_prod;
eq_prod *= eq[i];
}
// Do not need to update `eq_prod` for the last iteration
ltu_sum += ltu[C - 2] * eq_prod;

// x_s * (1 - y_s) + EQ(x_s, y_s) * LTU(x_{<s}, y_{<s})
left_msb[0] * (F::one() - right_msb[0])
Expand All @@ -59,7 +61,7 @@ impl<const WORD_SIZE: usize> JoltInstruction for SLTInstruction<WORD_SIZE> {
(Box::new(LeftMSBSubtable::new()), SubtableIndices::from(0)),
(Box::new(RightMSBSubtable::new()), SubtableIndices::from(0)),
(Box::new(LtuSubtable::new()), SubtableIndices::from(1..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(1..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(1..C - 1)),
(Box::new(LtAbsSubtable::new()), SubtableIndices::from(0)),
(Box::new(EqAbsSubtable::new()), SubtableIndices::from(0)),
]
Expand Down
7 changes: 4 additions & 3 deletions jolt-core/src/jolt/instruction/sltu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ impl<const WORD_SIZE: usize> JoltInstruction for SLTUInstruction<WORD_SIZE> {
let mut sum = F::zero();
let mut eq_prod = F::one();

for i in 0..C {
for i in 0..C - 1 {
sum += ltu[i] * eq_prod;
eq_prod *= eq[i];
}
sum
// Do not need to update `eq_prod` for the last iteration
sum + ltu[C - 1] * eq_prod
}

fn g_poly_degree(&self, C: usize) -> usize {
Expand All @@ -46,7 +47,7 @@ impl<const WORD_SIZE: usize> JoltInstruction for SLTUInstruction<WORD_SIZE> {
) -> Vec<(Box<dyn LassoSubtable<F>>, SubtableIndices)> {
vec![
(Box::new(LtuSubtable::new()), SubtableIndices::from(0..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(0..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(0..C - 1)),
]
}

Expand Down

0 comments on commit 6dac58c

Please sign in to comment.