riscv: Add a soft-float implementation of fabs()

We could just use a C implementation using __builtin_fabs(), but using
this assembly version guarantees that there is no additional prolog/epilog
code. Additionally, clang generates worse code for masking off the top bit
than GCC: https://bugs.llvm.org/show_bug.cgi?id=49377.

This fixes the RISCV64 softfloat world build after cf97d2a1da. That commit
added -fno-builtin to the msun tests which resulted in the first references to
fabs (previously the compiler inlined all calls).

Reviewed By:	dim
Reported by:	mjg
Differential Revision: https://reviews.freebsd.org/D28994
This commit is contained in:
Alex Richardson 2021-03-01 12:46:30 +00:00
parent a26ace4db6
commit 524b018d20

View File

@ -1,5 +1,6 @@
/*-
* Copyright (c) 2015-2017 Ruslan Bukin <br@bsdpad.com>
* Copyright (c) 2021 Alex Richardson <arichardson@FreeBSD.org>
* All rights reserved.
*
* Portions of this software were developed by SRI International and the
@ -10,6 +11,9 @@
* 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:
@ -35,9 +39,12 @@
#include <machine/asm.h>
__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