From d8507efcc7bb781662aa91dcd818e990c6cb2452 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 25 Jul 2023 17:55:15 +0200 Subject: [PATCH] blst: bump (#155) * blst: bump runtime cpu detection and assortment of fixes * using gnu99 instead of c99 to accomodate stint asm optimization --------- Co-authored-by: jangko --- blscurve/bls_backend.nim | 37 ++++++------------------------------- blscurve/miracl/milagro.nim | 10 +++++++++- vendor/blst | 2 +- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/blscurve/bls_backend.nim b/blscurve/bls_backend.nim index 22135e7..743226c 100644 --- a/blscurve/bls_backend.nim +++ b/blscurve/bls_backend.nim @@ -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 diff --git a/blscurve/miracl/milagro.nim b/blscurve/miracl/milagro.nim index 7030099..1d4804d 100644 --- a/blscurve/miracl/milagro.nim +++ b/blscurve/miracl/milagro.nim @@ -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 diff --git a/vendor/blst b/vendor/blst index ca03e11..4967efe 160000 --- a/vendor/blst +++ b/vendor/blst @@ -1 +1 @@ -Subproject commit ca03e11a3ff24d818ae390a1e7f435f15bf72aee +Subproject commit 4967efe5c49b5abd09895ffa31d54e308835ab15