commit a9ce50120b68db3669aaadeac348db8926bc15c4
parent c5fb4d1c0f0ecc30673a46e517dc82c5af2af5ef
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun, 19 Nov 2023 11:19:14 +0100
Improved architecture detection
Diffstat:
3 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/configure.sh b/configure.sh
@@ -1,8 +1,13 @@
#!/bin/sh
-cc -mavx2 utils/detect-immintrin.c && detected="AVX2" && rm a.out
+detect() { cc -march=native -dM -E - < /dev/null | grep "$1"; }
+
+[ -n "$(detect __AVX2__)" ] && detected="AVX2"
+
TYPE=${TYPE-"$detected"}
+echo "Using CUBE_$TYPE"
+
STD="-std=c99"
WFLAGS="-pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function"
[ "$TYPE" = "AVX2" ] && AVX="-mavx2"
diff --git a/cube.c b/cube.c
@@ -2,9 +2,7 @@
#include <stdbool.h>
#include <string.h>
-#ifdef CUBE_AVX2
-#include <immintrin.h>
-#endif
+#include "cube.h"
#ifdef DEBUG
#include <stdio.h>
@@ -25,8 +23,6 @@
#define DBG_ASSERT(condition, retval, ...)
#endif
-#include "cube.h"
-
/******************************************************************************
Section: constants, strings and other stuff
******************************************************************************/
@@ -495,6 +491,8 @@ Note: the #ifdef below is closed in the next section.
#ifdef CUBE_AVX2
+#include <immintrin.h>
+
typedef __m256i cube_fast_t;
#define _co2_avx2 _mm256_set_epi64x(0, 0, 0, 0x6060606060606060)
diff --git a/utils/detect-immintrin.c b/utils/detect-immintrin.c
@@ -1,5 +0,0 @@
-#include <immintrin.h>
-
-int main() {
- return 0;
-}