summaryrefslogtreecommitdiff
path: root/ports/sysdeps/am33/fpu
diff options
context:
space:
mode:
Diffstat (limited to 'ports/sysdeps/am33/fpu')
-rw-r--r--ports/sysdeps/am33/fpu/bits/fenv.h66
-rw-r--r--ports/sysdeps/am33/fpu/fclrexcpt.c51
-rw-r--r--ports/sysdeps/am33/fpu/fedisblxcpt.c41
-rw-r--r--ports/sysdeps/am33/fpu/feenablxcpt.c41
-rw-r--r--ports/sysdeps/am33/fpu/fegetenv.c34
-rw-r--r--ports/sysdeps/am33/fpu/fegetexcept.c34
-rw-r--r--ports/sysdeps/am33/fpu/fegetround.c34
-rw-r--r--ports/sysdeps/am33/fpu/feholdexcpt.c38
-rw-r--r--ports/sysdeps/am33/fpu/fenv_libc.h32
-rw-r--r--ports/sysdeps/am33/fpu/fesetenv.c59
-rw-r--r--ports/sysdeps/am33/fpu/fesetround.c28
-rw-r--r--ports/sysdeps/am33/fpu/feupdateenv.c46
-rw-r--r--ports/sysdeps/am33/fpu/fgetexcptflg.c43
-rw-r--r--ports/sysdeps/am33/fpu/fpu_control.h74
-rw-r--r--ports/sysdeps/am33/fpu/fraiseexcpt.c78
-rw-r--r--ports/sysdeps/am33/fpu/fsetexcptflg.c56
-rw-r--r--ports/sysdeps/am33/fpu/ftestexcept.c33
17 files changed, 788 insertions, 0 deletions
diff --git a/ports/sysdeps/am33/fpu/bits/fenv.h b/ports/sysdeps/am33/fpu/bits/fenv.h
new file mode 100644
index 0000000000..d3a89982bf
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/bits/fenv.h
@@ -0,0 +1,66 @@
+/* Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on the corresponding file in the mips port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _FENV_H
+# error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
+#endif
+
+
+/* Define bits representing the exception. We use the EF bit
+ positions of the appropriate bits in the FPCR register. */
+enum
+ {
+ FE_INEXACT = 0x01,
+#define FE_INEXACT FE_INEXACT
+ FE_UNDERFLOW = 0x02,
+#define FE_UNDERFLOW FE_UNDERFLOW
+ FE_OVERFLOW = 0x04,
+#define FE_OVERFLOW FE_OVERFLOW
+ FE_DIVBYZERO = 0x08,
+#define FE_DIVBYZERO FE_DIVBYZERO
+ FE_INVALID = 0x10,
+#define FE_INVALID FE_INVALID
+ };
+
+#define FE_ALL_EXCEPT \
+ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
+
+/* The AM33/2.0 FPU supports only Round to nearest. Bits 3<<16 are
+ reserved to represent other rounding modes. */
+enum
+ {
+ FE_TONEAREST = 0x00000,
+#define FE_TONEAREST FE_TONEAREST
+ };
+
+
+/* Type representing exception flags. */
+typedef unsigned int fexcept_t;
+
+
+/* Type representing floating-point environment. */
+typedef unsigned int fenv_t;
+
+/* If the default argument is used we use this value. */
+#define FE_DFL_ENV ((__const fenv_t *) -1)
+
+#ifdef __USE_GNU
+/* Floating-point environment where none of the exception is masked. */
+# define FE_NOMASK_ENV ((__const fenv_t *) -2)
+#endif
diff --git a/ports/sysdeps/am33/fpu/fclrexcpt.c b/ports/sysdeps/am33/fpu/fclrexcpt.c
new file mode 100644
index 0000000000..2b15f45a63
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fclrexcpt.c
@@ -0,0 +1,51 @@
+/* Clear given exceptions in current floating-point environment.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+#include <shlib-compat.h>
+
+int
+__feclearexcept (int excepts)
+{
+ fpu_control_t 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. EF bits are cleared by
+ assigning 1 to them (and there's no way to set them); other bits
+ are copied normally. */
+
+ cw &= ~((excepts << CAUSE_SHIFT) | FE_ALL_EXCEPT);
+ cw |= excepts;
+
+ /* Put the new data in effect. */
+ _FPU_SETFCW (cw);
+
+ /* Success. */
+ return 0;
+}
+
+versioned_symbol (libm, __feclearexcept, feclearexcept, GLIBC_2_2);
diff --git a/ports/sysdeps/am33/fpu/fedisblxcpt.c b/ports/sysdeps/am33/fpu/fedisblxcpt.c
new file mode 100644
index 0000000000..170f8200ed
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fedisblxcpt.c
@@ -0,0 +1,41 @@
+/* Disable floating-point exceptions.
+ Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+
+int
+fedisableexcept (int excepts)
+{
+ fpu_control_t 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;
+}
diff --git a/ports/sysdeps/am33/fpu/feenablxcpt.c b/ports/sysdeps/am33/fpu/feenablxcpt.c
new file mode 100644
index 0000000000..fe6d880c21
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/feenablxcpt.c
@@ -0,0 +1,41 @@
+/* Enable floating-point exceptions.
+ Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+
+int
+feenableexcept (int excepts)
+{
+ fpu_control_t 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;
+}
diff --git a/ports/sysdeps/am33/fpu/fegetenv.c b/ports/sysdeps/am33/fpu/fegetenv.c
new file mode 100644
index 0000000000..6da6eeb913
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fegetenv.c
@@ -0,0 +1,34 @@
+/* Store current floating-point environment.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <shlib-compat.h>
+
+int
+__fegetenv (fenv_t *envp)
+{
+ _FPU_GETCW (*envp);
+
+ /* Success. */
+ return 0;
+}
+
+versioned_symbol (libm, __fegetenv, fegetenv, GLIBC_2_2);
diff --git a/ports/sysdeps/am33/fpu/fegetexcept.c b/ports/sysdeps/am33/fpu/fegetexcept.c
new file mode 100644
index 0000000000..13e5306af9
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fegetexcept.c
@@ -0,0 +1,34 @@
+/* Get enabled floating-point exceptions.
+ Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://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;
+}
diff --git a/ports/sysdeps/am33/fpu/fegetround.c b/ports/sysdeps/am33/fpu/fegetround.c
new file mode 100644
index 0000000000..d649f18bf7
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fegetround.c
@@ -0,0 +1,34 @@
+/* Return current rounding direction.
+ Copyright (C) 1998, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+
+int
+fegetround (void)
+{
+ int cw;
+
+ /* Get control word. */
+ _FPU_GETCW (cw);
+
+ return (cw & ROUND_MASK);
+}
diff --git a/ports/sysdeps/am33/fpu/feholdexcpt.c b/ports/sysdeps/am33/fpu/feholdexcpt.c
new file mode 100644
index 0000000000..1c002d8d94
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/feholdexcpt.c
@@ -0,0 +1,38 @@
+/* Store current floating-point environment and clear exceptions.
+ Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://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 = cw;
+
+ /* Clear all exception enable bits and flags. */
+ cw &= ~(_FPU_MASK_V|_FPU_MASK_Z|_FPU_MASK_O|_FPU_MASK_U|_FPU_MASK_I);
+ _FPU_SETFCW (cw);
+
+ return 0;
+}
diff --git a/ports/sysdeps/am33/fpu/fenv_libc.h b/ports/sysdeps/am33/fpu/fenv_libc.h
new file mode 100644
index 0000000000..40d57259bd
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fenv_libc.h
@@ -0,0 +1,32 @@
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on the corresponding file in the mips port.
+
+ 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
+ <http://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 0x003E0U
+#define CAUSE_MASK 0x07C00U
+#define ROUND_MASK 0x30000U
+
+/* Shift for FE_* flags to get up to the ENABLE bits and the CAUSE bits. */
+#define ENABLE_SHIFT 5
+#define CAUSE_SHIFT 10
+
+#endif /* _FENV_LIBC_H */
diff --git a/ports/sysdeps/am33/fpu/fesetenv.c b/ports/sysdeps/am33/fpu/fesetenv.c
new file mode 100644
index 0000000000..110c49c9f8
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fesetenv.c
@@ -0,0 +1,59 @@
+/* Install given floating-point environment.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <shlib-compat.h>
+
+int
+__fesetenv (const fenv_t *envp)
+{
+ fpu_control_t cw;
+
+ /* We want to clear all EF bits for the default end IEEE. */
+
+ if (envp == FE_DFL_ENV)
+ _FPU_SETFCW (_FPU_DEFAULT|FE_ALL_EXCEPT);
+ else if (envp == FE_NOMASK_ENV)
+ _FPU_SETFCW (_FPU_IEEE|FE_ALL_EXCEPT);
+ else
+ {
+ fpu_control_t temp;
+
+ _FPU_GETCW (temp);
+ cw = *envp;
+
+ /* If EF bits are cleared and the user requests them to be set,
+ we have to fail, because there's no way to do it. */
+ if (~temp & cw & FE_ALL_EXCEPT)
+ return -1;
+
+ /* We clear EF bits by storing a 1 in them, so flip the
+ FE_ALL_EXCEPT bits. */
+ cw = (cw & ~FE_ALL_EXCEPT) | (~cw & FE_ALL_EXCEPT);
+ _FPU_SETFCW (cw);
+ }
+
+ /* Success. */
+ return 0;
+}
+
+libm_hidden_ver (__fesetenv, fesetenv)
+versioned_symbol (libm, __fesetenv, fesetenv, GLIBC_2_2);
diff --git a/ports/sysdeps/am33/fpu/fesetround.c b/ports/sysdeps/am33/fpu/fesetround.c
new file mode 100644
index 0000000000..e77dc7684f
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fesetround.c
@@ -0,0 +1,28 @@
+/* Set current rounding direction.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+
+int
+fesetround (int round)
+{
+ /* The only supported rounding mode is to-nearest. Just check
+ whether we're switching to it. */
+ return (round != FE_TONEAREST);
+}
diff --git a/ports/sysdeps/am33/fpu/feupdateenv.c b/ports/sysdeps/am33/fpu/feupdateenv.c
new file mode 100644
index 0000000000..70951a3675
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/feupdateenv.c
@@ -0,0 +1,46 @@
+/* Install given floating-point environment and raise exceptions.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <shlib-compat.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;
+}
+
+versioned_symbol (libm, __feupdateenv, feupdateenv, GLIBC_2_2);
diff --git a/ports/sysdeps/am33/fpu/fgetexcptflg.c b/ports/sysdeps/am33/fpu/fgetexcptflg.c
new file mode 100644
index 0000000000..d5828e6011
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fgetexcptflg.c
@@ -0,0 +1,43 @@
+/* Store current representation for exceptions.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <shlib-compat.h>
+
+int
+__fegetexceptflag (fexcept_t *flagp, int excepts)
+{
+ fexcept_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;
+}
+
+versioned_symbol (libm, __fegetexceptflag, fegetexceptflag, GLIBC_2_2);
diff --git a/ports/sysdeps/am33/fpu/fpu_control.h b/ports/sysdeps/am33/fpu/fpu_control.h
new file mode 100644
index 0000000000..de28228e71
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fpu_control.h
@@ -0,0 +1,74 @@
+/* FPU control word bits. AM33/2.0 version.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on the corresponding file in the mips port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _FPU_CONTROL_H
+#define _FPU_CONTROL_H
+
+/* AM33/2.0 FPU floating point control register bits.
+ *
+ * 31-22 -> reserved
+ * 21-18 -> floating-point condition codes (L, G, E, U)
+ * 17-16 -> rounding modes (00 is to-nearest; other values are reserved
+ * 15 -> reserved (read as 0, write with 0)
+ * 14-10 -> Exception Cause (inValid, divZero, Overflow, Underflow, Inexact)
+ * 9- 5 -> Exception Enable
+ * 4- 0 -> Exception Flag, cleared when exception cause is set
+ */
+
+#include <features.h>
+#include <fenv.h>
+
+/* masking of interrupts */
+#define _FPU_MASK_V 0x0200 /* Invalid operation */
+#define _FPU_MASK_Z 0x0100 /* Division by zero */
+#define _FPU_MASK_O 0x0080 /* Overflow */
+#define _FPU_MASK_U 0x0040 /* Underflow */
+#define _FPU_MASK_I 0x0020 /* Inexact operation */
+
+/* rounding control */
+#define _FPU_RC_NEAREST 0x0 /* Only available mode */
+
+#define _FPU_RESERVED 0xffc08000 /* Reserved bits in fpcr */
+
+
+/* The fdlibm code requires strict IEEE double precision arithmetic,
+ and no interrupts for exceptions, rounding to nearest. */
+
+#define _FPU_DEFAULT 0x0000001f
+
+/* IEEE: same as above, but exceptions */
+#define _FPU_IEEE 0x000003ff
+
+/* Type of the control word. */
+typedef unsigned int fpu_control_t;
+
+/* Macros for accessing the hardware control word. _FPU_SETCW is
+ defined such that it won't modify the EF bits, that are cleared
+ when assigned bits that are set. Use SETFCW to get them actually
+ reset. */
+#define _FPU_SETFCW(cw) __asm__ ("fmov %0,fpcr" : : "ri" (cw))
+#define _FPU_SETCW(cw) _FPU_SETFCW((cw) & ~FE_ALL_EXCEPT)
+#define _FPU_GETCW(cw) __asm__ ("fmov fpcr,%0" : "=r" (cw))
+
+/* Default control word set at startup. */
+extern fpu_control_t __fpu_control;
+
+#endif /* fpu_control.h */
diff --git a/ports/sysdeps/am33/fpu/fraiseexcpt.c b/ports/sysdeps/am33/fpu/fraiseexcpt.c
new file mode 100644
index 0000000000..628ad56e9b
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fraiseexcpt.c
@@ -0,0 +1,78 @@
+/* Raise given exceptions.
+ Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the M68K port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+#include <shlib-compat.h>
+
+int
+__feraiseexcept (int excepts)
+{
+ /* Raise exceptions represented by EXCEPTS. But we must raise only one
+ signal at a time. It is important that if the overflow/underflow
+ exception and the divide by zero exception are given at the same
+ time, the overflow/underflow exception follows the divide by zero
+ exception. */
+
+ /* First: invalid exception. */
+ if (excepts & FE_INVALID)
+ {
+ /* One example of a invalid operation is 0 * Infinity. */
+ float x = HUGE_VALF, y = 0.0f;
+ __asm__ __volatile__ ("fmul %1,%0" : "+f" (x) : "f" (y));
+ }
+
+ /* Next: division by zero. */
+ if (excepts & FE_DIVBYZERO)
+ {
+ float x = 1.0f, y = 0.0f;
+ __asm__ __volatile__ ("fdiv %1,%0" : "+f" (x) : "f" (y));
+ }
+
+ /* Next: overflow. */
+ if (excepts & FE_OVERFLOW)
+ {
+ float x = FLT_MAX;
+
+ __asm__ __volatile__ ("fmul %0,%0" : "+f" (x));
+ }
+
+ /* Next: underflow. */
+ if (excepts & FE_UNDERFLOW)
+ {
+ float x = -FLT_MIN;
+
+ __asm__ __volatile__ ("fmul %0,%0" : "+f" (x));
+ }
+
+ /* Last: inexact. */
+ if (excepts & FE_INEXACT)
+ {
+ float x = 1.0f, y = 3.0f;
+ __asm__ __volatile__ ("fdiv %1,%0" : "=f" (x) : "f" (y));
+ }
+
+ /* Success. */
+ return 0;
+}
+
+libm_hidden_ver (__feraiseexcept, feraiseexcept)
+versioned_symbol (libm, __feraiseexcept, feraiseexcept, GLIBC_2_2);
diff --git a/ports/sysdeps/am33/fpu/fsetexcptflg.c b/ports/sysdeps/am33/fpu/fsetexcptflg.c
new file mode 100644
index 0000000000..a5bde40200
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/fsetexcptflg.c
@@ -0,0 +1,56 @@
+/* Set floating-point environment exception handling.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <shlib-compat.h>
+
+int
+__fesetexceptflag (const fexcept_t *flagp, int excepts)
+{
+ fpu_control_t cw, temp;
+
+ /* Get the current exceptions. */
+ _FPU_GETCW (cw);
+
+ /* Make sure the flags we want restored are legal. */
+ excepts &= FE_ALL_EXCEPT;
+ temp = *flagp & excepts;
+
+ /* If EF bits are clear and the user requests them to be set,
+ we have to fail, because there's no way to do it. */
+ if (~(cw & excepts) & temp)
+ return -1;
+
+ /* We clear EF bits by storing a 1 in them, so flip the
+ FE_ALL_EXCEPT bits. */
+ temp = (~temp & 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. */
+ cw = (cw & ~FE_ALL_EXCEPT) | temp;
+
+ _FPU_SETFCW (cw);
+
+ /* Success. */
+ return 0;
+}
+
+versioned_symbol (libm, __fesetexceptflag, fesetexceptflag, GLIBC_2_2);
diff --git a/ports/sysdeps/am33/fpu/ftestexcept.c b/ports/sysdeps/am33/fpu/ftestexcept.c
new file mode 100644
index 0000000000..ef3e761fcc
--- /dev/null
+++ b/ports/sysdeps/am33/fpu/ftestexcept.c
@@ -0,0 +1,33 @@
+/* Test exception in current environment.
+ Copyright (C) 1998, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Alexandre Oliva <aoliva@redhat.com>
+ based on corresponding file in the MIPS port.
+
+ 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
+ <http://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;
+}