mirror of
git://sourceware.org/git/glibc.git
synced 2025-04-12 14:21:18 +08:00
LoongArch: Hard Float Support
This commit is contained in:
parent
3d87c89815
commit
68d61026d5
46
sysdeps/loongarch/fpu/fclrexcpt.c
Normal file
46
sysdeps/loongarch/fpu/fclrexcpt.c
Normal file
@ -0,0 +1,46 @@
|
||||
/* Clear given exceptions in current floating-point environment.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fenv_libc.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
feclearexcept (int excepts)
|
||||
{
|
||||
int cw;
|
||||
|
||||
/* Mask out unsupported bits/exceptions. */
|
||||
excepts &= FE_ALL_EXCEPT;
|
||||
|
||||
/* Read the complete control word. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
/* Clear exception flag bits and cause bits. If the cause bit is not
|
||||
cleared, the next CTC instruction (just below) will re-generate the
|
||||
exception. */
|
||||
|
||||
cw &= ~(excepts | (excepts << CAUSE_SHIFT));
|
||||
|
||||
/* Put the new data in effect. */
|
||||
_FPU_SETCW (cw);
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
||||
libm_hidden_def (feclearexcept)
|
39
sysdeps/loongarch/fpu/fedisblxcpt.c
Normal file
39
sysdeps/loongarch/fpu/fedisblxcpt.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* Disable floating-point exceptions.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fenv_libc.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
fedisableexcept (int excepts)
|
||||
{
|
||||
unsigned int new_exc, old_exc;
|
||||
|
||||
/* Get the current control word. */
|
||||
_FPU_GETCW (new_exc);
|
||||
|
||||
old_exc = (new_exc & ENABLE_MASK) << ENABLE_SHIFT;
|
||||
|
||||
excepts &= FE_ALL_EXCEPT;
|
||||
|
||||
new_exc &= ~(excepts >> ENABLE_SHIFT);
|
||||
_FPU_SETCW (new_exc);
|
||||
|
||||
return old_exc;
|
||||
}
|
39
sysdeps/loongarch/fpu/feenablxcpt.c
Normal file
39
sysdeps/loongarch/fpu/feenablxcpt.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* Enable floating-point exceptions.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fenv_libc.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
feenableexcept (int excepts)
|
||||
{
|
||||
unsigned int new_exc, old_exc;
|
||||
|
||||
/* Get the current control word. */
|
||||
_FPU_GETCW (new_exc);
|
||||
|
||||
old_exc = (new_exc & ENABLE_MASK) << ENABLE_SHIFT;
|
||||
|
||||
excepts &= FE_ALL_EXCEPT;
|
||||
|
||||
new_exc |= excepts >> ENABLE_SHIFT;
|
||||
_FPU_SETCW (new_exc);
|
||||
|
||||
return old_exc;
|
||||
}
|
31
sysdeps/loongarch/fpu/fegetenv.c
Normal file
31
sysdeps/loongarch/fpu/fegetenv.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* Store current floating-point environment.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
__fegetenv (fenv_t *envp)
|
||||
{
|
||||
_FPU_GETCW (*envp);
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
||||
libm_hidden_def (__fegetenv) weak_alias (__fegetenv, fegetenv)
|
||||
libm_hidden_weak (fegetenv)
|
32
sysdeps/loongarch/fpu/fegetexcept.c
Normal file
32
sysdeps/loongarch/fpu/fegetexcept.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* Get enabled floating-point exceptions.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fenv_libc.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
fegetexcept (void)
|
||||
{
|
||||
unsigned int exc;
|
||||
|
||||
/* Get the current control word. */
|
||||
_FPU_GETCW (exc);
|
||||
|
||||
return (exc & ENABLE_MASK) << ENABLE_SHIFT;
|
||||
}
|
27
sysdeps/loongarch/fpu/fegetmode.c
Normal file
27
sysdeps/loongarch/fpu/fegetmode.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* Store current floating-point control modes.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
fegetmode (femode_t *modep)
|
||||
{
|
||||
_FPU_GETCW (*modep);
|
||||
return 0;
|
||||
}
|
33
sysdeps/loongarch/fpu/fegetround.c
Normal file
33
sysdeps/loongarch/fpu/fegetround.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* Return current rounding direction.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
__fegetround (void)
|
||||
{
|
||||
int cw;
|
||||
|
||||
/* Get control word. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
return cw & _FPU_RC_MASK;
|
||||
}
|
||||
libm_hidden_def (__fegetround) weak_alias (__fegetround, fegetround)
|
||||
libm_hidden_weak (fegetround)
|
40
sysdeps/loongarch/fpu/feholdexcpt.c
Normal file
40
sysdeps/loongarch/fpu/feholdexcpt.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* Store current floating-point environment and clear exceptions.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
__feholdexcept (fenv_t *envp)
|
||||
{
|
||||
fpu_control_t cw;
|
||||
|
||||
/* Save the current state. */
|
||||
_FPU_GETCW (cw);
|
||||
envp->__fp_control_register = cw;
|
||||
|
||||
/* Clear all exception enable bits and flags. */
|
||||
cw &= ~(_FPU_MASK_V | _FPU_MASK_Z | _FPU_MASK_O | _FPU_MASK_U | _FPU_MASK_I
|
||||
| FE_ALL_EXCEPT);
|
||||
_FPU_SETCW (cw);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
libm_hidden_def (__feholdexcept) weak_alias (__feholdexcept, feholdexcept)
|
||||
libm_hidden_weak (feholdexcept)
|
30
sysdeps/loongarch/fpu/fenv_libc.h
Normal file
30
sysdeps/loongarch/fpu/fenv_libc.h
Normal file
@ -0,0 +1,30 @@
|
||||
/* Internal libc stuff for floating point environment routines.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _FENV_LIBC_H
|
||||
#define _FENV_LIBC_H 1
|
||||
|
||||
/* Mask for enabling exceptions and for the CAUSE bits. */
|
||||
#define ENABLE_MASK 0x0000001FU
|
||||
#define CAUSE_MASK 0x1F000000U
|
||||
|
||||
/* Shift for FE_* flags to get up to the ENABLE bits and the CAUSE bits. */
|
||||
#define ENABLE_SHIFT 16
|
||||
#define CAUSE_SHIFT 8
|
||||
|
||||
#endif /* _FENV_LIBC_H */
|
42
sysdeps/loongarch/fpu/fesetenv.c
Normal file
42
sysdeps/loongarch/fpu/fesetenv.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* Install given floating-point environment.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
__fesetenv (const fenv_t *envp)
|
||||
{
|
||||
fpu_control_t cw;
|
||||
|
||||
/* Read first current state to flush fpu pipeline. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
if (envp == FE_DFL_ENV)
|
||||
_FPU_SETCW (_FPU_DEFAULT);
|
||||
else if (envp == FE_NOMASK_ENV)
|
||||
_FPU_SETCW (_FPU_IEEE);
|
||||
else
|
||||
_FPU_SETCW (envp->__fp_control_register);
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
libm_hidden_def (__fesetenv) weak_alias (__fesetenv, fesetenv)
|
||||
libm_hidden_weak (fesetenv)
|
32
sysdeps/loongarch/fpu/fesetexcept.c
Normal file
32
sysdeps/loongarch/fpu/fesetexcept.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* Set given exception flags.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
fesetexcept (int excepts)
|
||||
{
|
||||
fpu_control_t temp;
|
||||
|
||||
_FPU_GETCW (temp);
|
||||
temp |= excepts & FE_ALL_EXCEPT;
|
||||
_FPU_SETCW (temp);
|
||||
|
||||
return 0;
|
||||
}
|
38
sysdeps/loongarch/fpu/fesetmode.c
Normal file
38
sysdeps/loongarch/fpu/fesetmode.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* Install given floating-point control modes.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
#define FCSR_STATUS 0x1f1f0000
|
||||
|
||||
int
|
||||
fesetmode (const femode_t *modep)
|
||||
{
|
||||
fpu_control_t cw;
|
||||
|
||||
_FPU_GETCW (cw);
|
||||
cw &= FCSR_STATUS;
|
||||
if (modep == FE_DFL_MODE)
|
||||
cw |= _FPU_DEFAULT;
|
||||
else
|
||||
cw |= *modep & ~FCSR_STATUS;
|
||||
_FPU_SETCW (cw);
|
||||
|
||||
return 0;
|
||||
}
|
44
sysdeps/loongarch/fpu/fesetround.c
Normal file
44
sysdeps/loongarch/fpu/fesetround.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* Set current rounding direction.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
__fesetround (int round)
|
||||
{
|
||||
fpu_control_t cw;
|
||||
|
||||
if ((round & ~_FPU_RC_MASK) != 0)
|
||||
/* ROUND is no valid rounding mode. */
|
||||
return 1;
|
||||
|
||||
/* Get current state. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
/* Set rounding bits. */
|
||||
cw &= ~_FPU_RC_MASK;
|
||||
cw |= round;
|
||||
/* Set new state. */
|
||||
_FPU_SETCW (cw);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
libm_hidden_def (__fesetround) weak_alias (__fesetround, fesetround)
|
||||
libm_hidden_weak (fesetround)
|
43
sysdeps/loongarch/fpu/feupdateenv.c
Normal file
43
sysdeps/loongarch/fpu/feupdateenv.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* Install given floating-point environment and raise exceptions.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
__feupdateenv (const fenv_t *envp)
|
||||
{
|
||||
int temp;
|
||||
|
||||
/* Save current exceptions. */
|
||||
_FPU_GETCW (temp);
|
||||
temp &= FE_ALL_EXCEPT;
|
||||
|
||||
/* Install new environment. */
|
||||
__fesetenv (envp);
|
||||
|
||||
/* Raise the safed exception. Incidently for us the implementation
|
||||
defined format of the values in objects of type fexcept_t is the
|
||||
same as the ones specified using the FE_* constants. */
|
||||
__feraiseexcept (temp);
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
||||
libm_hidden_def (__feupdateenv) weak_alias (__feupdateenv, feupdateenv)
|
||||
libm_hidden_weak (feupdateenv)
|
38
sysdeps/loongarch/fpu/fgetexcptflg.c
Normal file
38
sysdeps/loongarch/fpu/fgetexcptflg.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* Store current representation for exceptions.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
fegetexceptflag (fexcept_t *flagp, int excepts)
|
||||
{
|
||||
fpu_control_t temp;
|
||||
|
||||
/* Get the current exceptions. */
|
||||
_FPU_GETCW (temp);
|
||||
|
||||
/* We only save the relevant bits here. In particular, care has to be
|
||||
taken with the CAUSE bits, as an inadvertent restore later on could
|
||||
generate unexpected exceptions. */
|
||||
|
||||
*flagp = temp & excepts & FE_ALL_EXCEPT;
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
80
sysdeps/loongarch/fpu/fraiseexcpt.c
Normal file
80
sysdeps/loongarch/fpu/fraiseexcpt.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* Raise given exceptions.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
#include <float.h>
|
||||
|
||||
int
|
||||
__feraiseexcept (int excepts)
|
||||
{
|
||||
const float fp_zero = 0.0f;
|
||||
const float fp_one = 1.0f;
|
||||
const float fp_max = FLT_MAX;
|
||||
const float fp_min = FLT_MIN;
|
||||
const float fp_1e32 = 1.0e32f;
|
||||
const float fp_two = 2.0f;
|
||||
const float fp_three = 3.0f;
|
||||
|
||||
/* Raise exceptions represented by EXPECTS. But we must raise only
|
||||
one signal at a time. It is important that if the overflow/underflow
|
||||
exception and the inexact exception are given at the same time,
|
||||
the overflow/underflow exception follows the inexact exception. */
|
||||
|
||||
/* First: invalid exception. */
|
||||
if (FE_INVALID & excepts)
|
||||
__asm__ __volatile__("fdiv.s $f0,%0,%0\n\t"
|
||||
:
|
||||
: "f"(fp_zero)
|
||||
: "$f0");
|
||||
|
||||
/* Next: division by zero. */
|
||||
if (FE_DIVBYZERO & excepts)
|
||||
__asm__ __volatile__("fdiv.s $f0,%0,%1\n\t"
|
||||
:
|
||||
: "f"(fp_one), "f"(fp_zero)
|
||||
: "$f0");
|
||||
|
||||
/* Next: overflow. */
|
||||
if (FE_OVERFLOW & excepts)
|
||||
/* There's no way to raise overflow without also raising inexact. */
|
||||
__asm__ __volatile__("fadd.s $f0,%0,%1\n\t"
|
||||
:
|
||||
: "f"(fp_max), "f"(fp_1e32)
|
||||
: "$f0");
|
||||
|
||||
/* Next: underflow. */
|
||||
if (FE_UNDERFLOW & excepts)
|
||||
__asm__ __volatile__("fdiv.s $f0,%0,%1\n\t"
|
||||
:
|
||||
: "f"(fp_min), "f"(fp_three)
|
||||
: "$f0");
|
||||
|
||||
/* Last: inexact. */
|
||||
if (FE_INEXACT & excepts)
|
||||
__asm__ __volatile__("fdiv.s $f0, %0, %1\n\t"
|
||||
:
|
||||
: "f"(fp_two), "f"(fp_three)
|
||||
: "$f0");
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
libm_hidden_def (__feraiseexcept) weak_alias (__feraiseexcept, feraiseexcept)
|
||||
libm_hidden_weak (feraiseexcept)
|
41
sysdeps/loongarch/fpu/fsetexcptflg.c
Normal file
41
sysdeps/loongarch/fpu/fsetexcptflg.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* Set floating-point environment exception handling.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
fesetexceptflag (const fexcept_t *flagp, int excepts)
|
||||
{
|
||||
fpu_control_t temp;
|
||||
|
||||
/* Get the current exceptions. */
|
||||
_FPU_GETCW (temp);
|
||||
|
||||
/* Make sure the flags we want restored are legal. */
|
||||
excepts &= FE_ALL_EXCEPT;
|
||||
|
||||
/* Now clear the bits called for, and copy them in from flagp. Note that
|
||||
we ignore all non-flag bits from *flagp, so they don't matter. */
|
||||
temp = (temp & ~excepts) | (*flagp & excepts);
|
||||
|
||||
_FPU_SETCW (temp);
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
32
sysdeps/loongarch/fpu/ftestexcept.c
Normal file
32
sysdeps/loongarch/fpu/ftestexcept.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* Test exception in current environment.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
int
|
||||
fetestexcept (int excepts)
|
||||
{
|
||||
int cw;
|
||||
|
||||
/* Get current control word. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
return cw & excepts & FE_ALL_EXCEPT;
|
||||
}
|
||||
libm_hidden_def (fetestexcept)
|
4
sysdeps/loongarch/fpu/math-use-builtins-sqrt.h
Normal file
4
sysdeps/loongarch/fpu/math-use-builtins-sqrt.h
Normal file
@ -0,0 +1,4 @@
|
||||
#define USE_SQRT_BUILTIN 1
|
||||
#define USE_SQRTF_BUILTIN 1
|
||||
#define USE_SQRTL_BUILTIN 0
|
||||
#define USE_SQRTF128_BUILTIN 0
|
1412
sysdeps/loongarch/lp64/libm-test-ulps
Normal file
1412
sysdeps/loongarch/lp64/libm-test-ulps
Normal file
File diff suppressed because it is too large
Load Diff
1
sysdeps/loongarch/lp64/libm-test-ulps-name
Normal file
1
sysdeps/loongarch/lp64/libm-test-ulps-name
Normal file
@ -0,0 +1 @@
|
||||
LoongArch 64-bit
|
248
sysdeps/loongarch/math_private.h
Normal file
248
sysdeps/loongarch/math_private.h
Normal file
@ -0,0 +1,248 @@
|
||||
/* Internal math stuff.
|
||||
Copyright (C) 2022 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
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef LOONGARCH_MATH_PRIVATE_H
|
||||
#define LOONGARCH_MATH_PRIVATE_H 1
|
||||
|
||||
/* Inline functions to speed up the math library implementation. The
|
||||
default versions of these routines are in generic/math_private.h
|
||||
and call fesetround, feholdexcept, etc. These routines use inlined
|
||||
code instead. */
|
||||
|
||||
#ifdef __loongarch_hard_float
|
||||
|
||||
#include <fenv.h>
|
||||
#include <fenv_libc.h>
|
||||
#include <fpu_control.h>
|
||||
|
||||
#define _FPU_MASK_ALL \
|
||||
(_FPU_MASK_V | _FPU_MASK_Z | _FPU_MASK_O | _FPU_MASK_U | _FPU_MASK_I \
|
||||
| FE_ALL_EXCEPT)
|
||||
|
||||
static __always_inline void
|
||||
libc_feholdexcept_loongarch (fenv_t *envp)
|
||||
{
|
||||
fpu_control_t cw;
|
||||
|
||||
/* Save the current state. */
|
||||
_FPU_GETCW (cw);
|
||||
envp->__fp_control_register = cw;
|
||||
|
||||
/* Clear all exception enable bits and flags. */
|
||||
cw &= ~(_FPU_MASK_ALL);
|
||||
_FPU_SETCW (cw);
|
||||
}
|
||||
#define libc_feholdexcept libc_feholdexcept_loongarch
|
||||
#define libc_feholdexceptf libc_feholdexcept_loongarch
|
||||
#define libc_feholdexceptl libc_feholdexcept_loongarch
|
||||
|
||||
static __always_inline void
|
||||
libc_fesetround_loongarch (int round)
|
||||
{
|
||||
fpu_control_t cw;
|
||||
|
||||
/* Get current state. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
/* Set rounding bits. */
|
||||
cw &= ~_FPU_RC_MASK;
|
||||
cw |= round;
|
||||
|
||||
/* Set new state. */
|
||||
_FPU_SETCW (cw);
|
||||
}
|
||||
#define libc_fesetround libc_fesetround_loongarch
|
||||
#define libc_fesetroundf libc_fesetround_loongarch
|
||||
#define libc_fesetroundl libc_fesetround_loongarch
|
||||
|
||||
static __always_inline void
|
||||
libc_feholdexcept_setround_loongarch (fenv_t *envp, int round)
|
||||
{
|
||||
fpu_control_t cw;
|
||||
|
||||
/* Save the current state. */
|
||||
_FPU_GETCW (cw);
|
||||
envp->__fp_control_register = cw;
|
||||
|
||||
/* Clear all exception enable bits and flags. */
|
||||
cw &= ~(_FPU_MASK_ALL);
|
||||
|
||||
/* Set rounding bits. */
|
||||
cw &= ~_FPU_RC_MASK;
|
||||
cw |= round;
|
||||
|
||||
/* Set new state. */
|
||||
_FPU_SETCW (cw);
|
||||
}
|
||||
#define libc_feholdexcept_setround libc_feholdexcept_setround_loongarch
|
||||
#define libc_feholdexcept_setroundf libc_feholdexcept_setround_loongarch
|
||||
#define libc_feholdexcept_setroundl libc_feholdexcept_setround_loongarch
|
||||
|
||||
#define libc_feholdsetround libc_feholdexcept_setround_loongarch
|
||||
#define libc_feholdsetroundf libc_feholdexcept_setround_loongarch
|
||||
#define libc_feholdsetroundl libc_feholdexcept_setround_loongarch
|
||||
|
||||
static __always_inline void
|
||||
libc_fesetenv_loongarch (fenv_t *envp)
|
||||
{
|
||||
fpu_control_t cw __attribute__ ((unused));
|
||||
|
||||
/* Read current state to flush fpu pipeline. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
_FPU_SETCW (envp->__fp_control_register);
|
||||
}
|
||||
#define libc_fesetenv libc_fesetenv_loongarch
|
||||
#define libc_fesetenvf libc_fesetenv_loongarch
|
||||
#define libc_fesetenvl libc_fesetenv_loongarch
|
||||
|
||||
static __always_inline int
|
||||
libc_feupdateenv_test_loongarch (fenv_t *envp, int excepts)
|
||||
{
|
||||
/* int ret = fetestexcept (excepts); feupdateenv (envp); return ret; */
|
||||
int cw, temp;
|
||||
|
||||
/* Get current control word. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
/* Set flag bits (which are accumulative), and *also* set the
|
||||
cause bits. The setting of the cause bits is what actually causes
|
||||
the hardware to generate the exception, if the corresponding enable
|
||||
bit is set as well. */
|
||||
temp = cw & FE_ALL_EXCEPT;
|
||||
temp |= envp->__fp_control_register | (temp << CAUSE_SHIFT);
|
||||
|
||||
/* Set new state. */
|
||||
_FPU_SETCW (temp);
|
||||
|
||||
return cw & excepts & FE_ALL_EXCEPT;
|
||||
}
|
||||
#define libc_feupdateenv_test libc_feupdateenv_test_loongarch
|
||||
#define libc_feupdateenv_testf libc_feupdateenv_test_loongarch
|
||||
#define libc_feupdateenv_testl libc_feupdateenv_test_loongarch
|
||||
|
||||
static __always_inline void
|
||||
libc_feupdateenv_loongarch (fenv_t *envp)
|
||||
{
|
||||
libc_feupdateenv_test_loongarch (envp, 0);
|
||||
}
|
||||
#define libc_feupdateenv libc_feupdateenv_loongarch
|
||||
#define libc_feupdateenvf libc_feupdateenv_loongarch
|
||||
#define libc_feupdateenvl libc_feupdateenv_loongarch
|
||||
|
||||
#define libc_feresetround libc_feupdateenv_loongarch
|
||||
#define libc_feresetroundf libc_feupdateenv_loongarch
|
||||
#define libc_feresetroundl libc_feupdateenv_loongarch
|
||||
|
||||
static __always_inline int
|
||||
libc_fetestexcept_loongarch (int excepts)
|
||||
{
|
||||
int cw;
|
||||
|
||||
/* Get current control word. */
|
||||
_FPU_GETCW (cw);
|
||||
|
||||
return cw & excepts & FE_ALL_EXCEPT;
|
||||
}
|
||||
#define libc_fetestexcept libc_fetestexcept_loongarch
|
||||
#define libc_fetestexceptf libc_fetestexcept_loongarch
|
||||
#define libc_fetestexceptl libc_fetestexcept_loongarch
|
||||
|
||||
/* Enable support for rounding mode context. */
|
||||
#define HAVE_RM_CTX 1
|
||||
|
||||
static __always_inline void
|
||||
libc_feholdexcept_setround_loongarch_ctx (struct rm_ctx *ctx, int round)
|
||||
{
|
||||
fpu_control_t old, new;
|
||||
|
||||
/* Save the current state. */
|
||||
_FPU_GETCW (old);
|
||||
ctx->env.__fp_control_register = old;
|
||||
|
||||
/* Clear all exception enable bits and flags. */
|
||||
new = old & ~(_FPU_MASK_ALL);
|
||||
|
||||
/* Set rounding bits. */
|
||||
new = (new & ~_FPU_RC_MASK) | round;
|
||||
|
||||
if (__glibc_unlikely (new != old))
|
||||
{
|
||||
_FPU_SETCW (new);
|
||||
ctx->updated_status = true;
|
||||
}
|
||||
else
|
||||
ctx->updated_status = false;
|
||||
}
|
||||
#define libc_feholdexcept_setround_ctx libc_feholdexcept_setround_loongarch_ctx
|
||||
#define libc_feholdexcept_setroundf_ctx \
|
||||
libc_feholdexcept_setround_loongarch_ctx
|
||||
#define libc_feholdexcept_setroundl_ctx \
|
||||
libc_feholdexcept_setround_loongarch_ctx
|
||||
|
||||
static __always_inline void
|
||||
libc_fesetenv_loongarch_ctx (struct rm_ctx *ctx)
|
||||
{
|
||||
libc_fesetenv_loongarch (&ctx->env);
|
||||
}
|
||||
#define libc_fesetenv_ctx libc_fesetenv_loongarch_ctx
|
||||
#define libc_fesetenvf_ctx libc_fesetenv_loongarch_ctx
|
||||
#define libc_fesetenvl_ctx libc_fesetenv_loongarch_ctx
|
||||
|
||||
static __always_inline void
|
||||
libc_feupdateenv_loongarch_ctx (struct rm_ctx *ctx)
|
||||
{
|
||||
if (__glibc_unlikely (ctx->updated_status))
|
||||
libc_feupdateenv_test_loongarch (&ctx->env, 0);
|
||||
}
|
||||
#define libc_feupdateenv_ctx libc_feupdateenv_loongarch_ctx
|
||||
#define libc_feupdateenvf_ctx libc_feupdateenv_loongarch_ctx
|
||||
#define libc_feupdateenvl_ctx libc_feupdateenv_loongarch_ctx
|
||||
#define libc_feresetround_ctx libc_feupdateenv_loongarch_ctx
|
||||
#define libc_feresetroundf_ctx libc_feupdateenv_loongarch_ctx
|
||||
#define libc_feresetroundl_ctx libc_feupdateenv_loongarch_ctx
|
||||
|
||||
static __always_inline void
|
||||
libc_feholdsetround_loongarch_ctx (struct rm_ctx *ctx, int round)
|
||||
{
|
||||
fpu_control_t old, new;
|
||||
|
||||
/* Save the current state. */
|
||||
_FPU_GETCW (old);
|
||||
ctx->env.__fp_control_register = old;
|
||||
|
||||
/* Set rounding bits. */
|
||||
new = (old & ~_FPU_RC_MASK) | round;
|
||||
|
||||
if (__glibc_unlikely (new != old))
|
||||
{
|
||||
_FPU_SETCW (new);
|
||||
ctx->updated_status = true;
|
||||
}
|
||||
else
|
||||
ctx->updated_status = false;
|
||||
}
|
||||
#define libc_feholdsetround_ctx libc_feholdsetround_loongarch_ctx
|
||||
#define libc_feholdsetroundf_ctx libc_feholdsetround_loongarch_ctx
|
||||
#define libc_feholdsetroundl_ctx libc_feholdsetround_loongarch_ctx
|
||||
|
||||
#endif
|
||||
|
||||
#include_next <math_private.h>
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user