Skip to content

Commit 030be7f

Browse files
committed
chore: use a constant for log2(num_limbs)
1 parent 2ccb630 commit 030be7f

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/rv32im/circuit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ num-bigint.workspace = true
3030
num-integer.workspace = true
3131
serde = { workspace = true, features = ["derive", "std"] }
3232
serde-big-array.workspace = true
33+
static_assertions.workspace = true
3334

3435
[dev-dependencies]
3536
openvm-stark-sdk = { workspace = true }

extensions/rv32im/circuit/src/hintstore/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ use openvm_stark_backend::{
3636
p3_air::{Air, AirBuilder, BaseAir},
3737
p3_field::{Field, FieldAlgebra, PrimeField32},
3838
p3_matrix::{dense::RowMajorMatrix, Matrix},
39-
p3_util::log2_strict_usize,
4039
prover::types::AirProofInput,
4140
rap::{AnyRap, BaseAirWithPublicValues, PartitionedBaseAir},
4241
Chip, ChipUsageGetter,
4342
};
4443
use serde::{Deserialize, Serialize};
44+
use static_assertions::const_assert_eq;
4545

4646
use crate::adapters::{compose, decompose};
4747

@@ -89,6 +89,9 @@ impl<F: Field> BaseAir<F> for Rv32HintStoreAir {
8989
impl<F: Field> BaseAirWithPublicValues<F> for Rv32HintStoreAir {}
9090
impl<F: Field> PartitionedBaseAir<F> for Rv32HintStoreAir {}
9191

92+
const LOG2_RV32_REGISTER_NUM_LIMBS: usize = 2;
93+
const_assert_eq!(1 << LOG2_RV32_REGISTER_NUM_LIMBS, RV32_REGISTER_NUM_LIMBS);
94+
9295
impl<AB: InteractionBuilder> Air<AB> for Rv32HintStoreAir {
9396
fn eval(&self, builder: &mut AB) {
9497
let main = builder.main();
@@ -235,7 +238,7 @@ impl<AB: InteractionBuilder> Air<AB> for Rv32HintStoreAir {
235238
.range_check::<AB::Expr>(
236239
local_cols.mem_ptr_limbs[0]
237240
* AB::F::from_canonical_usize(RV32_REGISTER_NUM_LIMBS).inverse(),
238-
RV32_CELL_BITS - log2_strict_usize(RV32_REGISTER_NUM_LIMBS),
241+
RV32_CELL_BITS - LOG2_RV32_REGISTER_NUM_LIMBS,
239242
)
240243
.eval(builder, is_start.clone());
241244
// We only check this on `is_start` since it is implied on non-start rows by the next_mem_ptr = mem_ptr + 4 constraint below
@@ -482,8 +485,8 @@ impl<F: PrimeField32> Rv32HintStoreChip<F> {
482485
rem_words_msl << (RV32_REGISTER_NUM_LIMBS * RV32_CELL_BITS - pointer_max_bits),
483486
);
484487
memory.range_checker().add_count(
485-
(mem_ptr & ((1 << RV32_CELL_BITS) - 1)) >> 2,
486-
RV32_CELL_BITS - 2,
488+
(mem_ptr & ((1 << RV32_CELL_BITS) - 1)) >> LOG2_RV32_REGISTER_NUM_LIMBS,
489+
RV32_CELL_BITS - LOG2_RV32_REGISTER_NUM_LIMBS,
487490
);
488491
for (i, &(data, write)) in record.hints.iter().enumerate() {
489492
for half in 0..(RV32_REGISTER_NUM_LIMBS / 2) {

0 commit comments

Comments
 (0)