Skip to content

Commit

Permalink
Merge branch 'master' into multi-parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
zah authored Jul 25, 2023
2 parents be1ad53 + d8507ef commit 47e79bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
37 changes: 6 additions & 31 deletions blscurve/bls_backend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,15 @@ type BlsBackendKind* = enum
Miracl

const UseBLST = BLS_FORCE_BACKEND == "auto" or BLS_FORCE_BACKEND == "blst"
const OnX86 = defined(i386) or defined(amd64)
const OnARM = defined(arm) or defined(arm64)

when UseBLST:
when OnX86:
import os, strutils
# BLST defaults to SSSE3 for SHA256 (Pentium 4, 2004). To disable that, we
# need a "portable" build.
#
# It also autodetects MULX and ADCX/ADOX for bigints (Intel Broadwell 2015,
# AMD Ryzen 2017) by looking at a C preprocessor define (__ADX__) set when
# "-march=native" or "-madx" are used on a CPU that supports this extension.
when defined(windows):
const GccDefines = gorgeEx(getEnv("CC", "gcc") & " -march=native -dM -E -x c NUL").output
else:
const GccDefines = gorgeEx(getEnv("CC", "gcc") & " -march=native -dM -E -x c /dev/null").output
const BLSTuseSSSE3 {.intdefine.} = find(GccDefines, "SSSE3") != -1
when not BLSTuseSSSE3:
static: echo "BLST: not using SSSE3"
{.passC: "-D__BLST_PORTABLE__".}
elif OnARM:
# On ARM, BLST can use hardware SHA256.
# This is the case for all ARM 64-bit device except Raspberry Pis.
# BLST detects at compile-time the support via
# the __ARM_FEATURE_CRYPTO compile-time define
#
# It is set either with -march=native on a proper CPU
# or -march=armv8-a+crypto
# and can be disabled with -D__BLST_PORTABLE__

# {.passC: "-D__BLST_PORTABLE__".}
discard
when defined(amd64) or defined(arm64):
# BLST has assembly routines and detects the most profitable one at runtime
# when `__BLST_PORTABLE__` is set
{.passc: "-D__BLST_PORTABLE__".}
else:
{.passC: "-D__BLST_NO_ASM__".}
# WASM and others - no specialised assembly code available
{.passc: "-D__BLST_NO_ASM__".}
const BLS_BACKEND* = BLST
else:
# Miracl
Expand Down
10 changes: 9 additions & 1 deletion blscurve/miracl/milagro.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@

{.push raises: [].} # C functions don't raise

const
GCC_Compatible = defined(gcc) or defined(clang) or defined(llvm_gcc)

when not defined(cpp) or defined(objc) or defined(js):
{.passc: "-std=c99".}
when GCC_Compatible and (NimMajor, NimMinor) <= (1,6):
# nim-stint asm optimization is using
# gnu extensions
{.passc: "-std=gnu99".}
else:
{.passc: "-std=c99".}

import strutils
from os import DirSep
Expand Down
2 changes: 1 addition & 1 deletion vendor/blst
Submodule blst updated 102 files

0 comments on commit 47e79bf

Please sign in to comment.