xref: /freebsd/contrib/arm-optimized-routines/pl/math/test/runulp.sh (revision 5a02ffc32e777041dd2dad4e651ed2a0865a0a5d)
1#!/bin/bash
2
3# ULP error check script.
4#
5# Copyright (c) 2019-2023, Arm Limited.
6# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
7
8#set -x
9set -eu
10
11# cd to bin directory.
12cd "${0%/*}"
13
14flags="${ULPFLAGS:--q}"
15emu="$@"
16
17# Enable SVE testing
18WANT_SVE_MATH=${WANT_SVE_MATH:-0}
19
20FAIL=0
21PASS=0
22
23t() {
24	routine=$1
25	L=$(cat $LIMITS | grep "^$routine " | awk '{print $2}')
26	[[ $L =~ ^[0-9]+\.[0-9]+$ ]]
27	extra_flags=
28	[[ -z "${5:-}" ]] || extra_flags="$extra_flags -c $5"
29	grep -q "^$routine$" $FENV || extra_flags="$extra_flags -f"
30	IFS=',' read -ra LO <<< "$2"
31	IFS=',' read -ra HI <<< "$3"
32	ITV="${LO[0]} ${HI[0]}"
33	for i in "${!LO[@]}"; do
34	[[ "$i" -eq "0" ]] || ITV="$ITV x ${LO[$i]} ${HI[$i]}"
35	done
36	# Add -z flag to ignore zero sign for vector routines
37	{ echo $routine | grep -q "ZGV"; } && extra_flags="$extra_flags -z"
38	$emu ./ulp -e $L $flags ${extra_flags} $routine $ITV $4 && PASS=$((PASS+1)) || FAIL=$((FAIL+1))
39}
40
41check() {
42	$emu ./ulp -f -q "$@" #>/dev/null
43}
44
45if [ "$FUNC" == "atan2" ] || [ -z "$FUNC" ]; then
46    # Regression-test for correct NaN handling in atan2
47    check atan2 0x1p-1022 0x1p-1000 x 0 0x1p-1022 40000
48    check atan2 0x1.7887a0a717aefp+1017 0x1.7887a0a717aefp+1017 x -nan -nan
49    check atan2 nan nan x -nan -nan
50fi
51
52# vector functions
53flags="${ULPFLAGS:--q}"
54runsv=
55if [ $WANT_SVE_MATH -eq 1 ]; then
56# No guarantees about powi accuracy, so regression-test for exactness
57# w.r.t. the custom reference impl in ulp_wrappers.h
58check -q -f -e 0 _ZGVsMxvv_powi  0  inf x  0  1000 100000 && runsv=1
59check -q -f -e 0 _ZGVsMxvv_powi -0 -inf x  0  1000 100000 && runsv=1
60check -q -f -e 0 _ZGVsMxvv_powi  0  inf x -0 -1000 100000 && runsv=1
61check -q -f -e 0 _ZGVsMxvv_powi -0 -inf x -0 -1000 100000 && runsv=1
62check -q -f -e 0 _ZGVsMxvv_powk  0  inf x  0  1000 100000 && runsv=1
63check -q -f -e 0 _ZGVsMxvv_powk -0 -inf x  0  1000 100000 && runsv=1
64check -q -f -e 0 _ZGVsMxvv_powk  0  inf x -0 -1000 100000 && runsv=1
65check -q -f -e 0 _ZGVsMxvv_powk -0 -inf x -0 -1000 100000 && runsv=1
66fi
67
68while read F LO HI N C
69do
70	t $F $LO $HI $N $C
71done << EOF
72$(cat $INTERVALS | grep "\b$FUNC\b")
73EOF
74
75[ 0 -eq $FAIL ] || {
76	echo "FAILED $FAIL PASSED $PASS"
77	exit 1
78}
79