-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
configure.ac
146 lines (125 loc) · 3.85 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#
# configure.ac -- Autoconf script for simdzone
#
# Copyright (c) 2022-2023, NLnet Labs. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# This file is intended for inclusion by configure.ac in NSD. Support for any
# platform not supported by NSD here is undesirable. Builds for standalone use
# or development/testing are required to use CMake.
AC_INIT([simdzone],[0.1.0],[https://github.com/NLnetLabs/simdzone/issues])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])
m4_include(m4/ax_check_compile_flag.m4)
m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_STDC])
AC_CHECK_HEADERS([endian.h sys/endian.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_DECLS([bswap16,bswap32,bswap64], [], [], [
AC_INCLUDES_DEFAULT
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
])
AC_ARG_ENABLE(westmere, AS_HELP_STRING([--disable-westmere],[Disable Westmere (SSE4.2) kernel]))
case "$enable_westmere" in
no) enable_westmere=no ;;
yes|*) enable_westmere=yes ;;
esac
AC_ARG_ENABLE(haswell, AS_HELP_STRING([--disable-haswell],[Disable Haswell (AVX2) kernel]))
case "$enable_haswell" in
no) enable_haswell=no ;;
yes|*) enable_haswell=yes ;;
esac
# GCC and Clang
AX_CHECK_COMPILE_FLAG([-MMD],DEPFLAGS="-MMD -MP")
# Oracle Developer Studio (no -MP)
AX_CHECK_COMPILE_FLAG([-xMMD],DEPFLAGS="-xMMD")
AC_SUBST([DEPFLAGS])
# Figure out the canonical target architecture.
AC_CANONICAL_TARGET
# Multiple instruction sets may be supported by a specific architecture.
# e.g. x86_64 may (or may not) support any of SSE42, AVX2 and AVX-512. The
# best instruction set is automatically selected at runtime, but the compiler
# may or may not support generating code for an instruction set.
case "$target" in
*amd64*) x86_64=yes ;;
*x86_64*) x86_64=yes ;;
*) x86_64=no ;;
esac
HAVE_WESTMERE=NO
HAVE_HASWELL=NO
if test $x86_64 = "yes"; then
AC_CHECK_HEADER(immintrin.h,,,)
AX_CHECK_COMPILE_FLAG([-march=westmere],,,[-Werror])
AX_CHECK_COMPILE_FLAG([-march=haswell],,,[-Werror])
# Check if the arch instruction set support includes the simd instructions.
if test $enable_westmere != "no" -a \
$ax_cv_check_cflags__Werror__march_westmere = "yes" -a \
$ac_cv_header_immintrin_h = "yes" ; then
AC_MSG_CHECKING(whether -march=westmere works)
BAKCFLAGS="$CFLAGS"
CFLAGS="-march=westmere $CFLAGS"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
[
#include <stdint.h>
#include <immintrin.h>
int main(int argc, char *argv[])
{
(void)argv;
uint64_t popcnt = _mm_popcnt_u64((uint64_t)argc);
return popcnt == 11;
}
]])
],[
AC_DEFINE(HAVE_WESTMERE, 1, [Wether or not to compile support for SSE4.2])
HAVE_WESTMERE=WESTMERE
AC_MSG_RESULT(yes)
],[
AC_MSG_RESULT(no)
])
CFLAGS="$BAKCFLAGS"
fi
if test $enable_haswell != "no" -a \
$ax_cv_check_cflags__Werror__march_haswell = "yes" -a \
$ac_cv_header_immintrin_h = "yes" ; then
AC_MSG_CHECKING(whether -march=haswell works)
BAKCFLAGS="$CFLAGS"
CFLAGS="-march=haswell $CFLAGS"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
[
#include <stdint.h>
#include <immintrin.h>
int main(int argc, char *argv[])
{
(void)argv;
int argc32x8[8] = { argc, 0, 0, 0, 0, 0, 0, 0 };
__m256i argc256 = _mm256_loadu_si256((__m256i *)argc32x8);
return _mm256_testz_si256(argc256, _mm256_set1_epi8(11));
}
]])
],[
AC_DEFINE(HAVE_HASWELL, 1, [Wether or not to compile support for AVX2])
HAVE_HASWELL=HASWELL
AC_MSG_RESULT(yes)
],[
AC_MSG_RESULT(no)
])
CFLAGS="$BAKCFLAGS"
fi
fi
AC_CHECK_FUNCS([realpath],,[AC_MSG_ERROR([realpath is not available])])
AC_SUBST([HAVE_ENDIAN_H])
AC_SUBST([HAVE_WESTMERE])
AC_SUBST([HAVE_HASWELL])
AH_BOTTOM([
/* Defines _XOPEN_SOURCE and _POSIX_C_SOURCE implicitly in features.h */
#ifndef _DEFAULT_SOURCE
# define _DEFAULT_SOURCE 1
#endif
])
AC_OUTPUT