2018-01-29 17:27:10 +00:00
|
|
|
/* Private floating point rounding and exceptions handling. RISC-V version.
|
2022-01-01 18:54:23 +00:00
|
|
|
Copyright (C) 2014-2022 Free Software Foundation, Inc.
|
2018-01-29 17:27:10 +00:00
|
|
|
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
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2018-01-29 17:27:10 +00:00
|
|
|
|
2018-08-28 20:48:49 +00:00
|
|
|
#ifndef RISCV_FENV_PRIVATE_H
|
|
|
|
#define RISCV_FENV_PRIVATE_H 1
|
2018-01-29 17:27:10 +00:00
|
|
|
|
|
|
|
#include <fenv.h>
|
|
|
|
#include <fpu_control.h>
|
|
|
|
#include <get-rounding-mode.h>
|
|
|
|
|
|
|
|
static __always_inline int
|
|
|
|
riscv_getround (void)
|
|
|
|
{
|
|
|
|
return get_rounding_mode ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
riscv_setround (int rm)
|
|
|
|
{
|
|
|
|
asm volatile ("fsrm %z0" : : "rJ" (rm));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline int
|
|
|
|
riscv_getflags (void)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
asm volatile ("frflags %0" : "=r" (flags));
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
riscv_setflags (int flags)
|
|
|
|
{
|
|
|
|
asm volatile ("fsflags %z0" : : "rJ" (flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
libc_feholdexcept_riscv (fenv_t *envp)
|
|
|
|
{
|
|
|
|
asm volatile ("csrrc %0, fcsr, %1" : "=r" (*envp) : "i" (FE_ALL_EXCEPT));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_feholdexcept libc_feholdexcept_riscv
|
|
|
|
#define libc_feholdexceptf libc_feholdexcept_riscv
|
|
|
|
#define libc_feholdexceptl libc_feholdexcept_riscv
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
libc_fesetround_riscv (int round)
|
|
|
|
{
|
|
|
|
riscv_setround (round);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_fesetround libc_fesetround_riscv
|
|
|
|
#define libc_fesetroundf libc_fesetround_riscv
|
|
|
|
#define libc_fesetroundl libc_fesetround_riscv
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
libc_feholdexcept_setround_riscv (fenv_t *envp, int round)
|
|
|
|
{
|
|
|
|
libc_feholdexcept_riscv (envp);
|
2018-08-03 17:43:31 +00:00
|
|
|
libc_fesetround_riscv (round);
|
2018-01-29 17:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_feholdexcept_setround libc_feholdexcept_setround_riscv
|
|
|
|
#define libc_feholdexcept_setroundf libc_feholdexcept_setround_riscv
|
|
|
|
#define libc_feholdexcept_setroundl libc_feholdexcept_setround_riscv
|
|
|
|
|
|
|
|
static __always_inline int
|
|
|
|
libc_fetestexcept_riscv (int ex)
|
|
|
|
{
|
|
|
|
return riscv_getflags () & ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_fetestexcept libc_fetestexcept_riscv
|
|
|
|
#define libc_fetestexceptf libc_fetestexcept_riscv
|
|
|
|
#define libc_fetestexceptl libc_fetestexcept_riscv
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
libc_fesetenv_riscv (const fenv_t *envp)
|
|
|
|
{
|
|
|
|
long int env = (long int) envp - (long int) FE_DFL_ENV;
|
|
|
|
if (env != 0)
|
|
|
|
env = *envp;
|
|
|
|
|
|
|
|
_FPU_SETCW (env);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_fesetenv libc_fesetenv_riscv
|
|
|
|
#define libc_fesetenvf libc_fesetenv_riscv
|
|
|
|
#define libc_fesetenvl libc_fesetenv_riscv
|
|
|
|
#define libc_feresetround_noex libc_fesetenv_riscv
|
|
|
|
#define libc_feresetround_noexf libc_fesetenv_riscv
|
|
|
|
#define libc_feresetround_noexl libc_fesetenv_riscv
|
|
|
|
|
|
|
|
static __always_inline int
|
|
|
|
libc_feupdateenv_test_riscv (const fenv_t *envp, int ex)
|
|
|
|
{
|
|
|
|
fenv_t env = *envp;
|
|
|
|
int flags = riscv_getflags ();
|
|
|
|
asm volatile ("csrw fcsr, %z0" : : "rJ" (env | flags));
|
|
|
|
return flags & ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_feupdateenv_test libc_feupdateenv_test_riscv
|
|
|
|
#define libc_feupdateenv_testf libc_feupdateenv_test_riscv
|
|
|
|
#define libc_feupdateenv_testl libc_feupdateenv_test_riscv
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
libc_feupdateenv_riscv (const fenv_t *envp)
|
|
|
|
{
|
|
|
|
_FPU_SETCW (*envp | riscv_getflags ());
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_feupdateenv libc_feupdateenv_riscv
|
|
|
|
#define libc_feupdateenvf libc_feupdateenv_riscv
|
|
|
|
#define libc_feupdateenvl libc_feupdateenv_riscv
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
libc_feholdsetround_riscv (fenv_t *envp, int round)
|
|
|
|
{
|
|
|
|
/* Note this implementation makes an improperly-formatted fenv_t and
|
|
|
|
so should only be used in conjunction with libc_feresetround. */
|
|
|
|
int old_round;
|
|
|
|
asm volatile ("csrrw %0, frm, %z1" : "=r" (old_round) : "rJ" (round));
|
|
|
|
*envp = old_round;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_feholdsetround libc_feholdsetround_riscv
|
|
|
|
#define libc_feholdsetroundf libc_feholdsetround_riscv
|
|
|
|
#define libc_feholdsetroundl libc_feholdsetround_riscv
|
|
|
|
|
|
|
|
static __always_inline void
|
|
|
|
libc_feresetround_riscv (fenv_t *envp)
|
|
|
|
{
|
|
|
|
/* Note this implementation takes an improperly-formatted fenv_t and
|
|
|
|
so should only be used in conjunction with libc_feholdsetround. */
|
|
|
|
riscv_setround (*envp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define libc_feresetround libc_feresetround_riscv
|
|
|
|
#define libc_feresetroundf libc_feresetround_riscv
|
|
|
|
#define libc_feresetroundl libc_feresetround_riscv
|
|
|
|
|
2018-08-28 20:48:49 +00:00
|
|
|
#include_next <fenv_private.h>
|
2018-01-29 17:27:10 +00:00
|
|
|
|
|
|
|
#endif
|