-
Notifications
You must be signed in to change notification settings - Fork 30
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
[feat] Add the functionality for custom RISC-V intrinsics, support hints in RISC-V #726
Conversation
INT-2498 need a different `hintinput_rv32` phantom instruction when `len` is a word
but for INT-2474 Macros for custom_insn in axvm-platform
Make macros This should go in some INT-2409 Intrinsics for `hintstorew` and `hintinput`
Make intrinsic opcode for The actual hint function in rust will be more complicated since it will need to hint in a byte slice End flow: you have a struct that is input you want hinted into program. Need to study how risc0 does this; I believe they just use
For this ticket, just implement in |
toolchain/riscv/transpiler/data/rv32im-hint-program-elf-release
Outdated
Show resolved
Hide resolved
@@ -79,6 +79,7 @@ | |||
#![deny(rustdoc::broken_intra_doc_links)] | |||
#![deny(missing_docs)] | |||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] | |||
#![feature(asm_const)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a nightly feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the imm = const $imm
in asm!
macro doesn't work without this. I don't know if it's nightly or not, here is its origin: rust-lang/rust#93332
@@ -13,35 +13,42 @@ macro_rules! hint_store_u32 { | |||
} | |||
|
|||
/// Read the next 4 bytes from the hint stream. | |||
#[allow(asm_sub_register)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this magic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok it seems it's because we hint to memory and register is stack. please add some comments because you're too clever
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was just doing what compiler suggested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
INT-2489 Rust hint input support
Firstly we just want a rust function that will hint in a This is something like:
Next is that we don't want to just hint in a raw
I think we can just use |
…nts in RISC-V (#726) * Add custom insn macros * Wip * Wip * Add "read-vec" function * Add the new HintInputRv32 phantom instruction, add the corresponding intrinsic, support transpiling it * Add a test * Optimize reading a vector * Address comments, add a test, fix transpiler * Fix rust-v hint program * chore: mv exit,panic to process * feat: make `read_vec` more optimal * fix: () vs ! * fix import * fix: ptr was not ptr_start --------- Co-authored-by: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com>
This should resolve INT-2498, INT-2474, INT-2409.
Also towards INT-2489
What this does:
custom_insn_i!
andcustom_insn_r!
for creating our own new instructions in Rust-V (maybe in the future we will need other modifications, as to which registers we care about and which we don't),PhantomInstruction::HintInput
that differs only in prepending with 4-byte length decomposition instead of 1-usize.Copilot:
This pull request includes several changes to the
toolchain
andvm
modules to enhance the handling of hint streams and custom instructions. The most important changes include the addition of new hint stream utilities, the introduction of a new instruction variant, and updates to existing instruction handling logic.Enhancements to Hint Stream Handling:
toolchain/riscv/axvm/src/intrinsics/io.rs
for reading from and writing to the hint stream, includingread_u32
,read_vec
,read_size_and_vec
, andhint_input
.toolchain/riscv/axvm/src/intrinsics/mod.rs
.Introduction of New Instruction Variant:
HintInputRv32
to thePhantomInstruction
enum intoolchain/instructions/src/phantom.rs
, which prepares the next input vector for hinting with a 4-byte decomposition of its length.Updates to Instruction Handling Logic:
toolchain/riscv/platform/src/intrinsics/mod.rs
for defining custom instructions, such ascustom_insn_i
andcustom_insn_r
.toolchain/riscv/transpiler/src/rrs.rs
andvm/src/system/phantom/mod.rs
to handle the newHintInputRv32
instruction variant. [1] [2]Additional Changes:
asm_const
feature intoolchain/riscv/axvm/src/lib.rs
.toolchain/riscv/examples/hint/program
to demonstrate the usage of the new hint stream utilities and instructions. [1] [2] [3]These changes collectively improve the handling of hint streams and custom instructions, providing more flexibility and functionality for developers working with the
toolchain
andvm
modules.