From b2cb5e0298e08b486190610a9e82356ccb6f564b Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Mon, 29 Jan 2018 09:27:10 -0800 Subject: RISC-V: Hard Float Support This patch contains hardware floating-point support for the RISC-V ISA. While we currently only support hard-float systems with both the F and D extensions, I've left the F-specific code split out into seperate folders in order to ease adding support for F-only and RV32I-based systems in the future. I gave this a quick once-over and believe I've removed all the code that implements RV32IF, RV32IFD, and RV64IF targets. 2018-01-29 Palmer Dabbelt * sysdeps/riscv/rv64/rvd/s_ceil.c: New file. * sysdeps/riscv/rv64/rvd/s_floor.c: Likewise. * sysdeps/riscv/rv64/rvd/s_llrint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_llround.c: Likewise. * sysdeps/riscv/rv64/rvd/s_lrint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_lround.c: Likewise. * sysdeps/riscv/rv64/rvd/s_nearbyint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_rint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_round.c: Likewise. * sysdeps/riscv/rv64/rvd/s_roundeven.c: Likewise. * sysdeps/riscv/rv64/rvd/s_trunc.c: Likewise. * sysdeps/riscv/rv64/rvf/s_llrintf.c: Likewise. * sysdeps/riscv/rv64/rvf/s_llroundf.c: Likewise. * sysdeps/riscv/rv64/rvf/s_lrintf.c: Likewise. * sysdeps/riscv/rv64/rvf/s_lroundf.c: Likewise. * sysdeps/riscv/rvd/e_sqrt.c: Likewise. * sysdeps/riscv/rvd/s_copysign.c: Likewise. * sysdeps/riscv/rvd/s_finite.c: Likewise. * sysdeps/riscv/rvd/s_fma.c: Likewise. * sysdeps/riscv/rvd/s_fmax.c: Likewise. * sysdeps/riscv/rvd/s_fmin.c: Likewise. * sysdeps/riscv/rvd/s_fpclassify.c: Likewise. * sysdeps/riscv/rvd/s_isinf.c: Likewise. * sysdeps/riscv/rvd/s_isnan.c: Likewise. * sysdeps/riscv/rvd/s_issignaling.c: Likewise. * sysdeps/riscv/rvf/e_sqrtf.c: Likewise. * sysdeps/riscv/rvf/fclrexcpt.c: Likewise. * sysdeps/riscv/rvf/fegetenv.c: Likewise. * sysdeps/riscv/rvf/fegetmode.c: Likewise. * sysdeps/riscv/rvf/fegetround.c: Likewise. * sysdeps/riscv/rvf/feholdexcpt.c: Likewise. * sysdeps/riscv/rvf/fesetenv.c: Likewise. * sysdeps/riscv/rvf/fesetexcept.c: Likewise. * sysdeps/riscv/rvf/fesetmode.c: Likewise. * sysdeps/riscv/rvf/fesetround.c: Likewise. * sysdeps/riscv/rvf/feupdateenv.c: Likewise. * sysdeps/riscv/rvf/fgetexcptflg.c: Likewise. * sysdeps/riscv/rvf/fraiseexcpt.c: Likewise. * sysdeps/riscv/rvf/fsetexcptflg.c: Likewise. * sysdeps/riscv/rvf/ftestexcept.c: Likewise. * sysdeps/riscv/rvf/get-rounding-mode.h: Likewise. * sysdeps/riscv/rvf/math_private.h: Likewise. * sysdeps/riscv/rvf/s_ceilf.c: Likewise. * sysdeps/riscv/rvf/s_copysignf.c: Likewise. * sysdeps/riscv/rvf/s_finitef.c: Likewise. * sysdeps/riscv/rvf/s_floorf.c: Likewise. * sysdeps/riscv/rvf/s_fmaf.c: Likewise. * sysdeps/riscv/rvf/s_fmaxf.c: Likewise. * sysdeps/riscv/rvf/s_fminf.c: Likewise. * sysdeps/riscv/rvf/s_fpclassifyf.c: Likewise. * sysdeps/riscv/rvf/s_isinff.c: Likewise. * sysdeps/riscv/rvf/s_isnanf.c: Likewise. * sysdeps/riscv/rvf/s_issignalingf.c: Likewise. * sysdeps/riscv/rvf/s_nearbyintf.c: Likewise. * sysdeps/riscv/rvf/s_rintf.c: Likewise. * sysdeps/riscv/rvf/s_roundevenf.c: Likewise. * sysdeps/riscv/rvf/s_roundf.c: Likewise. * sysdeps/riscv/rvf/s_truncf.c: Likewise. --- sysdeps/riscv/rvd/e_sqrt.c | 27 +++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_copysign.c | 28 ++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_finite.c | 28 ++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_fma.c | 30 ++++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_fmax.c | 28 ++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_fmin.c | 28 ++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_fpclassify.c | 36 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_isinf.c | 29 +++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_isnan.c | 28 ++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_issignaling.c | 27 +++++++++++++++++++++++++++ 10 files changed, 289 insertions(+) create mode 100644 sysdeps/riscv/rvd/e_sqrt.c create mode 100644 sysdeps/riscv/rvd/s_copysign.c create mode 100644 sysdeps/riscv/rvd/s_finite.c create mode 100644 sysdeps/riscv/rvd/s_fma.c create mode 100644 sysdeps/riscv/rvd/s_fmax.c create mode 100644 sysdeps/riscv/rvd/s_fmin.c create mode 100644 sysdeps/riscv/rvd/s_fpclassify.c create mode 100644 sysdeps/riscv/rvd/s_isinf.c create mode 100644 sysdeps/riscv/rvd/s_isnan.c create mode 100644 sysdeps/riscv/rvd/s_issignaling.c (limited to 'sysdeps/riscv/rvd') diff --git a/sysdeps/riscv/rvd/e_sqrt.c b/sysdeps/riscv/rvd/e_sqrt.c new file mode 100644 index 0000000..66627ee --- /dev/null +++ b/sysdeps/riscv/rvd/e_sqrt.c @@ -0,0 +1,27 @@ +/* Double precision floating point square root. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include + +double +__ieee754_sqrt (double x) +{ + asm ("fsqrt.d %0, %1" : "=f" (x) : "f" (x)); + return x; +} +strong_alias (__ieee754_sqrt, __sqrt_finite) diff --git a/sysdeps/riscv/rvd/s_copysign.c b/sysdeps/riscv/rvd/s_copysign.c new file mode 100644 index 0000000..36fef55 --- /dev/null +++ b/sysdeps/riscv/rvd/s_copysign.c @@ -0,0 +1,28 @@ +/* Copy sign bit between floating-point values. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +double +__copysign (double x, double y) +{ + asm ("fsgnj.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__copysign, copysign) diff --git a/sysdeps/riscv/rvd/s_finite.c b/sysdeps/riscv/rvd/s_finite.c new file mode 100644 index 0000000..402ae3f --- /dev/null +++ b/sysdeps/riscv/rvd/s_finite.c @@ -0,0 +1,28 @@ +/* finite(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__finite (double x) +{ + return _FCLASS (x) & ~(_FCLASS_INF | _FCLASS_NAN); +} +hidden_def (__finite) +weak_alias (__finite, finite) diff --git a/sysdeps/riscv/rvd/s_fma.c b/sysdeps/riscv/rvd/s_fma.c new file mode 100644 index 0000000..1655579 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fma.c @@ -0,0 +1,30 @@ +/* Double precision floating point fused multiply-add. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +double +__fma (double x, double y, double z) +{ + asm ("fmadd.d %0, %1, %2, %3" : "=f" (x) : "f" (x), "f" (y), "f" (z)); + return x; +} +libm_alias_double (__fma, fma) diff --git a/sysdeps/riscv/rvd/s_fmax.c b/sysdeps/riscv/rvd/s_fmax.c new file mode 100644 index 0000000..ef8f134 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmax.c @@ -0,0 +1,28 @@ +/* fmax(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +double +__fmax (double x, double y) +{ + asm ("fmax.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fmax, fmax) diff --git a/sysdeps/riscv/rvd/s_fmin.c b/sysdeps/riscv/rvd/s_fmin.c new file mode 100644 index 0000000..c6ff24c --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmin.c @@ -0,0 +1,28 @@ +/* fmin(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +double +__fmin (double x, double y) +{ + asm ("fmin.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fmin, fmin) diff --git a/sysdeps/riscv/rvd/s_fpclassify.c b/sysdeps/riscv/rvd/s_fpclassify.c new file mode 100644 index 0000000..fe693c2 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fpclassify.c @@ -0,0 +1,36 @@ +/* fpclassify(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__fpclassify (double x) +{ + int cls = _FCLASS (x); + if (__builtin_expect (cls & _FCLASS_NORM, _FCLASS_NORM)) + return FP_NORMAL; + if (__builtin_expect (cls & _FCLASS_ZERO, _FCLASS_ZERO)) + return FP_ZERO; + if (__builtin_expect (cls & _FCLASS_SUBNORM, _FCLASS_SUBNORM)) + return FP_SUBNORMAL; + if (__builtin_expect (cls & _FCLASS_INF, _FCLASS_INF)) + return FP_INFINITE; + return FP_NAN; +} +libm_hidden_def (__fpclassify) diff --git a/sysdeps/riscv/rvd/s_isinf.c b/sysdeps/riscv/rvd/s_isinf.c new file mode 100644 index 0000000..1b9767a --- /dev/null +++ b/sysdeps/riscv/rvd/s_isinf.c @@ -0,0 +1,29 @@ +/* isinf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__isinf (double x) +{ + int cls = _FCLASS (x); + return -((cls & _FCLASS_MINF) ? 1 : 0) | ((cls & _FCLASS_PINF) ? 1 : 0); +} +hidden_def (__isinf) +weak_alias (__isinf, isinf) diff --git a/sysdeps/riscv/rvd/s_isnan.c b/sysdeps/riscv/rvd/s_isnan.c new file mode 100644 index 0000000..3739de7 --- /dev/null +++ b/sysdeps/riscv/rvd/s_isnan.c @@ -0,0 +1,28 @@ +/* isnan(). RISC_V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__isnan (double x) +{ + return (_FCLASS (x) & _FCLASS_NAN) != 0; +} +hidden_def (__isnan) +weak_alias (__isnan, isnan) diff --git a/sysdeps/riscv/rvd/s_issignaling.c b/sysdeps/riscv/rvd/s_issignaling.c new file mode 100644 index 0000000..1b65206 --- /dev/null +++ b/sysdeps/riscv/rvd/s_issignaling.c @@ -0,0 +1,27 @@ +/* issignaling(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__issignaling (double x) +{ + return (_FCLASS (x) & _FCLASS_SNAN) != 0; +} +libm_hidden_def (__issignaling) -- cgit v1.1