Skip to content

secp256k1: Select arch-specific field backend. - #3758

Merged
davecgh merged 2 commits into
decred:masterfrom
davecgh:secp256k1_select_backend_per_arch
Nov 20, 2026
Merged

davecgh merged 2 commits into
decred:masterfrom
davecgh:secp256k1_select_backend_per_arch

Conversation

@davecgh

@davecgh davecgh commented Jul 29, 2026

Copy link
Copy Markdown
Member

This modifies the field wrapper to choose an architecture-specific backend at compile time.

This is distinct from the additional architecture-specific optimizations the backend implementations choose at run time.

As expected, the 32-bit results do not change because it continues to use the same backend. However, as shown below, 64-bit benefits from significant performance enhancements.

Comparison of relevant operations for 32-bit platforms:

$ {before,after}_x86.txt
name                           old time/op   new time/op   delta
---------------------------------------------------------------------------------
AddNonConst/Z1AndZ2EqualsOne    779ns ± 3%    781ns ± 8%     ~  (p=0.353 n=10+10)
AddNonConst/Z1EqualsZ2          882ns ± 5%    881ns ± 4%     ~  (p=0.031 n=9+9)
AddNonConst/Z2EqualsOne        1.30µs ± 1%   1.31µs ± 1%     ~  (p=0.008 n=8+9)
AddNonConst/Generic            1.81µs ± 1%   1.82µs ± 1%     ~  (p=0.002 n=9+10)
DoubleNonConst/ZEqualsOne       682ns ± 3%    682ns ± 2%     ~  (p=0.853 n=10+10)
DoubleNonConst/Generic          778ns ± 1%    778ns ± 2%     ~  (p=0.955 n=10+10)
ScalarBaseMultNonConst         40.0µs ± 2%   40.0µs ± 1%     ~  (p=0.905 n=10+9)
ScalarMultNonConst              186µs ± 2%    186µs ± 1%     ~  (p=0.631 n=10+10)
SigVerify                       233µs ± 1%    234µs ± 4%     ~  (p=0.489 n=9+9)
RecoverCompact                  281µs ± 2%    282µs ± 1%     ~  (p=0.218 n=10+10)

Comparison of relevant operations for 64-bit platforms:

$ benchstat {before,after}_x64.txt
name                           old time/op   new time/op   delta
------------------------------------------------------------------------------------
AddNonConst/Z1AndZ2EqualsOne    367ns ± 3%    176ns ± 3%   -52.15% (p=0.000 n=8+9)
AddNonConst/Z1EqualsZ2          403ns ± 1%    147ns ± 2%   -63.48% (p=0.000 n=9+9)
AddNonConst/Z2EqualsOne         624ns ± 1%    248ns ± 2%   -60.32% (p=0.000 n=8+10)
AddNonConst/Generic             871ns ± 1%    299ns ± 1%   -65.64% (p=0.000 n=10+10)
DoubleNonConst/ZEqualsOne       298ns ± 2%    165ns ± 1%   -44.69% (p=0.000 n=10+10)
DoubleNonConst/Generic          345ns ± 1%    171ns ± 1%   -50.27% (p=0.000 n=10+9)
ScalarBaseMultNonConst         19.0µs ± 1%    7.6µs ± 1%   -60.09% (p=0.000 n=8+10)
ScalarMultNonConst             85.3µs ± 2%   36.8µs ± 1%   -56.83% (p=0.000 n=9+10)
SigVerify                       107µs ± 2%     47µs ± 1%   -56.63% (p=0.000 n=8+10)
RecoverCompact                  125µs ± 1%     53µs ± 1%   -57.24% (p=0.000 n=9+8)

@davecgh davecgh added this to the 2.2.0 milestone Jul 29, 2026
@davecgh
davecgh force-pushed the secp256k1_select_backend_per_arch branch 2 times, most recently from b1c0854 to 50b2de4 Compare July 30, 2026 10:39
Comment thread dcrec/secp256k1/README.md Resolved
@davecgh
davecgh force-pushed the secp256k1_select_backend_per_arch branch from 50b2de4 to 61bbf6b Compare July 31, 2026 06:57
This modifies the field wrapper to select an architecture-specific
backend at compile time.

This is distinct from the additional architecture-specific optimizations
the backend implementations perform at run time.

Comparison of relevant operations for 32-bit platforms:
```
$ {before,after}_x86.txt
name                           old time/op   new time/op   delta
---------------------------------------------------------------------------------
AddNonConst/Z1AndZ2EqualsOne    779ns ± 3%    781ns ± 8%     ~  (p=0.353 n=10+10)
AddNonConst/Z1EqualsZ2          882ns ± 5%    881ns ± 4%     ~  (p=0.031 n=9+9)
AddNonConst/Z2EqualsOne        1.30µs ± 1%   1.31µs ± 1%     ~  (p=0.008 n=8+9)
AddNonConst/Generic            1.81µs ± 1%   1.82µs ± 1%     ~  (p=0.002 n=9+10)
DoubleNonConst/ZEqualsOne       682ns ± 3%    682ns ± 2%     ~  (p=0.853 n=10+10)
DoubleNonConst/Generic          778ns ± 1%    778ns ± 2%     ~  (p=0.955 n=10+10)
ScalarBaseMultNonConst         40.0µs ± 2%   40.0µs ± 1%     ~  (p=0.905 n=10+9)
ScalarMultNonConst              186µs ± 2%    186µs ± 1%     ~  (p=0.631 n=10+10)
SigVerify                       233µs ± 1%    234µs ± 4%     ~  (p=0.489 n=9+9)
RecoverCompact                  281µs ± 2%    282µs ± 1%     ~  (p=0.218 n=10+10)
```

Comparison of relevant operations for 64-bit platforms:
```
$ benchstat {before,after}_x64.txt
name                           old time/op   new time/op   delta
------------------------------------------------------------------------------------
AddNonConst/Z1AndZ2EqualsOne    367ns ± 3%    176ns ± 3%   -52.15% (p=0.000 n=8+9)
AddNonConst/Z1EqualsZ2          403ns ± 1%    147ns ± 2%   -63.48% (p=0.000 n=9+9)
AddNonConst/Z2EqualsOne         624ns ± 1%    248ns ± 2%   -60.32% (p=0.000 n=8+10)
AddNonConst/Generic             871ns ± 1%    299ns ± 1%   -65.64% (p=0.000 n=10+10)
DoubleNonConst/ZEqualsOne       298ns ± 2%    165ns ± 1%   -44.69% (p=0.000 n=10+10)
DoubleNonConst/Generic          345ns ± 1%    171ns ± 1%   -50.27% (p=0.000 n=10+9)
ScalarBaseMultNonConst         19.0µs ± 1%    7.6µs ± 1%   -60.09% (p=0.000 n=8+10)
ScalarMultNonConst             85.3µs ± 2%   36.8µs ± 1%   -56.83% (p=0.000 n=9+10)
SigVerify                       107µs ± 2%     47µs ± 1%   -56.63% (p=0.000 n=8+10)
RecoverCompact                  125µs ± 1%     53µs ± 1%   -57.24% (p=0.000 n=9+8)
```

As expected, the 32-bit results are effectively unchanged because those
architectures continue to the existing backend.  However, as shown,
64-bit benefits from significant performance enhancements.
Also, remove repeated content from doc.go since all all doc interfaces
nowadays show the `README.md` too.
@davecgh
davecgh force-pushed the secp256k1_select_backend_per_arch branch from 61bbf6b to 3cb3bb7 Compare November 20, 2026 07:42
@davecgh
davecgh merged commit 3cb3bb7 into decred:master Nov 20, 2026
32 checks passed
@davecgh
davecgh deleted the secp256k1_select_backend_per_arch branch November 20, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants