github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/crypto_adx_flag.mk (about)

     1  # This script can be imported by Makefiles in order to set the `CRYPTO_FLAG` automatically for 
     2  # a native build (build and run on the same machine NOT for cross-compilation).
     3  #
     4  # The `CRYPTO_FLAG` is a Go command flag that should be used when the target machine's CPU executing 
     5  # the command may not support ADX instructions.
     6  # For new machines that support ADX instructions, the `CRYPTO_FLAG` flag is not needed (or set
     7  # to an empty string).  
     8  
     9  # First detect ADX support:
    10  # `ADX_SUPPORT` is 1 if ADX instructions are supported on the current machine and 0 otherwise.
    11  ifeq ($(shell uname -s),Linux)
    12  # detect ADX support on the CURRENT linux machine.
    13  	ADX_SUPPORT := $(shell if ([ -f "/proc/cpuinfo" ] && grep -q -e '^flags.*\badx\b' /proc/cpuinfo); then echo 1; else echo 0; fi)
    14  else
    15  # on non-linux machines, set the flag to 1 by default
    16  	ADX_SUPPORT := 1
    17  endif
    18  
    19  DISABLE_ADX := "-O2 -D__BLST_PORTABLE__"
    20  
    21  # Then, set `CRYPTO_FLAG`
    22  # the crypto package uses BLST source files underneath which may use ADX instructions.
    23  ifeq ($(ADX_SUPPORT), 1)
    24  # if ADX instructions are supported on the current machine, default is to use a fast ADX implementation 
    25  	CRYPTO_FLAG := ""
    26  else
    27  # if ADX instructions aren't supported, this CGO flags uses a slower non-ADX implementation 
    28  	CRYPTO_FLAG := $(DISABLE_ADX)
    29  endif