Skip to content

Commit

Permalink
Add operand_chunks method to JoltInstruction; add chunk_operand funct…
Browse files Browse the repository at this point in the history
…ion to instruction_utils
  • Loading branch information
moodlezoup committed Nov 20, 2023
1 parent 54a807e commit c4c52c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions jolt-core/src/jolt/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub trait JoltInstruction {
fn g_poly_degree(&self, C: usize) -> usize;
fn subtables<F: PrimeField>(&self, C: usize) -> Vec<Box<dyn LassoSubtable<F>>>;
fn to_indices(&self, C: usize, log_M: usize) -> Vec<usize>;
fn operand_chunks(&self, C: usize, log_M: usize) -> (Vec<u64>, Vec<u64>);
}

pub trait Opcode {
Expand Down
10 changes: 10 additions & 0 deletions jolt-core/src/utils/instruction_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ pub fn concatenate_lookups<F: PrimeField>(vals: &[F], C: usize, shift_bits: usiz
sum
}

pub fn chunk_operand(x: u64, num_chunks: usize, bits_per_chunk: usize) -> Vec<u64> {
let bit_mask = (1 << bits_per_chunk) - 1;
(0..num_chunks)
.map(|i| {
let shift = ((num_chunks - i - 1) * bits_per_chunk) as u32;
x.checked_shr(shift).unwrap_or(0) & bit_mask;
})
.collect()
}

pub fn chunk_and_concatenate_operands(x: u64, y: u64, C: usize, log_M: usize) -> Vec<usize> {
let operand_bits: usize = log_M / 2;
let operand_bit_mask: usize = (1 << operand_bits) - 1;
Expand Down

0 comments on commit c4c52c5

Please sign in to comment.