Skip to content

secp256k1: Add internal cpufeat package. - #3753

Merged
davecgh merged 4 commits into
decred:masterfrom
davecgh:secp256k1_internal_cpufeat
Nov 20, 2026
Merged

davecgh merged 4 commits into
decred:masterfrom
davecgh:secp256k1_internal_cpufeat

Conversation

@davecgh

@davecgh davecgh commented Jul 27, 2026

Copy link
Copy Markdown
Member

This is rebased on #3752.

The current CPU feature detection for the recently added MULX/ADX optimizations is done directly in the field64 code. There is nothing wrong with this from a purely functional standpoint, but it is difficult to extend and can't be reused across other packages in the module.

With that in mind, this adds an internal package to detect support for CPU and operating system features that are relevant to architecture-specific optimizations throughout the secp256k1 package.

The package intentionally provides a minimal abstraction consisting only of the feature detection required by the secp256k1 implementation.

This provides a clean mechanism for detecting and supporting new hardware extensions in the future.

Finally, it updates the field64 code to use the new cpufeat package for feature detection instead of doing it manually inline.

@davecgh davecgh added this to the 2.2.0 milestone Jul 27, 2026
@davecgh
davecgh force-pushed the secp256k1_internal_cpufeat branch 3 times, most recently from 90f9006 to fdfdeaa Compare July 27, 2026 21:04
@davecgh
davecgh force-pushed the secp256k1_internal_cpufeat branch 2 times, most recently from 799c120 to ecc3151 Compare July 29, 2026 00:30
@davecgh
davecgh force-pushed the secp256k1_internal_cpufeat branch 2 times, most recently from b1d0d74 to f266edf Compare July 29, 2026 08:17
The current CPU feature detection for the recently added MULX/ADX
optimizations is done directly in the field64 code.  There is nothing
wrong with this from a purely functional standpoint, but it is difficult
to extend and can't be reused across other packages in the module.

With that in mind, this adds an internal package to detect support for
CPU and operating system features that are relevant to
architecture-specific optimizations throughout the secp256k1 package.

The package intentionally provides a minimal abstraction consisting only
of the feature detection required by the secp256k1 implementation.

This provides a clean mechanism for detecting and supporting new
hardware extensions in the future.

Note that does not incorporate the package yet.  It only introduces the
new code.
This adds dedicated tests for the functions in the new internal cpufeat
package.

Since the specific values depend on the hardware, this avoids asserting
specific values that would fail when not running on specific hardware
and instead focuses on ensuring the functions are idempotent.
This updates the field64 code to use the new cpufeat package for feature
detection instead of doing it manually inline.
@davecgh
davecgh force-pushed the secp256k1_internal_cpufeat branch from f266edf to 1dd546e Compare November 20, 2026 07:15
@davecgh
davecgh merged commit 1dd546e into decred:master Nov 20, 2026
32 checks passed
@davecgh
davecgh deleted the secp256k1_internal_cpufeat branch November 20, 2026 07:27
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