Skip to content

Commit 58b4d75

Browse files
authored
feat: add EUC benchmark (#1324)
This adds a benchmark corresponding to the "Tiny Euclidean Division Module (EUC)".
1 parent b7edfdf commit 58b4d75

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

pkg/test/assembly_bench_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ func Test_AsmBench_Add(t *testing.T) {
2323
util.CheckWithFields(t, false, "asm/bench/add", util.ASM_MAX_PADDING, field.BLS12_377, field.KOALABEAR_16)
2424
}
2525

26+
func Test_AsmBench_Euc(t *testing.T) {
27+
util.CheckWithFields(t, false, "asm/bench/euc", util.ASM_MAX_PADDING, field.BLS12_377)
28+
}
2629
func Test_AsmBench_Exp(t *testing.T) {
2730
util.CheckWithFields(t, false, "asm/bench/exp", util.ASM_MAX_PADDING, field.BLS12_377)
2831
}

testdata/asm/bench/euc.accepts.bz2

59.3 KB
Binary file not shown.

testdata/asm/bench/euc.zkasm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
;; The Tiny Euclidean Division Module (EUC) is used for checking small
2+
;; (64-bit) divisions are correct. In addition, the function computes
3+
;; a ceiling for the quotient. NOTE: the function does not permit a
4+
;; zero divisor
5+
fn euc(DIVIDEND u64, DIVISOR=1 u64, QUOTIENT u64, REMAINDER u64) -> (CEIL u64)
6+
;; PRE: DIVISOR!=0
7+
{
8+
var val_hi, val_lo u64
9+
var tmp u64
10+
var b, c u1
11+
;; assert divisor is non-zero
12+
if DIVISOR == 0 goto exit_f
13+
;; reconstruct value from quotient / remainder
14+
val_hi,val_lo = (QUOTIENT * DIVISOR) + REMAINDER
15+
;; assert value is consistent
16+
if val_hi != 0 goto exit_f
17+
if val_lo != DIVIDEND goto exit_f
18+
;; assert remainder < divisor
19+
b, tmp = DIVISOR - REMAINDER - 1
20+
if b == 1 goto exit_f
21+
;; Compute ceiling
22+
if REMAINDER == 0 goto exit_0
23+
c, CEIL = QUOTIENT + 1
24+
return
25+
exit_0:
26+
CEIL = QUOTIENT
27+
return
28+
exit_f:
29+
fail
30+
}

0 commit comments

Comments
 (0)