nx_p256_pointloop_bench.nx source
↩ module page · 33 lines · 1333 B
1// nx_p256_pointloop_bench.nx -- reusable crypto perf workload for codegen A/B.
2// A field-op-heavy P-256 point loop (double + add): long mem-bound limb chains,
3// the real critical path where register residency (G1) pays off. Per-iter arena
4// framing keeps memory constant. Used by bench/nx_codegen_ab.sh as a standing
5// "racing crew" benchmark for any backend/codegen change (G1/G2/G3/...).
6// expect_exit: deterministic (same under any correct codegen) -- A/B compares it.
7import "nx_syscalls.nx"
8import "nx_u256.nx"
9import "nx_p256_field.nx"
10import "nx_p256_point.nx"
11import "nx_p256_point_add.nx"
12const K_MAGIC_50000: i64 = 50000
13
14func main() -> i64 {
15 let G: *P256Point = p256_point_alloc()
16 p256_point_load_g(G)
17 let a: *P256Point = p256_point_alloc()
18 let b: *P256Point = p256_point_alloc()
19 p256_point_double(a, G) // a = 2G (persistent, outside the frame)
20
21 var i: i64 = 0
22 var acc: i64 = 0
23 while i < K_MAGIC_50000 {
24 let mark: i64 = nx_scratch_save()
25 p256_point_double(b, a) // b = 2a (field muls/sqrs)
26 p256_point_add(a, b, G) // a = b+G (field muls)
27 nx_scratch_restore(mark)
28 acc = acc + 1
29 i = i + 1
30 }
31 let xb: *i64 = a.x // sink a coordinate -> no dead-code elim
32 return (acc + xb[0]) & 255
33}