sp1_core_machine/operations/
or.rs1use p3_field::{AbstractField, Field};
2use sp1_core_executor::{events::ByteRecord, ByteOpcode, ExecutionRecord};
3use sp1_derive::AlignedBorrow;
4use sp1_primitives::consts::WORD_SIZE;
5use sp1_stark::{air::SP1AirBuilder, Word};
6
7#[derive(AlignedBorrow, Default, Debug, Clone, Copy)]
9#[repr(C)]
10pub struct OrOperation<T> {
11 pub value: Word<T>,
13}
14
15impl<F: Field> OrOperation<F> {
16 pub fn populate(&mut self, record: &mut ExecutionRecord, x: u32, y: u32) -> u32 {
17 let expected = x | y;
18 let x_bytes = x.to_le_bytes();
19 let y_bytes = y.to_le_bytes();
20 for i in 0..WORD_SIZE {
21 self.value[i] = F::from_canonical_u8(x_bytes[i] | y_bytes[i]);
22 record.lookup_or(x_bytes[i], y_bytes[i]);
23 }
24 expected
25 }
26
27 pub fn eval<AB: SP1AirBuilder>(
28 builder: &mut AB,
29 a: Word<AB::Var>,
30 b: Word<AB::Var>,
31 cols: OrOperation<AB::Var>,
32 is_real: AB::Var,
33 ) {
34 for i in 0..WORD_SIZE {
35 builder.send_byte(
36 AB::F::from_canonical_u32(ByteOpcode::OR as u32),
37 cols.value[i],
38 a[i],
39 b[i],
40 is_real,
41 );
42 }
43 }
44}