From ca68b59475f6b1773fa62e6dbc4b68349602b441 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 12 Sep 2024 16:55:28 +0200 Subject: Update build files to enable multithreading --- configure.sh | 73 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 21 deletions(-) (limited to 'configure.sh') diff --git a/configure.sh b/configure.sh index 34da488..03873e5 100755 --- a/configure.sh +++ b/configure.sh @@ -1,51 +1,82 @@ #!/bin/sh -cc=${CC:-cc} +greparch() { + $CC -march=native -dM -E - /dev/null | grep "$1" +} + +grepsan() { + $CC -fsanitize=$1 -dM -E -x c - /dev/null | grep "SANITIZE" +} + +detectthreads() { + echo 16 # TODO: choose based on system +} detectarch() { - ${cc} -march=native -dM -E - /dev/null | grep "$1" + [ -n "$(greparch __AVX2__)" ] && detected="AVX2" + [ -n "$(greparch __ARM_NEON)" ] && detected="NEON" + [ -z "$detected" ] && detected="PORTABLE" + + echo "$detected" } -detectsan() { - ${cc} -fsanitize=$1 -dM -E -x c - /dev/null \ - | grep "SANITIZE" + +validatecc() { + if ! (which "$CC" >/dev/null 2>&1) ; then + echo "Error: compiler '$CC' not found" + exit 1 + fi } -[ -n "$(detectarch __AVX2__)" ] && detected="AVX2" -[ -n "$(detectarch __ARM_NEON)" ] && detected="NEON" -[ -z "$detected" ] && detected="PORTABLE" +validatethreads() { + if [ "$THREADS" -le 0 ] || [ "$THREADS" -gt 128 ]; then + echo "Error: number of threads must be between 1 and 128" + exit 1 + fi +} + +validatearch() { + case "$ARCH" in + AVX2|NEON|PORTABLE) + ;; + *) + echo "Error: architecture '$ARCH' not supported" + exit 1 + ;; + esac +} -ARCH=${ARCH-"$detected"} +CC=${CC:-cc} +THREADS=${THREADS-"$(detectthreads)"} +ARCH=${ARCH-"$(detectarch)"} -case "$ARCH" in -AVX2|NEON|PORTABLE) - ;; -*) - echo "Error: architecture $ARCH not supported" - exit 1 - ;; -esac +validatecc +validatethreads +validatearch STD="-std=c99" WFLAGS="-pedantic -Wall -Wextra" WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas" [ "$ARCH" = "AVX2" ] && AVX="-mavx2" -[ -n "$(detectsan address)" ] && ADDR="-fsanitize=address" -[ -n "$(detectsan undefined)" ] && UNDEF="-fsanitize=undefined" +[ -n "$(grepsan address)" ] && ADDR="-fsanitize=address" +[ -n "$(grepsan undefined)" ] && UNDEF="-fsanitize=undefined" SAN="$ADDR $UNDEF" LIBS="-lpthread" CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3" DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG" +MACROS="-DTHREADS=$THREADS -D$ARCH" echo "Selected architecture: $ARCH" -echo "Compiler: ${CC:-cc}" +echo "Number of threads: $THREADS" +echo "Compiler: $CC" { echo "ARCH = $ARCH"; echo ""; echo "CFLAGS = $CFLAGS"; echo "DBGFLAGS = $DBGFLAGS"; +echo "MACROS = $MACROS" echo ""; -echo "CC = ${cc}" +echo "CC = $CC" } > config.mk -- cgit v1.3