precomps.mx raw
1 package secp256k1
2
3 import (
4 _ "embed"
5 )
6
7 //go:embed rawbytepoints.bin
8 var bytepoints []byte
9 var bytePointTable [32][256]JacobianPoint
10 var bytePointsLoaded bool
11
12 // getBytePointTable returns the precomputed byte point table, initializing
13 // it on first call. Trivial getter — just a flag check and an out-of-line
14 // init call. The init logic is in initBytePointTable to keep this function's
15 // SelectionDAG small (LLVM 19 SDAG-combine has a known crash on the original
16 // inline form at -opt 0).
17 func getBytePointTable() *[32][256]JacobianPoint {
18 if !bytePointsLoaded {
19 initBytePointTable()
20 }
21 return &bytePointTable
22 }
23
24 // initBytePointTable fills the precomputed table from the embedded
25 // rawbytepoints.bin. Trivial loop dispatching to per-row helper.
26 //
27 //go:noinline
28 func initBytePointTable() {
29 for i := 0; i < 32; i++ {
30 loadBytePointRow(i)
31 }
32 bytePointsLoaded = true
33 }
34
35 // loadBytePointRow fills bytePointTable[row] from the embedded bytepoints
36 // blob. Indexes 256 entries at offsets row*256*64 + j*64.
37 //
38 //go:noinline
39 func loadBytePointRow(row int) {
40 base := row * 256 * 64
41 for j := 0; j < 256; j++ {
42 off := base + j*64
43 bytePointTable[row][j].X.SetByteSlice(bytepoints[off : off+32])
44 bytePointTable[row][j].Y.SetByteSlice(bytepoints[off+32 : off+64])
45 bytePointTable[row][j].Z.SetInt(1)
46 }
47 }
48