0

I'm using the blake2b hash in my program on all platforms. However the blake2s hash is more efficient on non-64bit architectures. Is it possible to have the 64bit file compiled on 64bit systems and the blake2s file compiled on all others?

- BLAKE2b (or just BLAKE2) is optimized for 64-bit platforms—including NEON-enabled ARMs—and produces digests of any size between 1 and 64 bytes
- BLAKE2s is optimized for 8- to 32-bit platforms and produces digests of any size between 1 and 32 bytes

Source: https://blake2.net/

The only thing I can think of is to manually list all 64bit architectures in one file and negate them in the other. This would work but isn't clean and would need to be updated every time a new architecture is added.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Awn
  • 817
  • 1
  • 16
  • 33
  • There is no single built-in build constraint for 64-bit architectures. You can either do as you suggested (list all the GOARCH) or use a build tag of your own making and specify the tag yourself when building. – Adrian May 16 '19 at 18:27
  • @Adrian What about a runtime check that would initialise the hash function at the start with one of the two implementations? – Awn May 16 '19 at 18:30
  • Based on what? It seems like that just pushes your GOARCH problem from compile time to run time. – Adrian May 16 '19 at 18:33
  • Look at this SO question https://stackoverflow.com/questions/5272825/detecting-64bit-compile-in-c It may solve your problem. – Alain Merigot May 16 '19 at 19:24
  • @Alain Merigot the UINTPTR_MAX solution looks interesting. Might be able to do unsafe.Sizeof on a uintptr type to ascertain the width. – Awn May 17 '19 at 01:08

0 Answers0