Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f869b88
common: back BitTable with a machine-sized Word instead of F128
xrvdg Sep 23, 2026
e6a2e4c
common: rename ColumnBits to BitsIter
xrvdg Sep 23, 2026
dd89f3f
common: generalise BitsIter into StepIter yielding S-bit chunks
xrvdg Sep 23, 2026
448fe41
common: transpose BitTable via word-level 64x64 bit block transpose
xrvdg Sep 28, 2026
0abcaf0
common: add a test-only transpose_reference and drop F128 packing con…
xrvdg Sep 28, 2026
d626b3d
common: let bit_block_transpose handle dim1-row tiles and test d = 4
xrvdg Sep 28, 2026
e5543a0
common: support any power-of-two dim1 in bit_transpose
xrvdg Sep 28, 2026
b8418a6
common: reduce bit_transpose_blocks to a single butterfly sweep
xrvdg Sep 28, 2026
5b37d62
common: compute butterfly masks inline instead of precomputing them
xrvdg Sep 28, 2026
f891e96
common: add divan benchmark of bit_transpose against the reference
xrvdg Sep 28, 2026
2d7fe1e
fixup! common: add divan benchmark of bit_transpose against the refer…
xrvdg Sep 28, 2026
b0340d2
common: make BitTable generic over its storage and replace Transposed…
xrvdg Sep 28, 2026
403e34a
fixup! common: add divan benchmark of bit_transpose against the refer…
xrvdg Sep 29, 2026
8f8c5e5
common: switch Word to u128 and rotate bit indices ahead of coarse-to…
xrvdg Sep 29, 2026
435d745
common: run in-lane bit index rotation swaps on u64 lanes so they vec…
xrvdg Sep 30, 2026
c56514d
common: replace bit_transpose's derivation comment with a short doc c…
xrvdg Oct 1, 2026
783a529
common: move the t >= 7 gate from Shape to BitZParams behind a WordCo…
xrvdg Oct 5, 2026
f8405bc
fixup! common: move the t >= 7 gate from Shape to BitZParams behind a…
xrvdg Oct 6, 2026
706a2ae
gkr: move leaf construction into GrandProductCircuit::new, taking row…
xrvdg Oct 7, 2026
336e809
common: split BitTable into a shaped BitTable view and a geometry-onl…
xrvdg Oct 7, 2026
e1505fa
common: limit bit_transpose to whole 128x128 blocks and gate s < 7 in…
xrvdg Oct 7, 2026
202028a
Merge remote-tracking branch 'origin/main' into xr/bittable
xrvdg Oct 8, 2026
f801684
common: replace BitTable::transpose with a borrowed as_matrix view an…
xrvdg Oct 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ license.workspace = true
[features]
default = ["parallel"]
parallel = ["dep:rayon"]
# Exposes private kernels to `benches/`; not part of the public API.
bench = []

[dependencies]
crypto-primitives = { workspace = true }
bytemuck = {workspace = true}
field = { workspace = true, features = ["spongefish"] }
spongefish = { workspace = true }
poly = { workspace = true }
rayon = { workspace = true, optional = true }
num-traits = { workspace = true }

[dev-dependencies]
divan = { workspace = true }
rand = { workspace = true }

[[bench]]
name = "matrix"
harness = false
required-features = ["bench"]
49 changes: 49 additions & 0 deletions crates/common/benches/matrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Compare the blocked `bit_transpose` with the bit-at-a-time reference.
//!
//! Run with `cargo bench -p common --features bench --bench matrix`.
//! Both transpose a `128 x DIM2`-bit matrix (`dim2` contiguous), including
//! output allocation. Input generation runs outside the measured loop.

use common::matrix::bench::{bit_transpose, transpose_reference};
use divan::counter::BytesCount;
use divan::{Bencher, black_box};
use rand::rngs::StdRng;
use rand::{RngExt, SeedableRng};

const DIM1: usize = 128;
/// `2^20` bits per row: a 16 MiB matrix, well past the last-level cache.
const DIM2: usize = 1 << 20;
Comment on lines +13 to +15

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI uses 128 for rows, and 1 << 20 columns, and I understand DIM1 here is the columns, in that case, this benchmark should have DIM1 = 1 << 20 and DIM2 = 128 to represent realistic witnesses


fn main() {
let xs = input();
assert_eq!(
bit_transpose(&xs, DIM1, DIM2),
transpose_reference::<DIM1>(&xs),
"bit_transpose disagrees with the reference"
);
divan::main();
}

/// Seeded so every run transposes the same matrix.
fn input() -> Vec<u128> {
let mut rng = StdRng::seed_from_u64(0);
(0..DIM1 * DIM2 / u128::BITS as usize)
.map(|_| rng.random())
.collect()
}

#[divan::bench]
fn blocked(bencher: Bencher) {
let xs = input();
bencher
.counter(BytesCount::of_slice(&xs))
.bench(|| bit_transpose(black_box(&xs), DIM1, DIM2));
}

#[divan::bench]
fn reference(bencher: Bencher) {
let xs = input();
bencher
.counter(BytesCount::of_slice(&xs))
.bench(|| transpose_reference::<DIM1>(black_box(&xs)));
}
34 changes: 14 additions & 20 deletions crates/common/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poly::DenseMultilinearExtension;
#[cfg(feature = "parallel")]
use rayon::prelude::*;

use crate::{BitTable, LinearClaim, Shape, table::PACKED_BITS};
use crate::{BitTable, LinearClaim, Shape};

/// A round whose parts do not describe the shape they belong to.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand All @@ -30,23 +30,16 @@ pub fn fold_column(table: &BitTable<'_>, exponents: &[u128], column: usize) -> u
table
.column(column)
.iter()
.enumerate()
.map(|(index, element)| {
let base = index * PACKED_BITS;
[(0, element.lo), (64, element.hi)]
.into_iter()
.map(|(half, mut remaining)| {
let mut total = 0u128;
while remaining != 0 {
total += exponents[base + half + remaining.trailing_zeros() as usize];
// Clears the lowest set bit.
remaining &= remaining - 1;
}
total
})
.sum::<u128>()
.fold((0usize, 0u128), |(base, mut total), &element| {
let mut remaining = element;
while remaining != 0 {
total += exponents[base + remaining.trailing_zeros() as usize];
// Clears the lowest set bit.
remaining &= remaining - 1;
}
(base + BitTable::BITS, total)
})
.sum()
.1
}

/// Every column's fold, in column order.
Expand Down Expand Up @@ -190,6 +183,7 @@ mod tests {
use num_traits::{ConstOne, ConstZero};

use super::*;
const PACKED_BITS: usize = 128;
use crate::{BitZParams, Shape};

const Q114: u128 = (1 << 114) - 11;
Expand Down Expand Up @@ -237,7 +231,7 @@ mod tests {
let claim = claim(field_weights, vec![Fq::ONE; shape.columns()]);

let packed = witness(&shape, &[(1, 0), (5, 0), (127, 0), (64, 4)]);
let table = BitTable::new(shape, &packed).unwrap();
let table = BitTable::new(shape, bytemuck::cast_slice(&packed)).unwrap();

assert_eq!(
fold_column(&table, &claim.row_exponents(), 0),
Expand All @@ -257,7 +251,7 @@ mod tests {
);
let all: Vec<(usize, usize)> = (0..shape.rows()).map(|row| (row, 0)).collect();
let packed = witness(&shape, &all);
let table = BitTable::new(shape, &packed).unwrap();
let table = BitTable::new(shape, bytemuck::cast_slice(&packed)).unwrap();

assert_eq!(
fold_column(&table, &claim.row_exponents(), 0),
Expand All @@ -278,7 +272,7 @@ mod tests {
.map(|row| (row, 6))
.collect();
let packed = witness(&shape, &bits);
let table = BitTable::new(shape, &packed).unwrap();
let table = BitTable::new(shape, bytemuck::cast_slice(&packed)).unwrap();

let expected: u128 = (0..shape.rows())
.filter(|&row| table.bit(6, row))
Expand Down
4 changes: 3 additions & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

pub mod claim;
pub mod fold;
pub mod matrix;
pub mod opening;
pub mod params;
pub mod shape;
Expand All @@ -16,10 +17,11 @@ pub use claim::{ClaimError, LinearClaim, Root};
pub use fold::{
Fold, FoldError, column_images, fold_column, fold_columns, reconstruct, row_images,
};
pub use matrix::BitMatrix;
pub use opening::OpeningQuery;
pub use params::{BitZParams, ParamsError, VirtualParams, VirtualParamsError};
pub use shape::{Shape, ShapeError};
pub use table::{BitTable, TableError, TransposeError, TransposedBitTable};
pub use table::{BitTable, TableError};
pub use virtual_map::{
TransposedWeights, VirtualMap, VirtualMapError, VirtualStatement, VirtualStatementError,
};
Expand Down
Loading
Loading