-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.sh
executable file
·187 lines (166 loc) · 5.45 KB
/
check.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
# Usages:
# (1) to use check.sh with GNU MPFR installed in a non-standard
# place, say /tmp/include and /tmp/lib, use the following
# (LD_LIBRARY_PATH is needed because of dynamic linking):
# LD_LIBRARY_PATH=/tmp/lib CFLAGS=-I/tmp/include LDFLAGS=-L/tmp/lib ./check.sh ...
# (2) to check the GNU libc instead of CORE-MATH:
# CORE_MATH_CHECK_STD=true ./check.sh ...
# (3) to check the GNU libc 2.27, installed in say /tmp/install:
# CORE_MATH_CHECK_STD=true CORE_MATH_LAUNCHER="/tmp/lib/ld-2.27.so --library-path /tmp/lib" LDFLAGS="-L /tmp/lib" ./check.sh --worst --rndn exp
# ensures CI fails in case of an error
set -e
if [ "`which gmake`" != "" ]; then
MAKE=gmake
else
MAKE=make
fi
FUN="${!#}"
ARGS=("${@:1:$#-1}")
MODES=()
for i in "${!ARGS[@]}"; do
case "${ARGS[i]}" in
--rnd*)
MODES+=("${ARGS[i]}")
unset 'ARGS[i]'
;;
--dry)
DRY="true"
unset 'ARGS[i]'
;;
esac
done
if [[ "${#MODES[@]}" -eq 0 ]]; then
MODES=("--rndn" "--rndz" "--rndu" "--rndd")
fi
FILE="$(echo src/*/*/"$FUN".c)"
ORIG_DIR="$(dirname "$FILE")"
if ! [ -d "$ORIG_DIR" ]; then
echo "Could not find $FUN"
exit 1
fi
TMP_DIR="$(mktemp -d -t core-math.XXXXXX)"
trap 'rm -rf "$TMP_DIR"' EXIT
DIR="$TMP_DIR/toto/$(basename "$ORIG_DIR")"
export CORE_MATH_CHECK_STD=true
export LIBM="/home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a"
# export LIBM="/home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a"
mkdir "$TMP_DIR/toto"
cp -a "$ORIG_DIR" "$ORIG_DIR/../support" "$TMP_DIR/toto"
cp -a "$ORIG_DIR/../../generic" "$TMP_DIR"
if [ -n "${ARGS[0]}" ]; then
KIND="${ARGS[0]}"
unset 'ARGS[0]'
else
SIZE=${FILE#src/binary}
SIZE=${SIZE%%/*}
case "$SIZE" in
32)
case "$FUN" in
atan2f)
KIND=--worst;;
atan2pif)
KIND=--worst;;
hypotf)
KIND=--worst;;
powf)
KIND=--worst;;
*)
KIND=--exhaustive;;
esac;;
*)
KIND=--worst
esac
fi
KIND=--worst
if [[ -z "$CORE_MATH_VERBOSE" ]]; then
QUIET=--quiet
else
QUIET=
fi
# define CORE_MATH_NO_OPENMP if you don't want OpenMP
if [[ -z "$CORE_MATH_NO_OPENMP" ]]; then
OPENMP=-fopenmp
else
export CFLAGS="$CFLAGS -DCORE_MATH_NO_OPENMP --libc"
fi
has_symbol () {
[ "$(nm "$LIBM" | while read a b c; do if [ "$c" = "$FUN" ]; then echo OK; return; fi; done | wc -l)" -ge 1 ]
}
if [[ -n "$LIBM" ]] && ! has_symbol; then
echo "Error: symbol $FUN is not present in $LIBM" >&2
exit 2
fi
if [ "$CFLAGS" == "" ]; then
MACHINE=`uname -m`
if [ "$CC" == "clang" ]; then
# clang does not provide -fsignaling-nans
# (https://gitlab.inria.fr/core-math/core-math/-/issues/8)
# -fhonor-nans is needed to disable warnings about __builtin_nan()
# (https://clang.llvm.org/docs/DiagnosticsReference.html#wnan-infinity-disabled)
export CFLAGS="-O3 -march=native -Wshadow -fno-finite-math-only -frounding-math -DCORE_MATH_CHECK_INEXACT -fhonor-nans"
elif [ "$CC" == "icx" ]; then
# icx needs -fp-model=precise and doesn't like -fsignaling-nans
export CFLAGS="-fp-model=precise -O3 -march=native -Wshadow -fno-finite-math-only -frounding-math -DCORE_MATH_CHECK_INEXACT"
elif [ "$MACHINE" == "ppc64le" ]; then
# -march=native is not supported by gcc 14 on ppc64le
export CFLAGS="-O3 -mcpu=native -Wshadow -fno-finite-math-only -frounding-math -fsignaling-nans -DCORE_MATH_CHECK_INEXACT"
else
export CFLAGS="-O3 -march=native -Wshadow -fno-finite-math-only -frounding-math -fsignaling-nans -DCORE_MATH_CHECK_INEXACT"
fi
unset MACHINE
else
# the core-math code assumes -frounding-math
# see also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678
# and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112367
export ROUNDING_MATH="-frounding-math"
fi
# define CORE_MATH_NO_OPENMP if you don't want OpenMP
if [[ -z "$CORE_MATH_NO_OPENMP" ]]; then
if [ "$CC" == "icx" ]; then
OPENMP=-qopenmp # icx prefers -qopenmp
else
OPENMP=-fopenmp
fi
else
export CFLAGS="$CFLAGS -DCORE_MATH_NO_OPENMP"
fi
# add EXTRA_CFLAGS if given
export CFLAGS="$CFLAGS $EXTRA_CFLAGS"
case "$KIND" in
--exhaustive)
"$MAKE" --quiet -C "$DIR" clean
OPENMP=$OPENMP "$MAKE" $QUIET -C "$DIR" check_exhaustive
if [[ -z "$DRY" ]]; then
for MODE in "${MODES[@]}"; do
echo "Running exhaustive check in $MODE mode..."
$CORE_MATH_LAUNCHER "$DIR/check_exhaustive" "$MODE" "${ARGS[@]}"
done
fi
;;
--worst)
"$MAKE" --quiet -C "$DIR" clean
OPENMP=$OPENMP "$MAKE" $QUIET -C "$DIR" check_worst
if [[ -z "$DRY" ]]; then
for MODE in "${MODES[@]}"; do
echo "Running worst cases check in $MODE mode..."
$CORE_MATH_LAUNCHER "$DIR/check_worst" "$MODE" "${ARGS[@]}" < "${FILE%.c}.wc"
done
fi
;;
--special)
"$MAKE" --quiet -C "$DIR" clean
OPENMP=$OPENMP "$MAKE" $QUIET -C "$DIR" check_special
if [[ -z "$DRY" ]]; then
for MODE in "${MODES[@]}"; do
echo "Running special checks in $MODE mode..."
# we also give xxx.wc in input to check --special since some
# functions use it (for example log2)
$CORE_MATH_LAUNCHER "$DIR/check_special" "$MODE" "${ARGS[@]}" < "${FILE%.c}.wc"
done
fi
;;
*)
echo "Unrecognized command"
exit 1
esac