xref: /freebsd-src/lib/libc/riscv/gen/fabs.S (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
10bfee928SRuslan Bukin/*-
2af19cc59SRuslan Bukin * Copyright (c) 2015-2017 Ruslan Bukin <br@bsdpad.com>
3*524b018dSAlex Richardson * Copyright (c) 2021 Alex Richardson <arichardson@FreeBSD.org>
40bfee928SRuslan Bukin * All rights reserved.
50bfee928SRuslan Bukin *
60bfee928SRuslan Bukin * Portions of this software were developed by SRI International and the
70bfee928SRuslan Bukin * University of Cambridge Computer Laboratory under DARPA/AFRL contract
80bfee928SRuslan Bukin * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
90bfee928SRuslan Bukin *
100bfee928SRuslan Bukin * Portions of this software were developed by the University of Cambridge
110bfee928SRuslan Bukin * Computer Laboratory as part of the CTSRD Project, with support from the
120bfee928SRuslan Bukin * UK Higher Education Innovation Fund (HEIF).
130bfee928SRuslan Bukin *
14*524b018dSAlex Richardson * This work was supported by Innovate UK project 105694, "Digital Security
15*524b018dSAlex Richardson * by Design (DSbD) Technology Platform Prototype".
16*524b018dSAlex Richardson *
170bfee928SRuslan Bukin * Redistribution and use in source and binary forms, with or without
180bfee928SRuslan Bukin * modification, are permitted provided that the following conditions
190bfee928SRuslan Bukin * are met:
200bfee928SRuslan Bukin * 1. Redistributions of source code must retain the above copyright
210bfee928SRuslan Bukin *    notice, this list of conditions and the following disclaimer.
220bfee928SRuslan Bukin * 2. Redistributions in binary form must reproduce the above copyright
230bfee928SRuslan Bukin *    notice, this list of conditions and the following disclaimer in the
240bfee928SRuslan Bukin *    documentation and/or other materials provided with the distribution.
250bfee928SRuslan Bukin *
260bfee928SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
270bfee928SRuslan Bukin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
280bfee928SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
290bfee928SRuslan Bukin * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
300bfee928SRuslan Bukin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
310bfee928SRuslan Bukin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
320bfee928SRuslan Bukin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
330bfee928SRuslan Bukin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
340bfee928SRuslan Bukin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
350bfee928SRuslan Bukin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
360bfee928SRuslan Bukin * SUCH DAMAGE.
370bfee928SRuslan Bukin */
380bfee928SRuslan Bukin
390bfee928SRuslan Bukin#include <machine/asm.h>
400bfee928SRuslan BukinENTRY(fabs)
41*524b018dSAlex Richardson#ifdef __riscv_float_abi_double
420bfee928SRuslan Bukin	fabs.d	fa0, fa0
43*524b018dSAlex Richardson#else
44*524b018dSAlex Richardson	slli	a0, a0, 1
45*524b018dSAlex Richardson	srli	a0, a0, 1
46*524b018dSAlex Richardson#endif
470bfee928SRuslan Bukin	ret
480bfee928SRuslan BukinEND(fabs)
49