-
Notifications
You must be signed in to change notification settings - Fork 447
/
hts_probe_cc.sh
executable file
·143 lines (130 loc) · 4.11 KB
/
hts_probe_cc.sh
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
#!/bin/sh
# Check compiler options for non-configure builds and create Makefile fragment
#
# Copyright (C) 2022-2024 Genome Research Ltd.
#
# Author: Rob Davies <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# Arguments are:
# 1. C compiler command
# 2. Initial CFLAGS
# 3. LDFLAGS
CC=$1
CFLAGS=$2
LDFLAGS=$3
# Try running the compiler. Uses the same contest.* names as
# configure for temporary files.
run_compiler ()
{
$CC $CFLAGS $1 $LDFLAGS -o conftest conftest.c 2> conftest.err
retval=$?
rm -f conftest.err conftest
return $retval
}
# Run a test. $1 is the flag to try, $2 is the Makefile variable to set
# with the flag probe result, $3 is a Makefile variable which will be
# set to 1 if the code was built successfully. The code to test should
# be passed in via fd 0.
# First try compiling conftest.c without the flag. If that fails, try
# again with it to see if the flag is needed.
run_test ()
{
if [ $have_cpuid -ne 1 ] ; then
# Only test for and build SSE / AVX code if cpuid works as
# otherwise it won't be executed, even if present
echo "$3 ="
return
fi
rm -f conftest conftest.err conftest.c
cat - > conftest.c
if run_compiler ; then
echo "$2 ="
echo "$3 = 1"
elif run_compiler "$1" ; then
echo "$2 = $1"
echo "$3 = 1"
else
echo "$3 ="
fi
}
echo "# Compiler probe results, generated by $0"
# Check for cpuid
rm -f conftest conftest.err conftest.c
cat > conftest.c <<'EOF'
#include <cpuid.h>
#include <stddef.h>
int main(int argc, char **argv) {
unsigned int a, b, c, d;
int level = __get_cpuid_max(0, NULL);
if (level > 0)
__cpuid_count(1, 0, a, b, c, d);
return 0;
}
EOF
if run_compiler ; then
echo "HTS_HAVE_CPUID = 1"
have_cpuid=1
else
echo "HTS_HAVE_CPUID ="
have_cpuid=0
fi
# Check for sse4.1 etc. support
run_test "-msse4.1 -mpopcnt -mssse3" HTS_CFLAGS_SSE4 HTS_BUILD_SSE4 <<'EOF'
#ifdef __x86_64__
#include "x86intrin.h"
int main(int argc, char **argv) {
__m128i a = _mm_set_epi32(1, 2, 3, 4), b = _mm_set_epi32(4, 3, 2, 1);
__m128i c = _mm_shuffle_epi8(_mm_max_epu32(a, b), b);
return _mm_popcnt_u32(*((char *) &c));
}
#else
int main(int argc, char **argv) { return 0; }
#endif
EOF
# Check for avx2
run_test "-mavx2 -mpopcnt" HTS_CFLAGS_AVX2 HTS_BUILD_AVX2 <<'EOF'
#ifdef __x86_64__
#include "x86intrin.h"
int main(int argc, char **argv) {
__m256i a = _mm256_set_epi32(1, 2, 3, 4, 5, 6, 7, 8);
__m256i b = _mm256_add_epi32(a, a);
long long c = _mm256_extract_epi64(b, 0);
return _mm_popcnt_u32((int) c);
}
#else
int main(int argc, char **argv) { return 0; }
#endif
EOF
# Check for avx512
run_test "-mavx512f -mpopcnt" HTS_CFLAGS_AVX512 HTS_BUILD_AVX512 <<'EOF'
#ifdef __x86_64__
#include "x86intrin.h"
int main(int argc, char **argv) {
__m512i a = _mm512_set1_epi32(1);
__m512i b = _mm512_add_epi32(a, a);
__m256i c = _mm512_castsi512_si256(b);
__m256i d = _mm512_extracti64x4_epi64(a, 1);
return _mm_popcnt_u32(*((char *) &c)) + (*(char *) &d);
}
#else
int main(int argc, char **argv) { return 0; }
#endif
EOF
rm -f conftest.c