Skip to content

Commit

Permalink
perf!: Faster and const time u64::lt snippet
Browse files Browse the repository at this point in the history
Improve worst-case performance of `lt` snippet for `u64`. This snippet exists
in two versions, one that consumes its input arguments, and one that does not.

Both snippet's running time is improved with this change for the worst-case
inputs but the snippet that preserves the arguments goes from 12 to 14 clock
cycles in the common (best) case scenario. The arg-consuming snippet is
improved for both the best-case and worst-case scenario.
  • Loading branch information
Sword-Smith committed Jul 18, 2024
1 parent 8dfd412 commit 7192858
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 241 deletions.
14 changes: 7 additions & 7 deletions tasm-lib/benchmarks/tasmlib_arithmetic_u64_div_mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
"name": "tasmlib_arithmetic_u64_div_mod",
"benchmark_result": {
"clock_cycle_count": 235,
"hash_table_height": 540,
"clock_cycle_count": 227,
"hash_table_height": 528,
"u32_table_height": 218,
"op_stack_table_height": 182,
"op_stack_table_height": 172,
"ram_table_height": 12
},
"case": "CommonCase"
},
{
"name": "tasmlib_arithmetic_u64_div_mod",
"benchmark_result": {
"clock_cycle_count": 9155,
"hash_table_height": 540,
"u32_table_height": 11290,
"op_stack_table_height": 6434,
"clock_cycle_count": 9047,
"hash_table_height": 528,
"u32_table_height": 11767,
"op_stack_table_height": 6228,
"ram_table_height": 142
},
"case": "WorstCase"
Expand Down
24 changes: 24 additions & 0 deletions tasm-lib/benchmarks/tasmlib_arithmetic_u64_lt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"name": "tasmlib_arithmetic_u64_lt",
"benchmark_result": {
"clock_cycle_count": 14,
"hash_table_height": 18,
"u32_table_height": 43,
"op_stack_table_height": 7,
"ram_table_height": 0
},
"case": "CommonCase"
},
{
"name": "tasmlib_arithmetic_u64_lt",
"benchmark_result": {
"clock_cycle_count": 14,
"hash_table_height": 18,
"u32_table_height": 66,
"op_stack_table_height": 7,
"ram_table_height": 0
},
"case": "WorstCase"
}
]
24 changes: 24 additions & 0 deletions tasm-lib/benchmarks/tasmlib_arithmetic_u64_lt_preserve_args.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"name": "tasmlib_arithmetic_u64_lt_preserve_args",
"benchmark_result": {
"clock_cycle_count": 14,
"hash_table_height": 18,
"u32_table_height": 35,
"op_stack_table_height": 11,
"ram_table_height": 0
},
"case": "CommonCase"
},
{
"name": "tasmlib_arithmetic_u64_lt_preserve_args",
"benchmark_result": {
"clock_cycle_count": 14,
"hash_table_height": 18,
"u32_table_height": 38,
"op_stack_table_height": 11,
"ram_table_height": 0
},
"case": "WorstCase"
}
]
24 changes: 0 additions & 24 deletions tasm-lib/benchmarks/tasmlib_arithmetic_u64_lt_standard.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
"name": "tasmlib_mmr_calculate_new_peaks_from_leaf_mutation",
"benchmark_result": {
"clock_cycle_count": 2280,
"hash_table_height": 426,
"clock_cycle_count": 2276,
"hash_table_height": 420,
"u32_table_height": 1069,
"op_stack_table_height": 1464,
"op_stack_table_height": 1462,
"ram_table_height": 160
},
"case": "CommonCase"
},
{
"name": "tasmlib_mmr_calculate_new_peaks_from_leaf_mutation",
"benchmark_result": {
"clock_cycle_count": 4333,
"hash_table_height": 612,
"u32_table_height": 1682,
"op_stack_table_height": 2834,
"clock_cycle_count": 4339,
"hash_table_height": 606,
"u32_table_height": 1715,
"op_stack_table_height": 2840,
"ram_table_height": 315
},
"case": "WorstCase"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
"name": "tasmlib_mmr_leaf_index_to_mt_index_and_peak_index",
"benchmark_result": {
"clock_cycle_count": 119,
"hash_table_height": 132,
"clock_cycle_count": 115,
"hash_table_height": 126,
"u32_table_height": 298,
"op_stack_table_height": 71,
"op_stack_table_height": 69,
"ram_table_height": 0
},
"case": "CommonCase"
},
{
"name": "tasmlib_mmr_leaf_index_to_mt_index_and_peak_index",
"benchmark_result": {
"clock_cycle_count": 119,
"hash_table_height": 132,
"clock_cycle_count": 115,
"hash_table_height": 126,
"u32_table_height": 326,
"op_stack_table_height": 71,
"op_stack_table_height": 69,
"ram_table_height": 0
},
"case": "WorstCase"
Expand Down
14 changes: 7 additions & 7 deletions tasm-lib/benchmarks/tasmlib_mmr_verify_from_memory.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
"name": "tasmlib_mmr_verify_from_memory",
"benchmark_result": {
"clock_cycle_count": 1517,
"hash_table_height": 432,
"clock_cycle_count": 1513,
"hash_table_height": 426,
"u32_table_height": 1399,
"op_stack_table_height": 1174,
"op_stack_table_height": 1172,
"ram_table_height": 160
},
"case": "CommonCase"
},
{
"name": "tasmlib_mmr_verify_from_memory",
"benchmark_result": {
"clock_cycle_count": 2857,
"hash_table_height": 618,
"u32_table_height": 1524,
"op_stack_table_height": 2234,
"clock_cycle_count": 2863,
"hash_table_height": 612,
"u32_table_height": 1557,
"op_stack_table_height": 2240,
"ram_table_height": 315
},
"case": "WorstCase"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
"name": "tasmlib_mmr_verify_from_secret_in_leaf_index_on_stack",
"benchmark_result": {
"clock_cycle_count": 1064,
"hash_table_height": 378,
"u32_table_height": 166,
"op_stack_table_height": 564,
"clock_cycle_count": 1070,
"hash_table_height": 372,
"u32_table_height": 199,
"op_stack_table_height": 570,
"ram_table_height": 5
},
"case": "CommonCase"
},
{
"name": "tasmlib_mmr_verify_from_secret_in_leaf_index_on_stack",
"benchmark_result": {
"clock_cycle_count": 1904,
"hash_table_height": 558,
"u32_table_height": 835,
"op_stack_table_height": 984,
"clock_cycle_count": 1910,
"hash_table_height": 552,
"u32_table_height": 836,
"op_stack_table_height": 990,
"ram_table_height": 5
},
"case": "WorstCase"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
"name": "tasmlib_mmr_verify_from_secret_in_secret_leaf_index",
"benchmark_result": {
"clock_cycle_count": 1072,
"hash_table_height": 390,
"u32_table_height": 166,
"op_stack_table_height": 570,
"clock_cycle_count": 1078,
"hash_table_height": 384,
"u32_table_height": 199,
"op_stack_table_height": 576,
"ram_table_height": 5
},
"case": "CommonCase"
},
{
"name": "tasmlib_mmr_verify_from_secret_in_secret_leaf_index",
"benchmark_result": {
"clock_cycle_count": 1912,
"hash_table_height": 570,
"u32_table_height": 933,
"op_stack_table_height": 990,
"clock_cycle_count": 1918,
"hash_table_height": 564,
"u32_table_height": 966,
"op_stack_table_height": 996,
"ram_table_height": 5
},
"case": "WorstCase"
Expand Down
4 changes: 2 additions & 2 deletions tasm-lib/src/arithmetic/u64/div_mod_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::arithmetic::u32::safeadd::Safeadd;
use crate::arithmetic::u32::safesub::Safesub;
use crate::arithmetic::u64::and_u64::AndU64;
use crate::arithmetic::u64::leading_zeros_u64::LeadingZerosU64;
use crate::arithmetic::u64::lt_u64::LtStandardU64;
use crate::arithmetic::u64::lt_u64::LtU64ConsumeArgs;
use crate::arithmetic::u64::or_u64::OrU64;
use crate::arithmetic::u64::shift_left_u64::ShiftLeftU64;
use crate::arithmetic::u64::shift_right_u64::ShiftRightU64;
Expand Down Expand Up @@ -65,7 +65,7 @@ impl DeprecatedSnippet for DivModU64 {
let shift_right_u64 = library.import(Box::new(ShiftRightU64));
let shift_left_u64 = library.import(Box::new(ShiftLeftU64));
let and_u64 = library.import(Box::new(AndU64));
let lt_u64 = library.import(Box::new(LtStandardU64));
let lt_u64 = library.import(Box::new(LtU64ConsumeArgs));
let or_u64 = library.import(Box::new(OrU64));
let sub_u64 = library.import(Box::new(SubU64));
let sub_u32 = library.import(Box::new(Safesub));
Expand Down
Loading

0 comments on commit 7192858

Please sign in to comment.