Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32-in 64-out unsigned multiplication chip #141

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions alu_u32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub mod com;
pub mod div;
pub mod lt;
pub mod mul;
pub mod mul64;
pub mod shift;
pub mod sub;
3 changes: 1 addition & 2 deletions alu_u32/src/mul/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use alloc::vec::Vec;
use columns::{Mul32Cols, MUL_COL_MAP, NUM_MUL_COLS};
use valida_bus::MachineWithGeneralBus;
use valida_cpu::MachineWithCpuChip;
use valida_machine::{instructions, Chip, Instruction, Interaction, Mulhs, Mulhu, Operands, Word};
use valida_machine::{instructions, Chip, Instruction, Interaction, Mulhs, Mulhu, Operands, StarkConfig, Word};
use valida_opcodes::{MUL32, MULHS32, MULHU32};
use valida_range::MachineWithRangeChip;

use core::borrow::BorrowMut;
use p3_air::VirtualPairCol;
use p3_field::{AbstractField, Field, PrimeField};
use p3_matrix::dense::RowMajorMatrix;
use valida_machine::StarkConfig;

pub mod columns;
pub mod stark;
Expand Down
29 changes: 29 additions & 0 deletions alu_u32/src/mul64/columns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extern crate alloc;

use alloc::borrow::{Borrow, BorrowMut};
use core::mem::{size_of, transmute};
use valida_derive::AlignedBorrow;
use valida_machine::Word;
use valida_util::indices_arr;

#[derive(Default)]
pub struct Word64<T> {
pub most_significant: Word<T>,
pub least_significant: Word<T>,
}

#[derive(AlignedBorrow, Default)]
pub struct Mul64Cols<T> {
pub input_1: Word<T>,
pub input_2: Word<T>,
pub output: Word64<T>,
// TODO
}

pub const NUM_MUL64_COLS: usize = size_of::<Mul64Cols<u8>>();
pub const MUL64_COL_MAP: Mul64Cols<usize> = make_col_map();

const fn make_col_map() -> Mul64Cols<usize> {
let indices_arr = indices_arr::<NUM_MUL64_COLS>();
unsafe { transmute::<[usize; NUM_MUL64_COLS], Mul64Cols<usize>>(indices_arr) }
}
56 changes: 56 additions & 0 deletions alu_u32/src/mul64/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
extern crate alloc;

pub mod columns;
pub mod stark;

use alloc::borrow::Borrow;
use alloc::vec::Vec;
use columns::{Mul64Cols, MUL64_COL_MAP, NUM_MUL64_COLS, Word64};
use valida_machine::{Chip, Interaction, Machine, Word, StarkConfig};

use p3_field::{AbstractField, Field, PrimeField};
use p3_matrix::dense::RowMajorMatrix;

pub struct Operation {
pub inputs: (Word<u8>, Word<u8>),
pub output: Word64<u8>,
}

pub struct Mul64Chip {
pub operations: Vec<Operation>,
}

impl<M, SC> Chip<M, SC> for Mul64Chip
where
M: Machine<SC::Val>,
SC: StarkConfig,
{
fn generate_trace(&self, _machine: &M) -> RowMajorMatrix<SC::Val> {
todo!()
}

fn global_receives(&self, machine: &M) -> Vec<Interaction<SC::Val>> {
todo!()
}
}

impl Mul64Chip {
fn op_to_row<F>(&self, op: &Operation, cosl: &mut Mul64Cols<F>)
where
F: PrimeField,
{
todo!()
}

fn set_cols<F>(&self, a: &Word<u8>, b: &Word<u8>, c: &Word64<u8>, cols: &mut Mul64Cols<F>)
where
F: PrimeField,
{
todo!()
}
}

pub trait MachineWithMul64Chip<F: Field>: Machine<F> {
fn mul_u64(&self) -> &Mul64Chip;
fn mul_u64_mut(&mut self) -> &mut Mul64Chip;
}
22 changes: 22 additions & 0 deletions alu_u32/src/mul64/stark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use super::columns::Mul64Cols;
use super::Mul64Chip;

use crate::mul64::columns::NUM_MUL64_COLS;
use p3_air::{Air, AirBuilder, BaseAir};
use p3_field::{PrimeField};

impl<F> BaseAir<F> for Mul64Chip {
fn width(&self) -> usize {
NUM_MUL64_COLS
}
}

impl<F, AB> Air<AB> for Mul64Chip
where
F: PrimeField,
AB: AirBuilder<F = F>,
{
fn eval(&self, _builder: &mut AB) {
todo!()
}
}
Loading