Skip to content

Commit 8e9807b

Browse files
committed
perf(barycentric): Use pick&place over swap
1 parent 67ef366 commit 8e9807b

7 files changed

+66
-103
lines changed

tasm-lib/benchmarks/tasmlib_verifier_fri_barycentric_evaluation.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
{
33
"name": "tasmlib_verifier_fri_barycentric_evaluation",
44
"benchmark_result": {
5-
"clock_cycle_count": 6879,
6-
"hash_table_height": 282,
5+
"clock_cycle_count": 6106,
6+
"hash_table_height": 270,
77
"u32_table_height": 50,
8-
"op_stack_table_height": 6351,
8+
"op_stack_table_height": 4811,
99
"ram_table_height": 3073
1010
},
1111
"case": "CommonCase"
1212
},
1313
{
1414
"name": "tasmlib_verifier_fri_barycentric_evaluation",
1515
"benchmark_result": {
16-
"clock_cycle_count": 13535,
17-
"hash_table_height": 282,
16+
"clock_cycle_count": 11994,
17+
"hash_table_height": 270,
1818
"u32_table_height": 49,
19-
"op_stack_table_height": 12495,
19+
"op_stack_table_height": 9419,
2020
"ram_table_height": 6145
2121
},
2222
"case": "WorstCase"

tasm-lib/benchmarks/tasmlib_verifier_fri_verify.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
{
33
"name": "tasmlib_verifier_fri_verify",
44
"benchmark_result": {
5-
"clock_cycle_count": 47806,
6-
"hash_table_height": 14670,
5+
"clock_cycle_count": 46265,
6+
"hash_table_height": 14664,
77
"u32_table_height": 17928,
8-
"op_stack_table_height": 47915,
8+
"op_stack_table_height": 44839,
99
"ram_table_height": 17532
1010
},
1111
"case": "CommonCase"
1212
},
1313
{
1414
"name": "tasmlib_verifier_fri_verify",
1515
"benchmark_result": {
16-
"clock_cycle_count": 47806,
17-
"hash_table_height": 14670,
16+
"clock_cycle_count": 46265,
17+
"hash_table_height": 14664,
1818
"u32_table_height": 17324,
19-
"op_stack_table_height": 47915,
19+
"op_stack_table_height": 44839,
2020
"ram_table_height": 17532
2121
},
2222
"case": "WorstCase"

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_dynamic_inner_padded_height_256_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_dynamic_inner_padded_height_256_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 198488,
6-
"hash_table_height": 142867,
7-
"u32_table_height": 25439,
8-
"op_stack_table_height": 182986,
5+
"clock_cycle_count": 196947,
6+
"hash_table_height": 142861,
7+
"u32_table_height": 24710,
8+
"op_stack_table_height": 179910,
99
"ram_table_height": 289180
1010
},
1111
"case": "CommonCase"

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_dynamic_inner_padded_height_512_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_dynamic_inner_padded_height_512_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 207241,
6-
"hash_table_height": 150559,
7-
"u32_table_height": 33969,
8-
"op_stack_table_height": 189114,
5+
"clock_cycle_count": 205700,
6+
"hash_table_height": 150553,
7+
"u32_table_height": 34237,
8+
"op_stack_table_height": 186038,
99
"ram_table_height": 290358
1010
},
1111
"case": "CommonCase"

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_static_inner_padded_height_256_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_static_inner_padded_height_256_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 186785,
6-
"hash_table_height": 128827,
7-
"u32_table_height": 25309,
8-
"op_stack_table_height": 175180,
5+
"clock_cycle_count": 185244,
6+
"hash_table_height": 128815,
7+
"u32_table_height": 24702,
8+
"op_stack_table_height": 172104,
99
"ram_table_height": 285281
1010
},
1111
"case": "CommonCase"

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_static_inner_padded_height_512_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_static_inner_padded_height_512_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 195538,
6-
"hash_table_height": 136519,
7-
"u32_table_height": 34122,
8-
"op_stack_table_height": 181308,
5+
"clock_cycle_count": 193997,
6+
"hash_table_height": 136507,
7+
"u32_table_height": 34349,
8+
"op_stack_table_height": 178232,
99
"ram_table_height": 286459
1010
},
1111
"case": "CommonCase"

tasm-lib/src/verifier/fri/barycentric_evaluation.rs

Lines changed: 38 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ impl BasicSnippet for BarycentricEvaluation {
5858
xb_mul
5959
// _ *partial_terms_end_cond *partial_terms generator [-indeterminate] generator_acc [generator_acc/(generator_acc-indeterminate)]
6060

61-
dup 8
61+
pick 8
6262
write_mem {EXTENSION_DEGREE}
63-
swap 6
64-
pop 1
63+
place 5
6564
// _ *partial_terms_end_cond *partial_terms' generator [-indeterminate] generator_acc
6665

6766
dup 4
@@ -76,19 +75,12 @@ impl BasicSnippet for BarycentricEvaluation {
7675
let numerator_from_partial_sums_loop_label =
7776
format!("{entrypoint}_numerator_from_partial_sums");
7877
let numerator_from_partial_sums_loop_code = triton_asm!(
79-
// BEGIN: _ *ptec *partial_terms[0] [0] *codeword[0] *partial_terms[0]
80-
// INVARIANT: _ *ptec *partial_terms[n] [acc] *codeword[n] *partial_terms[n]
78+
// BEGIN: _ *ptec *partial_terms[0] 0 [0] *codeword[0]
79+
// INVARIANT: _ *ptec *partial_terms[n] 0 [acc] *codeword[n]
8180
{numerator_from_partial_sums_loop_label}:
82-
// _ *ptec *partial_terms[n] [acc] *codeword[n] *partial_terms[n]
83-
81+
pick 5
8482
xx_dot_step
85-
// _ *ptec *partial_terms[n] [acc'] *codeword[n'] *partial_terms[n']
86-
87-
dup 0
88-
swap 6
89-
pop 1
90-
// _ *ptec *partial_terms[n'] [acc'] *codeword[n'] *partial_terms[n']
91-
83+
place 5
9284
recurse_or_return
9385
);
9486

@@ -101,12 +93,9 @@ impl BasicSnippet for BarycentricEvaluation {
10193
{denominator_from_partial_sums_loop_label}:
10294
// _ (*partial_terms-1) *partial_terms[n] 0 0 [acc]
10395

104-
dup 5
96+
pick 5
10597
read_mem {EXTENSION_DEGREE}
106-
// _ (*partial_terms-1) *partial_terms[n] 0 0 [acc] [term] *partial_terms[n-1]
107-
108-
swap 9
109-
pop 1
98+
place 8
11099
// _ (*partial_terms-1) *partial_terms[n-1] 0 0 [acc] [term]
111100

112101
xx_add
@@ -148,28 +137,20 @@ impl BasicSnippet for BarycentricEvaluation {
148137
hint generator: BFieldElement = stack[0]
149138
// _ *codeword [-indeterminate] codeword_len generator
150139

151-
swap 1
140+
pick 1
152141
// _ *codeword [-indeterminate] generator codeword_len
153142

154143
push {EXTENSION_DEGREE}
155144
mul
156145
push {partial_terms_alloc.write_address()}
157146
add
158-
// _ *codeword [-indeterminate] generator (*partial_terms_last_word+1)
159-
// _ *codeword (-i2) (-i1) (-i0) generator (*partial_terms_last_word+1) <-- rename
160-
161-
swap 4
162-
// _ *codeword (*partial_terms_last_word+1) (-i1) (-i0) generator (-i2)
147+
// _ *codeword [-indeterminate] generator (*partial_terms_last_word+1)
163148

149+
place 4
150+
place 3
164151
push {partial_terms_alloc.write_address()}
165-
swap 4
166-
// _ *codeword (*partial_terms_last_word+1) *partial_terms[0] (-i0) generator (-i2) (-i1)
167-
168-
swap 1
169-
swap 2
170-
swap 3
171-
// _ *codeword (*partial_terms_last_word+1) *partial_terms[0] generator (-i2) (-i1) (-i0)
172-
// _ *codeword (*partial_terms_last_word+1) *partial_terms[0] generator [-indeterminate] <-- rename
152+
place 4
153+
// _ *codeword (*partial_terms_last_word+1) *partial_terms[0] generator [-indeterminate]
173154

174155
push 1
175156
// _ *codeword (*partial_terms_last_word+1) *partial_terms[0] generator [-indeterminate] generator_acc
@@ -181,70 +162,52 @@ impl BasicSnippet for BarycentricEvaluation {
181162
pop 1
182163
// _ *codeword (*partial_terms_last_word+1)
183164

184-
swap 1
185-
// _ (*partial_terms_last_word+1) *codeword
186-
187-
push 1
188-
add
189-
// _ (*partial_terms_last_word+1) *codeword[0]
190-
191-
push 0
192-
push 0
193-
push 0
194-
// _ (*partial_terms_last_word+1) *codeword[0] [acc]
195-
165+
place 1
196166
push {partial_terms_alloc.write_address()}
197-
swap 4
198-
// _ (*partial_terms_last_word+1) *partial_terms[0] [acc] *codeword[0]
167+
push 0
168+
push 0 push 0 push 0
169+
// _ (*partial_terms_last_word+1) *codeword *partial_terms[0] 0 [acc]
199170

200-
push {partial_terms_alloc.write_address()}
201-
// _ (*partial_terms_last_word+1) *partial_terms[0] [acc] *codeword[0] *partial_terms[0]
171+
pick 5
172+
addi 1
173+
// _ (*partial_terms_last_word+1) *partial_terms[0] 0 [acc] *codeword[0]
202174

203175
call {numerator_from_partial_sums_loop_label}
204-
// _ (*partial_terms_last_word+1) (*partial_terms_last_word+1) [numerator] *codeword[last + 1] (*partial_terms_last_word+1)
176+
// _ (*partial_terms_last_word+1) (*partial_terms_last_word+1) 0 [numerator] *codeword[last + 1]
205177

178+
pick 4
206179
pop 2
207180
// _ (*partial_terms_last_word+1) (*partial_terms_last_word+1) [numerator]
208181
hint numerator: XFieldElement = stack[0..3]
209182

210-
// _ (*partial_terms_last_word+1) (*partial_terms_last_word+1) n2 n1 n0 <-- rename
211-
212-
213-
swap 2
214-
swap 4
215-
// _ n2 (*partial_terms_last_word+1) n0 n1 (*partial_terms_last_word+1)
216-
217-
push -1
218-
add
219-
// _ n2 (*partial_terms_last_word+1) n0 n1 *partial_terms_last_word
220-
221-
push {partial_terms_alloc.write_address() - bfe!(1)}
222-
// _ n2 (*partial_terms_last_word+1) n0 n1 *partial_terms_last_word (*partial_terms - 1)
223-
224-
swap 2
225-
swap 4
183+
place 4
184+
place 4
185+
place 4
226186
pop 1
227-
// _ n2 n1 n0 (*partial_terms - 1) *partial_terms_last_word
228-
// _ [numerator] (*partial_terms - 1) *partial_terms_last_word <-- rename
187+
addi -1
188+
// _ [numerator] *partial_terms_last_word
229189

230190
push 0
231191
push 0
232192
push 0
233193
push 0
234194
push 0
195+
// _ [numerator] *partial_terms_last_word 0 0 [0]
196+
197+
push {partial_terms_alloc.write_address() - bfe!(1)}
198+
hint loop_end_condition = stack[0]
199+
place 6
235200
// _ [numerator] (*partial_terms - 1) *partial_terms_last_word 0 0 [0]
236201

237202
call {denominator_from_partial_sums_loop_label}
203+
hint denominator: XFieldElement = stack[0..2]
238204
// _ [numerator] (*partial_terms - 1) *partial_terms_last_word 0 0 [denominator]
239205

240-
swap 4
241-
pop 1
242-
swap 4
243-
pop 1
244-
swap 4
245-
pop 2
206+
place 6
207+
place 6
208+
place 6
209+
pop 4
246210
// _ [numerator] [denominator]
247-
hint denominator: XFieldElement = stack[0..2]
248211

249212
x_invert
250213
xx_mul

0 commit comments

Comments
 (0)