tasm_lib/arithmetic/u64/
wrapping_sub.rsuse std::collections::HashMap;
use triton_vm::prelude::*;
use crate::arithmetic::u64::overflowing_sub::OverflowingSub;
use crate::prelude::*;
use crate::traits::basic_snippet::Reviewer;
use crate::traits::basic_snippet::SignOffFingerprint;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct WrappingSub;
impl BasicSnippet for WrappingSub {
fn inputs(&self) -> Vec<(DataType, String)> {
OverflowingSub.inputs()
}
fn outputs(&self) -> Vec<(DataType, String)> {
vec![(DataType::U64, "wrapped_difference".to_string())]
}
fn entrypoint(&self) -> String {
"tasmlib_arithmetic_u64_wrapping_sub".to_string()
}
fn code(&self, _: &mut Library) -> Vec<LabelledInstruction> {
triton_asm! {
{self.entrypoint()}:
{&OverflowingSub::common_subtraction_code()}
addi {1_u64 << 32}
split
place 2
pop 1
return
}
}
fn sign_offs(&self) -> HashMap<Reviewer, SignOffFingerprint> {
let mut sign_offs = HashMap::new();
sign_offs.insert(Reviewer("ferdinand"), 0xe6d83d5f88c389e3.into());
sign_offs
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_prelude::*;
impl Closure for WrappingSub {
type Args = <OverflowingSub as Closure>::Args;
fn rust_shadow(&self, stack: &mut Vec<BFieldElement>) {
let minuend = pop_encodable::<u64>(stack);
let subtrahend = pop_encodable::<u64>(stack);
let difference = minuend.wrapping_sub(subtrahend);
push_encodable(stack, &difference);
}
fn pseudorandom_args(
&self,
seed: [u8; 32],
bench_case: Option<BenchmarkCase>,
) -> Self::Args {
OverflowingSub.pseudorandom_args(seed, bench_case)
}
fn corner_case_args(&self) -> Vec<Self::Args> {
OverflowingSub.corner_case_args()
}
}
#[test]
fn rust_shadow() {
ShadowedClosure::new(WrappingSub).test()
}
}
#[cfg(test)]
mod benches {
use super::*;
use crate::test_prelude::*;
#[test]
fn benchmark() {
ShadowedClosure::new(WrappingSub).bench()
}
}