Skip to content

Commit

Permalink
Use the new BLST no assembly fallback on 32-bit (#96)
Browse files Browse the repository at this point in the history
* Use the new BLST no assembly fallback on 32-bit

* Update the tests as well

* Revert "Use the new BLST no assembly fallback on 32-bit"

This reverts commit c8b0619.

* Keep the fallback to Miracl for PowerPC / IBM Z / MIPS / Itanium ...

* typo

* Skip BLST in PowerPC CI
  • Loading branch information
mratsim authored Dec 4, 2020
1 parent 8a5fc68 commit 282d1f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 3 additions & 2 deletions blscurve.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ task test, "Run all tests":
# Internal BLS API - IETF standard
# test "", "tests/hash_to_curve_v7.nim"

# Public BLS API - IETF standard / Ethereum2.0 v0.12.x
# Public BLS API - IETF standard / Ethereum2.0 v1.0.0
test "-d:BLS_FORCE_BACKEND=miracl", "tests/eth2_vectors.nim"
# key Derivation - EIP 2333
test "-d:BLS_FORCE_BACKEND=miracl", "tests/eip2333_key_derivation.nim"
# Secret key to pubkey
test "-d:BLS_FORCE_BACKEND=miracl", "tests/priv_to_pub.nim"

when sizeof(int) == 8 and (defined(arm64) or defined(amd64)):
when defined(arm64) or defined(arm) or
defined(amd64) or defined(i386):
test "-d:BLS_FORCE_BACKEND=blst", "tests/eth2_vectors.nim"
test "-d:BLS_FORCE_BACKEND=blst", "tests/eip2333_key_derivation.nim"
test "-d:BLS_FORCE_BACKEND=blst", "tests/priv_to_pub.nim"
Expand Down
21 changes: 13 additions & 8 deletions blscurve/bls_backend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ type BlsBackendKind* = enum
BLST
Miracl

when BLS_FORCE_BACKEND == "blst" or (
BLS_FORCE_BACKEND == "auto" and
sizeof(int) == 8 and
(defined(arm64) or (
defined(amd64) and
gorgeEx(getEnv("CC", "gcc") & " -march=native -dM -E -x c /dev/null | grep -q SSSE3").exitCode == 0))
const AutoSelectBLST = BLS_FORCE_BACKEND == "auto" and (
defined(arm64) or defined(arm) or
defined(amd64) or defined(i386)
)
# Theoretically the BLST library has a fallback for any platform
# but it is missing https://github.com/supranational/blst/issues/46

when (BLS_FORCE_BACKEND == "blst" or AutoSelectBLST) and (
gorgeEx(getEnv("CC", "gcc") & " -march=native -dM -E -x c /dev/null | grep -q SSSE3").exitCode == 0
):
# BLST supports: x86_64 and ARM64
# BLST supports: x86 and ARM 32 and 64 bits
# and has optimized SHA256 routines for x86_64 CPU with SSE3
# It also assumes that all ARM CPUs are Neon instructions capable for SHA256
const BLS_BACKEND* = BLST
elif BLS_FORCE_BACKEND == "auto" and defined(amd64):
elif BLS_FORCE_BACKEND == "blst" or AutoSelectBLST:
# CPU doesn't support SSE3 which is used in optimized SHA256
# BLST_PORTABLE is a no-op on ARM
const BLS_BACKEND* = BLST
{.passC: "-D__BLST_PORTABLE__".}
else:
Expand Down

0 comments on commit 282d1f6

Please sign in to comment.