mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-05-20 16:59:44 +00:00
Rename arithmetic unit to ALU (#496)
This commit is contained in:
parent
9516e14c3e
commit
bedd2aa711
@ -7,7 +7,7 @@ use plonky2::plonk::circuit_builder::CircuitBuilder;
|
|||||||
use plonky2::plonk::plonk_common::reduce_with_powers_ext_recursive;
|
use plonky2::plonk::plonk_common::reduce_with_powers_ext_recursive;
|
||||||
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
||||||
|
|
||||||
use crate::registers::arithmetic::*;
|
use crate::registers::alu::*;
|
||||||
use crate::registers::NUM_COLUMNS;
|
use crate::registers::NUM_COLUMNS;
|
||||||
|
|
||||||
pub(crate) fn generate_addition<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
pub(crate) fn generate_addition<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
||||||
@ -6,7 +6,7 @@ use plonky2::iop::ext_target::ExtensionTarget;
|
|||||||
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
||||||
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
||||||
|
|
||||||
use crate::registers::arithmetic::*;
|
use crate::registers::alu::*;
|
||||||
use crate::registers::NUM_COLUMNS;
|
use crate::registers::NUM_COLUMNS;
|
||||||
|
|
||||||
pub(crate) fn generate_division<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
pub(crate) fn generate_division<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
||||||
@ -7,16 +7,16 @@ use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsume
|
|||||||
use starky::vars::StarkEvaluationTargets;
|
use starky::vars::StarkEvaluationTargets;
|
||||||
use starky::vars::StarkEvaluationVars;
|
use starky::vars::StarkEvaluationVars;
|
||||||
|
|
||||||
use crate::arithmetic::addition::{eval_addition, eval_addition_recursively, generate_addition};
|
use crate::alu::addition::{eval_addition, eval_addition_recursively, generate_addition};
|
||||||
use crate::arithmetic::division::{eval_division, eval_division_recursively, generate_division};
|
use crate::alu::division::{eval_division, eval_division_recursively, generate_division};
|
||||||
use crate::arithmetic::multiplication::{
|
use crate::alu::multiplication::{
|
||||||
eval_multiplication, eval_multiplication_recursively, generate_multiplication,
|
eval_multiplication, eval_multiplication_recursively, generate_multiplication,
|
||||||
};
|
};
|
||||||
use crate::arithmetic::subtraction::{
|
use crate::alu::subtraction::{
|
||||||
eval_subtraction, eval_subtraction_recursively, generate_subtraction,
|
eval_subtraction, eval_subtraction_recursively, generate_subtraction,
|
||||||
};
|
};
|
||||||
use crate::public_input_layout::NUM_PUBLIC_INPUTS;
|
use crate::public_input_layout::NUM_PUBLIC_INPUTS;
|
||||||
use crate::registers::arithmetic::*;
|
use crate::registers::alu::*;
|
||||||
use crate::registers::NUM_COLUMNS;
|
use crate::registers::NUM_COLUMNS;
|
||||||
|
|
||||||
mod addition;
|
mod addition;
|
||||||
@ -24,7 +24,7 @@ mod division;
|
|||||||
mod multiplication;
|
mod multiplication;
|
||||||
mod subtraction;
|
mod subtraction;
|
||||||
|
|
||||||
pub(crate) fn generate_arithmetic_unit<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
pub(crate) fn generate_alu<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
||||||
if values[IS_ADD].is_one() {
|
if values[IS_ADD].is_one() {
|
||||||
generate_addition(values);
|
generate_addition(values);
|
||||||
} else if values[IS_SUB].is_one() {
|
} else if values[IS_SUB].is_one() {
|
||||||
@ -36,7 +36,7 @@ pub(crate) fn generate_arithmetic_unit<F: PrimeField64>(values: &mut [F; NUM_COL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eval_arithmetic_unit<F: Field, P: PackedField<Scalar = F>>(
|
pub(crate) fn eval_alu<F: Field, P: PackedField<Scalar = F>>(
|
||||||
vars: StarkEvaluationVars<F, P, NUM_COLUMNS, NUM_PUBLIC_INPUTS>,
|
vars: StarkEvaluationVars<F, P, NUM_COLUMNS, NUM_PUBLIC_INPUTS>,
|
||||||
yield_constr: &mut ConstraintConsumer<P>,
|
yield_constr: &mut ConstraintConsumer<P>,
|
||||||
) {
|
) {
|
||||||
@ -54,7 +54,7 @@ pub(crate) fn eval_arithmetic_unit<F: Field, P: PackedField<Scalar = F>>(
|
|||||||
eval_division(local_values, yield_constr);
|
eval_division(local_values, yield_constr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eval_arithmetic_unit_recursively<F: RichField + Extendable<D>, const D: usize>(
|
pub(crate) fn eval_alu_recursively<F: RichField + Extendable<D>, const D: usize>(
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
vars: StarkEvaluationTargets<D, NUM_COLUMNS, NUM_PUBLIC_INPUTS>,
|
vars: StarkEvaluationTargets<D, NUM_COLUMNS, NUM_PUBLIC_INPUTS>,
|
||||||
yield_constr: &mut RecursiveConstraintConsumer<F, D>,
|
yield_constr: &mut RecursiveConstraintConsumer<F, D>,
|
||||||
@ -6,7 +6,7 @@ use plonky2::iop::ext_target::ExtensionTarget;
|
|||||||
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
||||||
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
||||||
|
|
||||||
use crate::registers::arithmetic::*;
|
use crate::registers::alu::*;
|
||||||
use crate::registers::NUM_COLUMNS;
|
use crate::registers::NUM_COLUMNS;
|
||||||
|
|
||||||
pub(crate) fn generate_multiplication<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
pub(crate) fn generate_multiplication<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
||||||
@ -6,7 +6,7 @@ use plonky2::iop::ext_target::ExtensionTarget;
|
|||||||
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
||||||
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
||||||
|
|
||||||
use crate::registers::arithmetic::*;
|
use crate::registers::alu::*;
|
||||||
use crate::registers::NUM_COLUMNS;
|
use crate::registers::NUM_COLUMNS;
|
||||||
|
|
||||||
pub(crate) fn generate_subtraction<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
pub(crate) fn generate_subtraction<F: PrimeField64>(values: &mut [F; NUM_COLUMNS]) {
|
||||||
@ -2,7 +2,7 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
mod arithmetic;
|
mod alu;
|
||||||
mod core_registers;
|
mod core_registers;
|
||||||
mod memory;
|
mod memory;
|
||||||
mod permutation_unit;
|
mod permutation_unit;
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
//! Arithmetic unit.
|
//! Arithmetic and logic unit.
|
||||||
|
|
||||||
pub(crate) const IS_ADD: usize = super::START_ARITHMETIC;
|
pub(crate) const IS_ADD: usize = super::START_ALU;
|
||||||
pub(crate) const IS_SUB: usize = IS_ADD + 1;
|
pub(crate) const IS_SUB: usize = IS_ADD + 1;
|
||||||
pub(crate) const IS_MUL: usize = IS_SUB + 1;
|
pub(crate) const IS_MUL: usize = IS_SUB + 1;
|
||||||
pub(crate) const IS_DIV: usize = IS_MUL + 1;
|
pub(crate) const IS_DIV: usize = IS_MUL + 1;
|
||||||
|
|
||||||
const START_SHARED_COLS: usize = IS_DIV + 1;
|
const START_SHARED_COLS: usize = IS_DIV + 1;
|
||||||
|
|
||||||
/// Within the arithmetic unit, there are shared columns which can be used by any arithmetic
|
/// Within the ALU, there are shared columns which can be used by any arithmetic/logic
|
||||||
/// circuit, depending on which one is active this cycle.
|
/// circuit, depending on which one is active this cycle.
|
||||||
// Can be increased as needed as other operations are implemented.
|
// Can be increased as needed as other operations are implemented.
|
||||||
const NUM_SHARED_COLS: usize = 3;
|
const NUM_SHARED_COLS: usize = 3;
|
||||||
@ -26,7 +26,7 @@ pub(crate) const COL_ADD_INPUT_3: usize = shared_col(2);
|
|||||||
|
|
||||||
// Note: Addition outputs three 16-bit chunks, and since these values need to be range-checked
|
// Note: Addition outputs three 16-bit chunks, and since these values need to be range-checked
|
||||||
// anyway, we might as well use the range check unit's columns as our addition outputs. So the
|
// anyway, we might as well use the range check unit's columns as our addition outputs. So the
|
||||||
// three proceeding columns are basically aliases, not columns owned by the arithmetic unit.
|
// three proceeding columns are basically aliases, not columns owned by the ALU.
|
||||||
/// The first 16-bit chunk of the output, based on little-endian ordering.
|
/// The first 16-bit chunk of the output, based on little-endian ordering.
|
||||||
pub(crate) const COL_ADD_OUTPUT_1: usize = super::range_check_16::col_rc_16_input(0);
|
pub(crate) const COL_ADD_OUTPUT_1: usize = super::range_check_16::col_rc_16_input(0);
|
||||||
/// The second 16-bit chunk of the output, based on little-endian ordering.
|
/// The second 16-bit chunk of the output, based on little-endian ordering.
|
||||||
@ -34,4 +34,4 @@ pub(crate) const COL_ADD_OUTPUT_2: usize = super::range_check_16::col_rc_16_inpu
|
|||||||
/// The third 16-bit chunk of the output, based on little-endian ordering.
|
/// The third 16-bit chunk of the output, based on little-endian ordering.
|
||||||
pub(crate) const COL_ADD_OUTPUT_3: usize = super::range_check_16::col_rc_16_input(2);
|
pub(crate) const COL_ADD_OUTPUT_3: usize = super::range_check_16::col_rc_16_input(2);
|
||||||
|
|
||||||
pub(super) const END: usize = super::START_ARITHMETIC + NUM_SHARED_COLS;
|
pub(super) const END: usize = super::START_ALU + NUM_SHARED_COLS;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
pub(crate) mod arithmetic;
|
pub(crate) mod alu;
|
||||||
pub(crate) mod boolean;
|
pub(crate) mod boolean;
|
||||||
pub(crate) mod core;
|
pub(crate) mod core;
|
||||||
pub(crate) mod logic;
|
pub(crate) mod logic;
|
||||||
@ -8,8 +8,8 @@ pub(crate) mod permutation;
|
|||||||
pub(crate) mod range_check_16;
|
pub(crate) mod range_check_16;
|
||||||
pub(crate) mod range_check_degree;
|
pub(crate) mod range_check_degree;
|
||||||
|
|
||||||
const START_ARITHMETIC: usize = 0;
|
const START_ALU: usize = 0;
|
||||||
const START_BOOLEAN: usize = arithmetic::END;
|
const START_BOOLEAN: usize = alu::END;
|
||||||
const START_CORE: usize = boolean::END;
|
const START_CORE: usize = boolean::END;
|
||||||
const START_LOGIC: usize = core::END;
|
const START_LOGIC: usize = core::END;
|
||||||
const START_LOOKUP: usize = logic::END;
|
const START_LOOKUP: usize = logic::END;
|
||||||
|
|||||||
@ -10,9 +10,7 @@ use starky::stark::Stark;
|
|||||||
use starky::vars::StarkEvaluationTargets;
|
use starky::vars::StarkEvaluationTargets;
|
||||||
use starky::vars::StarkEvaluationVars;
|
use starky::vars::StarkEvaluationVars;
|
||||||
|
|
||||||
use crate::arithmetic::{
|
use crate::alu::{eval_alu, eval_alu_recursively, generate_alu};
|
||||||
eval_arithmetic_unit, eval_arithmetic_unit_recursively, generate_arithmetic_unit,
|
|
||||||
};
|
|
||||||
use crate::core_registers::{
|
use crate::core_registers::{
|
||||||
eval_core_registers, eval_core_registers_recursively, generate_first_row_core_registers,
|
eval_core_registers, eval_core_registers_recursively, generate_first_row_core_registers,
|
||||||
generate_next_row_core_registers,
|
generate_next_row_core_registers,
|
||||||
@ -38,7 +36,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SystemZero<F, D> {
|
|||||||
|
|
||||||
let mut row = [F::ZERO; NUM_COLUMNS];
|
let mut row = [F::ZERO; NUM_COLUMNS];
|
||||||
generate_first_row_core_registers(&mut row);
|
generate_first_row_core_registers(&mut row);
|
||||||
generate_arithmetic_unit(&mut row);
|
generate_alu(&mut row);
|
||||||
generate_permutation_unit(&mut row);
|
generate_permutation_unit(&mut row);
|
||||||
|
|
||||||
let mut trace = Vec::with_capacity(MIN_TRACE_ROWS);
|
let mut trace = Vec::with_capacity(MIN_TRACE_ROWS);
|
||||||
@ -46,7 +44,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SystemZero<F, D> {
|
|||||||
loop {
|
loop {
|
||||||
let mut next_row = [F::ZERO; NUM_COLUMNS];
|
let mut next_row = [F::ZERO; NUM_COLUMNS];
|
||||||
generate_next_row_core_registers(&row, &mut next_row);
|
generate_next_row_core_registers(&row, &mut next_row);
|
||||||
generate_arithmetic_unit(&mut next_row);
|
generate_alu(&mut next_row);
|
||||||
generate_permutation_unit(&mut next_row);
|
generate_permutation_unit(&mut next_row);
|
||||||
|
|
||||||
trace.push(row);
|
trace.push(row);
|
||||||
@ -84,7 +82,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for SystemZero<F,
|
|||||||
P: PackedField<Scalar = FE>,
|
P: PackedField<Scalar = FE>,
|
||||||
{
|
{
|
||||||
eval_core_registers(vars, yield_constr);
|
eval_core_registers(vars, yield_constr);
|
||||||
eval_arithmetic_unit(vars, yield_constr);
|
eval_alu(vars, yield_constr);
|
||||||
eval_permutation_unit::<F, FE, P, D2>(vars, yield_constr);
|
eval_permutation_unit::<F, FE, P, D2>(vars, yield_constr);
|
||||||
// TODO: Other units
|
// TODO: Other units
|
||||||
}
|
}
|
||||||
@ -96,7 +94,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for SystemZero<F,
|
|||||||
yield_constr: &mut RecursiveConstraintConsumer<F, D>,
|
yield_constr: &mut RecursiveConstraintConsumer<F, D>,
|
||||||
) {
|
) {
|
||||||
eval_core_registers_recursively(builder, vars, yield_constr);
|
eval_core_registers_recursively(builder, vars, yield_constr);
|
||||||
eval_arithmetic_unit_recursively(builder, vars, yield_constr);
|
eval_alu_recursively(builder, vars, yield_constr);
|
||||||
eval_permutation_unit_recursively(builder, vars, yield_constr);
|
eval_permutation_unit_recursively(builder, vars, yield_constr);
|
||||||
// TODO: Other units
|
// TODO: Other units
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user