Skip to content

Commit

Permalink
Feat/word addressable memory (#509)
Browse files Browse the repository at this point in the history
* Deal with signed imm values outside of constraints

* SH virtual sequence

* Add memory-ops example

* Fix SH virtual sequence

* SB virtual sequence

* Add LBU, LHU, LB, LH virtual sequences

* Add AssertAlignedMemoryAccessInstruction and LowBitSubtable

* Switch to word-addressable memory in read_write_memory.rs

* Update constraints and remove SWInstruction lookup

* Assert word alignment for LW and SW

* rename load/store instruction lookups

* cargo update

* clippy
  • Loading branch information
moodlezoup authored Nov 22, 2024
1 parent ded4fcd commit dd9e5c4
Show file tree
Hide file tree
Showing 51 changed files with 3,519 additions and 2,174 deletions.
603 changes: 431 additions & 172 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ members = [
"examples/muldiv/guest",
"examples/overflow",
"examples/overflow/guest",


"examples/memory-ops",
"examples/memory-ops/guest",
]

[features]
Expand Down
11 changes: 2 additions & 9 deletions common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ const RISCV_REGISTER_COUNT: u64 = 32;
const VIRTUAL_REGISTER_COUNT: u64 = 32; // see Section 6.1 of Jolt paper
pub const REGISTER_COUNT: u64 = RISCV_REGISTER_COUNT + VIRTUAL_REGISTER_COUNT;
pub const BYTES_PER_INSTRUCTION: usize = 4;
pub const REG_OPS_PER_INSTRUCTION: usize = 3;
pub const RAM_OPS_PER_INSTRUCTION: usize = 4;
pub const MEMORY_OPS_PER_INSTRUCTION: usize = REG_OPS_PER_INSTRUCTION + RAM_OPS_PER_INSTRUCTION;
/// 3 registers (rd, rs1, rs2) + 1 RAM
pub const MEMORY_OPS_PER_INSTRUCTION: usize = 4;

pub const RAM_START_ADDRESS: u64 = 0x80000000;
pub const DEFAULT_MEMORY_SIZE: u64 = 10 * 1024 * 1024;
pub const DEFAULT_STACK_SIZE: u64 = 4096;
pub const DEFAULT_MAX_INPUT_SIZE: u64 = 4096;
pub const DEFAULT_MAX_OUTPUT_SIZE: u64 = 4096;

pub const fn memory_address_to_witness_index(address: u64, ram_witness_offset: u64) -> usize {
(address + ram_witness_offset - RAM_START_ADDRESS) as usize
}
pub const fn witness_index_to_memory_address(index: usize, ram_witness_offset: u64) -> u64 {
index as u64 + RAM_START_ADDRESS - ram_witness_offset
}
pub const fn virtual_register_index(index: u64) -> u64 {
index + VIRTUAL_REGISTER_COUNT
}
Expand Down
5 changes: 0 additions & 5 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
pub fn to_ram_address(index: usize) -> usize {
index * constants::BYTES_PER_INSTRUCTION + constants::RAM_START_ADDRESS as usize
}

pub mod attributes;
pub mod constants;
pub mod parallel;
pub mod rv_trace;
pub mod serializable;
34 changes: 0 additions & 34 deletions common/src/parallel.rs

This file was deleted.

Loading

0 comments on commit dd9e5c4

Please sign in to comment.