Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 74f9143

Browse files
committed
test-suite: add cpu features detection in configuration
Summary: This patch adds opportunity to detect cpu features via configuration, which can be used later in Makefiles. I'm preparing some tests, which use specific cpu features, so I don't want them to fail on machines without such features. Unfortunately, most of buildbots use configure+make approach, so I propose this patch for configure and makefiles structure. This additional m4 script is based on "ax_gcc_x86_cpu_support" and "ax_check_x86_features", scripts from autoconf base. Patch with similar feature for cmake - [[https://reviews.llvm.org/D38484|D38484]] Reviewers: zvi, eladcohen, steven_wu, anemet, MatzeB Reviewed By: MatzeB Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38182 git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@321142 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7ee8c3b commit 74f9143

File tree

4 files changed

+1862
-24
lines changed

4 files changed

+1862
-24
lines changed

Makefile.config.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,22 @@ SKIDMARKS10_ROOT := @SKIDMARKS10_ROOT@
229229

230230
# Get the shared library (dll) extension
231231
SHLIBEXT = @SHLIBEXT@
232+
233+
# Get CPU features
234+
HAVE_X86_AVX2_INSTRUCTIONS := @HAVE_X86_AVX2_INSTRUCTIONS@
235+
HAVE_X86_AVX512F_INSTRUCTIONS := @HAVE_X86_AVX512F_INSTRUCTIONS@
236+
HAVE_X86_AVX512VL_INSTRUCTIONS := @HAVE_X86_AVX512VL_INSTRUCTIONS@
237+
HAVE_X86_AVX512BW_INSTRUCTIONS := @HAVE_X86_AVX512BW_INSTRUCTIONS@
238+
HAVE_X86_AVX512DQ_INSTRUCTIONS := @HAVE_X86_AVX512DQ_INSTRUCTIONS@
239+
HAVE_X86_AVX_INSTRUCTIONS := @HAVE_X86_AVX_INSTRUCTIONS@
240+
HAVE_X86_BMI2_INSTRUCTIONS := @HAVE_X86_BMI2_INSTRUCTIONS@
241+
HAVE_X86_BMI_INSTRUCTIONS := @HAVE_X86_BMI_INSTRUCTIONS@
242+
HAVE_X86_FMA4_INSTRUCTIONS := @HAVE_X86_FMA4_INSTRUCTIONS@
243+
HAVE_X86_FMA_INSTRUCTIONS := @HAVE_X86_FMA_INSTRUCTIONS@
244+
HAVE_X86_MMX_INSTRUCTIONS := @HAVE_X86_MMX_INSTRUCTIONS@
245+
HAVE_X86_POPCNT_INSTRUCTIONS := @HAVE_X86_POPCNT_INSTRUCTIONS@
246+
HAVE_X86_SSE2_INSTRUCTIONS := @HAVE_X86_SSE2_INSTRUCTIONS@
247+
HAVE_X86_SSE3_INSTRUCTIONS := @HAVE_X86_SSE3_INSTRUCTIONS@
248+
HAVE_X86_SSE4_1_INSTRUCTIONS := @HAVE_X86_SSE4_1_INSTRUCTIONS@
249+
HAVE_X86_SSE4_2_INSTRUCTIONS := @HAVE_X86_SSE4_2_INSTRUCTIONS@
250+
HAVE_X86_SSE_INSTRUCTIONS := @HAVE_X86_SSE_INSTRUCTIONS@

autoconf/configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,13 @@ AC_PROG_CPP
359359

360360
dnl Verify that GCC is version 3.0 or higher
361361

362+
dnl Get CPU features
363+
if (test "$llvm_cv_target_arch" == "x86" ||
364+
test "$llvm_cv_target_arch" == "x86_64")
365+
then
366+
CHECK_X86_FEATURES
367+
fi
368+
362369
dnl Check for GNU Make. We use its extensions too, so don't build without it
363370
AC_CHECK_GNU_MAKE
364371
if test -z "$llvm_cv_gnu_make_command" ; then

autoconf/m4/get_cpu_target.m4

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
dnl This macro checks features using gcc and cpuinit
2+
dnl Set variables HAVE_X86_$feature_INSTRUCTIONS into
3+
dnl the configure.config.
4+
dnl Based on ax_gcc_x86_cpu_support and ax_check_x86_features.
5+
6+
AC_DEFUN_ONCE([CPU_INIT],
7+
[AC_LANG_PUSH([C])
8+
AC_CACHE_CHECK([for gcc __builtin_cpu_init function],
9+
[ax_cv_check_x86_cpu_init],
10+
[AC_RUN_IFELSE(
11+
[AC_LANG_PROGRAM([#include <stdlib.h>],
12+
[__builtin_cpu_init ();])
13+
],
14+
[ax_cv_check_x86_cpu_init=yes],
15+
[ax_cv_check_x86_cpu_init=no])])
16+
AS_IF([test "X$ax_cv_check_x86_cpu_init" = "Xno"],
17+
[AC_MSG_ERROR([Need GCC to support X86 CPU features tests])])
18+
])
19+
20+
AC_DEFUN([CPU_SUPPORTS],
21+
[AC_REQUIRE([AC_PROG_CC])
22+
AC_REQUIRE([CPU_INIT])
23+
AC_LANG_PUSH([C])
24+
AS_VAR_PUSHDEF([feature], [AS_TR_SH([ax_cv_cpu_supports_$1])])
25+
AC_CACHE_CHECK([for x86 $1 instruction support],
26+
[feature],
27+
[AC_RUN_IFELSE(
28+
[AC_LANG_PROGRAM( [#include <stdlib.h> ],
29+
[ __builtin_cpu_init ();
30+
if (__builtin_cpu_supports("$1"))
31+
return 0;
32+
return 1;
33+
])],
34+
[feature=yes],
35+
[feature=no]
36+
)]
37+
)
38+
AC_LANG_POP([C])
39+
AS_IF([test "$feature" = "yes"],
40+
[AC_SUBST(
41+
AS_TR_CPP([HAVE_X86_$1_INSTRUCTIONS]),
42+
[1],
43+
[Define if $1 instructions are supported])
44+
],
45+
[AC_SUBST(
46+
AS_TR_CPP([HAVE_X86_$1_INSTRUCTIONS]),
47+
[0])
48+
]
49+
)
50+
AS_VAR_POPDEF([feature])
51+
])
52+
53+
54+
AC_DEFUN([CHECK_X86_FEATURES],
55+
[m4_foreach_w(
56+
[feature],
57+
[mmx popcnt sse sse2 sse3 sse4.1 sse4.2 avx avx2 avx512f avx512vl avx512bw avx512dq fma fma4 bmi bmi2],
58+
[CPU_SUPPORTS(feature)])
59+
$2
60+
])
61+

0 commit comments

Comments
 (0)