Repository navigation
secp256k1: Separate generic field64 impls. - #3754
Conversation
7b165e0 to
33262ed
Compare
jholdstock
left a comment
There was a problem hiding this comment.
Not specific to this PR, but I wonder if we want to add a purego test/build to CI to ensure all of the code/test paths are actually exercised by GitHub
33262ed to
28a20b8
Compare
The way I handled it in I suspect that is one of the cleanest ways and would work well for this module too. |
28a20b8 to
2bf8bdc
Compare
I've implemented this via a separate commit now. I modified it slightly from the |
2bf8bdc to
a12dfc5
Compare
|
I noticed I made a small mistake I made when adding the new tests for the On amd64 with BMI2/MULX support: With |
a12dfc5 to
7333cfb
Compare
|
Switched the testing back to use But with the |
7333cfb to
1ed1176
Compare
This modifies the field64 amd64 benchmarks to be more consistent with the approach used for architecture-specific benchmarks in the rest of the code base. This approach is cleaner and makes it easier to add additional specialized implementations in the future.
This renames the field64Mul and field64Square funcs and their variants to include Reduce in their name to make it clear they are fused multiply/square-and-reduce operations unlike the generic arith.Mul512 and field64Reduce512 primitives.
The generic implementations of the fused field multiplication and squaring operations are currently duplicated in the amd64-specific code and the generic fallback code. Rather than duplicate that code, this moves the shared reduction implementation and generic fused multiply/square helpers into field64_generic.go and updates the architecture-specific dispatch to invoke the shared generic implementation when the optimized implementation is unavailable. To accomplish that, a new field64_noasm.go is introduced that only builds when the architecture-specific code is not built. Finally, it moves the amd64 instruction set architecture dispatch into field64isa_amd64.go file so that it only builds on amd64 and clearly separates ISA selection from the implementation itself. These modifications mirror the approach used for architecture-dependent code in the rest of the code base.
This adds tests to ensure all supported variants of the mul and square methods that choose different implementations at run time depending on available hardware are exercised when run on hardware that supports them. In particular, because pure Go is always supported, it ensures the pure Go code paths are for the methods are always tested versus only testing the optimized paths.
1ed1176 to
ae4d56d
Compare
This requires #3753.
The recent additions for dispatching the architecture-dependent field64 implementation in #3734 conflates three distinct concerns:
field64Reduce512)Notably, the generic implementations of the fused field multiplication and squaring operations are currently duplicated in the amd64-specific code and the generic fallback code.
Rather than duplicate that code, this moves the shared reduction implementation and generic fused multiply/square helpers into
field64_generic.goand updates the architecture-specific dispatch to invoke the shared generic implementation when the optimized implementation is unavailable.To accomplish that, a new
field64_noasm.gois introduced that only builds when the architecture-specific code is not built.Finally, it moves the amd64 instruction set architecture dispatch into
field64isa_amd64.gofile so that it only builds onamd64and clearly separates ISA selection from the implementation itself.These modifications mirror the approach used for architecture-dependent code in the rest of the code base.
While here, it also cleans up the associated benchmarks and renames the
field64Mulandfield64Squarefuncs and their variants to includeReducein their name to make it clear they are fused multiply/square-and-reduce operations unlike the genericarith.Mul512andfield64Reduce512primitives.