diff --git a/lib/libc/riscv/gen/fabs.S b/lib/libc/riscv/gen/fabs.S
index 44249252e9c1..036d50eddf90 100644
--- a/lib/libc/riscv/gen/fabs.S
+++ b/lib/libc/riscv/gen/fabs.S
@@ -1,43 +1,50 @@
/*-
* Copyright (c) 2015-2017 Ruslan Bukin
+ * Copyright (c) 2021 Alex Richardson
* All rights reserved.
*
* Portions of this software were developed by SRI International and the
* University of Cambridge Computer Laboratory under DARPA/AFRL contract
* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
*
* Portions of this software were developed by the University of Cambridge
* Computer Laboratory as part of the CTSRD Project, with support from the
* UK Higher Education Innovation Fund (HEIF).
*
+ * This work was supported by Innovate UK project 105694, "Digital Security
+ * by Design (DSbD) Technology Platform Prototype".
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include
__FBSDID("$FreeBSD$");
-#ifdef __riscv_float_abi_double
ENTRY(fabs)
+#ifdef __riscv_float_abi_double
fabs.d fa0, fa0
+#else
+ slli a0, a0, 1
+ srli a0, a0, 1
+#endif
ret
END(fabs)
-#endif
diff --git a/lib/msun/tests/Makefile b/lib/msun/tests/Makefile
index 67a38855309e..902d1ca22f73 100644
--- a/lib/msun/tests/Makefile
+++ b/lib/msun/tests/Makefile
@@ -1,106 +1,110 @@
# $FreeBSD$
.include
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libm
# All architectures on FreeBSD have fenv.h
CFLAGS+= -DHAVE_FENV_H
# For isqemu.h
CFLAGS+= -I${TESTSRC:H}/libc/gen
# Define __HAVE_LONG_DOUBLE for architectures whose long double has greater
# precision than their double.
.if ${MACHINE_CPUARCH} == "aarch64" || \
${MACHINE_CPUARCH} == "amd64" || \
${MACHINE_CPUARCH} == "i386" || \
${MACHINE_CPUARCH} == "riscv"
CFLAGS+= -D__HAVE_LONG_DOUBLE
.endif
+# Avoid builtins, to force the compiler to emit calls to the libm
+# functions, and not calculate any results in advance.
+CFLAGS+= -fno-builtin
+
NETBSD_ATF_TESTS_C= acos_test
NETBSD_ATF_TESTS_C+= asin_test
NETBSD_ATF_TESTS_C+= atan_test
NETBSD_ATF_TESTS_C+= cbrt_test
NETBSD_ATF_TESTS_C+= ceil_test
NETBSD_ATF_TESTS_C+= casinh_test
NETBSD_ATF_TESTS_C+= cos_test
NETBSD_ATF_TESTS_C+= cosh_test
NETBSD_ATF_TESTS_C+= erf_test
NETBSD_ATF_TESTS_C+= exp_test
NETBSD_ATF_TESTS_C+= fmod_test
NETBSD_ATF_TESTS_C+= fe_round_test
NETBSD_ATF_TESTS_C+= hypot_test
NETBSD_ATF_TESTS_C+= infinity_test
NETBSD_ATF_TESTS_C+= ilogb_test
NETBSD_ATF_TESTS_C+= ldexp_test
NETBSD_ATF_TESTS_C+= log_test
NETBSD_ATF_TESTS_C+= pow_test
NETBSD_ATF_TESTS_C+= precision_test
NETBSD_ATF_TESTS_C+= round_test
NETBSD_ATF_TESTS_C+= scalbn_test
NETBSD_ATF_TESTS_C+= sin_test
NETBSD_ATF_TESTS_C+= sinh_test
NETBSD_ATF_TESTS_C+= sqrt_test
NETBSD_ATF_TESTS_C+= tan_test
NETBSD_ATF_TESTS_C+= tanh_test
TAP_TESTS_C+= cexp_test
TAP_TESTS_C+= conj_test
.if ${MACHINE_CPUARCH} != "aarch64"
# Hits an assert in llvm when building for arm64:
# https://llvm.org/bugs/show_bug.cgi?id=26081
TAP_TESTS_C+= csqrt_test
.endif
ATF_TESTS_C+= ctrig_test
TAP_TESTS_C+= exponential_test
TAP_TESTS_C+= fenv_test
TAP_TESTS_C+= fma_test
TAP_TESTS_C+= fmaxmin_test
TAP_TESTS_C+= ilogb2_test
TAP_TESTS_C+= invtrig_test
TAP_TESTS_C+= invctrig_test
TAP_TESTS_C+= logarithm_test
TAP_TESTS_C+= lrint_test
# XXX: the testcase crashes on all platforms, but only on head
# (bug 205451)
#TAP_TESTS_C+= lround_test
TAP_TESTS_C+= nan_test
TAP_TESTS_C+= nearbyint_test
TAP_TESTS_C+= next_test
TAP_TESTS_C+= rem_test
ATF_TESTS_C+= trig_test
.if !empty(PROG) && !empty(TAP_TESTS_C:M${PROG})
CFLAGS+= -O0
.endif
#COPTS+= -Wfloat-equal
IGNORE_PRAGMA=
SRCS.ilogb2_test= ilogb_test.c
LIBADD+= m
WARNS?= 1
# Copied from lib/msun/Makefile
.if ${MACHINE_CPUARCH} == "i386"
ARCH_SUBDIR= i387
.else
ARCH_SUBDIR= ${MACHINE_CPUARCH}
.endif
.include "../${ARCH_SUBDIR}/Makefile.inc"
# XXX: for some odd reason float.h doesn't tell the full story about what the
# precision is.
CFLAGS+= -DLDBL_PREC=${LDBL_PREC}
CFLAGS.fe_round_test+= -D__HAVE_FENV
.include
.include