]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/riscv/sfp-machine.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / riscv / sfp-machine.h
CommitLineData
67236aeb 1/* RISC-V softfloat definitions
d614a753 2 Copyright (C) 2017-2020 Free Software Foundation, Inc.
67236aeb
PD
3
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
67236aeb
PD
19
20#include <fenv.h>
21#include <fpu_control.h>
22
23#if __riscv_xlen == 32
24
25# error "rv32i-based targets are not supported"
26
27#else
28
29# define _FP_W_TYPE_SIZE 64
30# define _FP_W_TYPE unsigned long long
31# define _FP_WS_TYPE signed long long
32# define _FP_I_TYPE long long
33
34# define _FP_MUL_MEAT_S(R, X, Y) \
35 _FP_MUL_MEAT_1_imm (_FP_WFRACBITS_S, R, X, Y)
36# define _FP_MUL_MEAT_D(R, X, Y) \
37 _FP_MUL_MEAT_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
38# define _FP_MUL_MEAT_Q(R, X, Y) \
39 _FP_MUL_MEAT_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
40
41# define _FP_MUL_MEAT_DW_S(R, X, Y) \
42 _FP_MUL_MEAT_DW_1_imm (_FP_WFRACBITS_S, R, X, Y)
43# define _FP_MUL_MEAT_DW_D(R, X, Y) \
44 _FP_MUL_MEAT_DW_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
45# define _FP_MUL_MEAT_DW_Q(R, X, Y) \
46 _FP_MUL_MEAT_DW_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
47
48# define _FP_DIV_MEAT_S(R, X, Y) _FP_DIV_MEAT_1_imm (S, R, X, Y, _FP_DIV_HELP_imm)
49# define _FP_DIV_MEAT_D(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (D, R, X, Y)
50# define _FP_DIV_MEAT_Q(R, X, Y) _FP_DIV_MEAT_2_udiv (Q, R, X, Y)
51
52# define _FP_NANFRAC_S _FP_QNANBIT_S
53# define _FP_NANFRAC_D _FP_QNANBIT_D
54# define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0
55
56#endif
57
58#define _FP_NANSIGN_S 0
59#define _FP_NANSIGN_D 0
60#define _FP_NANSIGN_Q 0
61
62#define _FP_KEEPNANFRACP 0
63#define _FP_QNANNEGATEDP 0
64
65#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
66 do { \
67 R##_s = _FP_NANSIGN_##fs; \
68 _FP_FRAC_SET_##wc (R, _FP_NANFRAC_##fs); \
69 R##_c = FP_CLS_NAN; \
70 } while (0)
71
72#define _FP_DECL_EX int _frm __attribute__ ((unused));
73#define FP_ROUNDMODE _frm
74
75#define FP_RND_NEAREST FE_TONEAREST
76#define FP_RND_ZERO FE_TOWARDZERO
77#define FP_RND_PINF FE_UPWARD
78#define FP_RND_MINF FE_DOWNWARD
79
80#define FP_EX_INVALID FE_INVALID
81#define FP_EX_OVERFLOW FE_OVERFLOW
82#define FP_EX_UNDERFLOW FE_UNDERFLOW
83#define FP_EX_DIVZERO FE_DIVBYZERO
84#define FP_EX_INEXACT FE_INEXACT
85
86#define _FP_TININESS_AFTER_ROUNDING 1
87
88#ifdef __riscv_flen
89# define FP_INIT_ROUNDMODE \
90do { \
91 __asm__ volatile ("frrm %0" : "=r" (_frm)); \
92} while (0)
93
94# define FP_HANDLE_EXCEPTIONS \
95do { \
96 if (__builtin_expect (_fex, 0)) \
97 __asm__ volatile ("csrs fflags, %0" : : "rK" (_fex)); \
98} while (0)
99#else
100# define FP_INIT_ROUNDMODE _frm = FP_RND_NEAREST
101#endif