sp1_core_machine/control_flow/branch/columns.rs
1use sp1_derive::AlignedBorrow;
2use sp1_stark::Word;
3use std::mem::size_of;
4
5use crate::operations::BabyBearWordRangeChecker;
6
7pub const NUM_BRANCH_COLS: usize = size_of::<BranchColumns<u8>>();
8
9/// The column layout for branching.
10#[derive(AlignedBorrow, Default, Debug, Clone, Copy)]
11#[repr(C)]
12pub struct BranchColumns<T> {
13 /// The current program counter.
14 pub pc: Word<T>,
15 pub pc_range_checker: BabyBearWordRangeChecker<T>,
16
17 /// The next program counter.
18 pub next_pc: Word<T>,
19 pub next_pc_range_checker: BabyBearWordRangeChecker<T>,
20
21 /// The value of the first operand.
22 pub op_a_value: Word<T>,
23 /// The value of the second operand.
24 pub op_b_value: Word<T>,
25 /// The value of the third operand.
26 pub op_c_value: Word<T>,
27
28 /// Whether the first operand is register 0.
29 pub op_a_0: T,
30
31 /// Branch Instructions.
32 pub is_beq: T,
33 pub is_bne: T,
34 pub is_blt: T,
35 pub is_bge: T,
36 pub is_bltu: T,
37 pub is_bgeu: T,
38
39 /// The is_branching column is equal to:
40 ///
41 /// > is_beq & a_eq_b ||
42 /// > is_bne & (a_lt_b | a_gt_b) ||
43 /// > (is_blt | is_bltu) & a_lt_b ||
44 /// > (is_bge | is_bgeu) & (a_eq_b | a_gt_b)
45 pub is_branching: T,
46
47 /// The not branching column is equal to:
48 ///
49 /// > is_beq & !a_eq_b ||
50 /// > is_bne & !(a_lt_b | a_gt_b) ||
51 /// > (is_blt | is_bltu) & !a_lt_b ||
52 /// > (is_bge | is_bgeu) & !(a_eq_b | a_gt_b)
53 ///
54 /// Note that we probably can do away with this column and just use !is_branching.
55 /// However, the branching related constraints were auditted twice when they were part of the
56 /// CPU table, so I'm preserving those columns/constraints for now.
57 pub not_branching: T,
58
59 /// Whether a equals b.
60 pub a_eq_b: T,
61
62 /// Whether a is greater than b.
63 pub a_gt_b: T,
64
65 /// Whether a is less than b.
66 pub a_lt_b: T,
67}