Skip to content

Commit

Permalink
feat: RISC-V 256-bit Integer Chip Implementations (#716)
Browse files Browse the repository at this point in the history
* feat: RISC-V base ALU int256 chip
* feat: remove eDSL support for U256 arithmetic, ECC, and modular arithmetic
  • Loading branch information
stephenh-axiom-xyz authored Oct 31, 2024
1 parent cd04710 commit 408d9a5
Show file tree
Hide file tree
Showing 54 changed files with 1,023 additions and 5,782 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/benchmark-call.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
options:
- verify_fibair
- fibonacci
- alu256_e2e
- small_e2e
instance_type:
type: string
Expand Down Expand Up @@ -93,12 +92,6 @@ jobs:
run: |
python3 ../ci/scripts/bench.py $BIN_NAME $CMD_ARGS
- name: Run benchmark
if: inputs.benchmark_name == 'alu256_e2e'
working-directory: lib/recursion
run: |
python3 ../../ci/scripts/bench.py $BIN_NAME $CMD_ARGS
- name: Run benchmark
if: inputs.benchmark_name == 'small_e2e'
working-directory: lib/recursion
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/recursion-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ env:
AXIOM_FAST_TEST: "1"

jobs:
benchmark_alu256_e2e:
uses: ./.github/workflows/benchmark-call.yml
# run on pull request with label 'run-benchmark' or 'run-benchmark-e2e'
# and always run on push to main
if: |
(github.event_name == 'pull_request' &&
(contains(github.event.pull_request.labels.*.name, 'run-benchmark') ||
contains(github.event.pull_request.labels.*.name, 'run-benchmark-e2e'))) ||
(github.event_name == 'push' && github.ref == 'refs/heads/main')
with:
instance_type: 64cpu-linux-arm64
benchmark_name: alu256_e2e
secrets: inherit

benchmark_small_e2e:
uses: ./.github/workflows/benchmark-call.yml
# run on non-draft pull request with label 'run-benchmark'
Expand Down
3 changes: 0 additions & 3 deletions lib/recursion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ cfg-if = { workspace = true }
[dev-dependencies]
ax-circuit-primitives.workspace = true

[[bin]]
name = "alu256_e2e"

[[bin]]
name = "small_e2e"

Expand Down
173 changes: 0 additions & 173 deletions lib/recursion/src/bin/alu256_e2e.rs

This file was deleted.

26 changes: 1 addition & 25 deletions lib/recursion/src/hints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::cmp::Reverse;

use ax_circuit_primitives::bigint::utils::big_uint_to_num_limbs;
use ax_stark_backend::{
keygen::types::TraceWidth,
prover::{
Expand All @@ -10,11 +9,9 @@ use ax_stark_backend::{
};
use ax_stark_sdk::config::baby_bear_poseidon2::BabyBearPoseidon2Config;
use axvm_native_compiler::ir::{
unsafe_array_transmute, Array, BigUintVar, Builder, Config, Ext, Felt, MemVariable, Usize, Var,
DIGEST_SIZE, LIMB_BITS, NUM_LIMBS,
unsafe_array_transmute, Array, Builder, Config, Ext, Felt, MemVariable, Usize, Var, DIGEST_SIZE,
};
use itertools::Itertools;
use num_bigint_dig::BigUint;
use p3_baby_bear::{BabyBear, DiffusionMatrixBabyBear};
use p3_commit::ExtensionMmcs;
use p3_field::{extension::BinomialExtensionField, AbstractExtensionField, AbstractField, Field};
Expand Down Expand Up @@ -472,27 +469,6 @@ impl Hintable<InnerConfig> for Commitments<BabyBearPoseidon2Config> {
}
}

impl Hintable<InnerConfig> for BigUint {
type HintVariable = BigUintVar<InnerConfig>;

fn read(builder: &mut Builder<InnerConfig>) -> Self::HintVariable {
let ret = builder.uninit_biguint();
for i in 0..NUM_LIMBS {
// FIXME: range check for each element.
let v = builder.hint_var();
builder.set_value(&ret, i, v);
}
ret
}

fn write(&self) -> Vec<Vec<<InnerConfig as Config>::N>> {
vec![big_uint_to_num_limbs(self, LIMB_BITS, NUM_LIMBS)
.iter()
.map(|x| <InnerConfig as Config>::N::from_canonical_usize(*x))
.collect()]
}
}

#[cfg(test)]
mod test {
use axvm_circuit::system::program::util::execute_program;
Expand Down
34 changes: 0 additions & 34 deletions toolchain/instructions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,40 +150,6 @@ pub enum ModularArithmeticOpcode {
DIV,
}

// to be deleted and replaced by Rv32Alu256Opcodes below
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, EnumCount, EnumIter, FromRepr, UsizeOpcode,
)]
#[opcode_offset = 0x180]
#[repr(usize)]
pub enum U256Opcode {
// maybe later we will make it uint and specify the parameters in the config
ADD,
SUB,
LT,
EQ,
XOR,
AND,
OR,
SLT,

SLL,
SRL,
SRA,

MUL,
}
impl U256Opcode {
// Excludes multiplication
pub fn arithmetic_opcodes() -> impl Iterator<Item = U256Opcode> {
(U256Opcode::ADD as usize..=U256Opcode::SLT as usize).map(U256Opcode::from_usize)
}

pub fn shift_opcodes() -> impl Iterator<Item = U256Opcode> {
(U256Opcode::SLL as usize..=U256Opcode::SRA as usize).map(U256Opcode::from_usize)
}
}

// to be deleted and replaced by Rv32SwOpcode
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, EnumCount, EnumIter, FromRepr, UsizeOpcode,
Expand Down
Loading

0 comments on commit 408d9a5

Please sign in to comment.