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

o1vm/riscv32: implement div_signed #2799

Open
wants to merge 2 commits into
base: dw/o1vm/riscv-remove-mul-hi-lo
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions o1vm/src/interpreters/riscv32im/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,15 @@ impl<Fp: Field> InterpreterEnv for Env<Fp> {
self.variable(position)
}

unsafe fn div_signed(
&mut self,
_x: &Self::Variable,
_y: &Self::Variable,
position: Self::Position,
) -> Self::Variable {
self.variable(position)
}

unsafe fn divmod_signed(
&mut self,
_x: &Self::Variable,
Expand Down
14 changes: 14 additions & 0 deletions o1vm/src/interpreters/riscv32im/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,20 @@ pub trait InterpreterEnv {
position: Self::Position,
) -> Self::Variable;

/// Returns `x / y`, storing the results in `position`.
///
/// # Safety
///
/// There are no constraints on the returned values; callers must manually add constraints to
/// ensure that the pair of returned values correspond to the given values `x` and `y`, and
/// that they fall within the desired range.
unsafe fn div_signed(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position,
) -> Self::Variable;

/// Returns `(x / y, x % y)`, storing the results in `position_quotient` and
/// `position_remainder` respectively.
///
Expand Down
14 changes: 14 additions & 0 deletions o1vm/src/interpreters/riscv32im/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,20 @@ impl<Fp: Field> InterpreterEnv for Env<Fp> {
res
}

unsafe fn div_signed(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position,
) -> Self::Variable {
let x: i32 = (*x).try_into().unwrap();
let y: i32 = (*y).try_into().unwrap();
let res = (x / y) as u32;
let res = res as u64;
self.write_column(position, res);
res
}

unsafe fn divmod_signed(
&mut self,
x: &Self::Variable,
Expand Down
Loading