-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!(leading_zeroes): Impl
BasicSnippet
Remove the implementations of `DeprecatedSnippet`, implement `BasicSnippet` directly.
- Loading branch information
1 parent
821d7ca
commit 9ba83df
Showing
11 changed files
with
202 additions
and
347 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
tasm-lib/benchmarks/tasmlib_arithmetic_u32_leading_zeros.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"name": "tasmlib_arithmetic_u32_leading_zeros", | ||
"benchmark_result": { | ||
"clock_cycle_count": 12, | ||
"hash_table_height": 12, | ||
"u32_table_height": 17, | ||
"op_stack_table_height": 4, | ||
"ram_table_height": 0 | ||
}, | ||
"case": "CommonCase" | ||
}, | ||
{ | ||
"name": "tasmlib_arithmetic_u32_leading_zeros", | ||
"benchmark_result": { | ||
"clock_cycle_count": 12, | ||
"hash_table_height": 12, | ||
"u32_table_height": 33, | ||
"op_stack_table_height": 4, | ||
"ram_table_height": 0 | ||
}, | ||
"case": "WorstCase" | ||
} | ||
] |
24 changes: 0 additions & 24 deletions
24
tasm-lib/benchmarks/tasmlib_arithmetic_u32_leadingzeros.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use triton_vm::prelude::*; | ||
|
||
use crate::prelude::*; | ||
|
||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | ||
pub struct LeadingZeros; | ||
|
||
impl BasicSnippet for LeadingZeros { | ||
fn inputs(&self) -> Vec<(DataType, String)> { | ||
vec![(DataType::U32, "arg".to_string())] | ||
} | ||
|
||
fn outputs(&self) -> Vec<(DataType, String)> { | ||
vec![(DataType::U32, "leading_zeros(arg)".to_string())] | ||
} | ||
|
||
fn entrypoint(&self) -> String { | ||
"tasmlib_arithmetic_u32_leading_zeros".to_string() | ||
} | ||
|
||
fn code(&self, _: &mut Library) -> Vec<LabelledInstruction> { | ||
let entrypoint = self.entrypoint(); | ||
let non_zero_label = format!("{entrypoint}_non_zero"); | ||
|
||
triton_asm! { | ||
// BEFORE: _ value | ||
// AFTER: _ (leading zeros in value) | ||
{entrypoint}: | ||
dup 0 | ||
skiz | ||
call {non_zero_label} | ||
|
||
push -1 | ||
mul | ||
addi 32 | ||
|
||
return | ||
|
||
{non_zero_label}: | ||
log_2_floor | ||
addi 1 | ||
return | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::test_prelude::*; | ||
|
||
impl Closure for LeadingZeros { | ||
type Args = u32; | ||
|
||
fn rust_shadow(&self, stack: &mut Vec<BFieldElement>) { | ||
let arg = pop_encodable::<Self::Args>(stack); | ||
push_encodable(stack, &arg.leading_zeros()); | ||
} | ||
|
||
fn pseudorandom_args( | ||
&self, | ||
seed: [u8; 32], | ||
bench_case: Option<BenchmarkCase>, | ||
) -> Self::Args { | ||
match bench_case { | ||
Some(BenchmarkCase::CommonCase) => 1 << 15, | ||
Some(BenchmarkCase::WorstCase) => u32::MAX, | ||
None => StdRng::from_seed(seed).gen(), | ||
} | ||
} | ||
|
||
fn corner_case_args(&self) -> Vec<Self::Args> { | ||
vec![0, 1, 2, 3, 1 << 28, 1 << 29, 1 << 30, 1 << 31, u32::MAX] | ||
} | ||
} | ||
|
||
#[test] | ||
fn unit() { | ||
ShadowedClosure::new(LeadingZeros).test(); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod benches { | ||
use super::*; | ||
use crate::test_prelude::*; | ||
|
||
#[test] | ||
fn benchmark() { | ||
ShadowedClosure::new(LeadingZeros).bench(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.