about summary refs log tree commit diff
path: root/sysdeps/i386/fpu
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/i386/fpu')
-rw-r--r--sysdeps/i386/fpu/fclrexcpt.c40
-rw-r--r--sysdeps/i386/fpu/fegetenv.c27
-rw-r--r--sysdeps/i386/fpu/fegetround.c31
-rw-r--r--sysdeps/i386/fpu/feholdexcpt.c36
-rw-r--r--sysdeps/i386/fpu/fenvbits.h91
-rw-r--r--sysdeps/i386/fpu/fesetenv.c76
-rw-r--r--sysdeps/i386/fpu/fesetround.c38
-rw-r--r--sysdeps/i386/fpu/feupdateenv.c39
-rw-r--r--sysdeps/i386/fpu/fgetexcptflg.c32
-rw-r--r--sysdeps/i386/fpu/fraiseexcpt.c75
-rw-r--r--sysdeps/i386/fpu/fsetexcptflg.c40
-rw-r--r--sysdeps/i386/fpu/ftestexcept.c32
-rw-r--r--sysdeps/i386/fpu/mathbits.h36
13 files changed, 593 insertions, 0 deletions
diff --git a/sysdeps/i386/fpu/fclrexcpt.c b/sysdeps/i386/fpu/fclrexcpt.c
new file mode 100644
index 0000000000..0b43776f54
--- /dev/null
+++ b/sysdeps/i386/fpu/fclrexcpt.c
@@ -0,0 +1,40 @@
+/* Clear given exceptions in current floating-point environment.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+void
+feclearexcept (int excepts)
+{
+  fenv_t temp;
+
+  /* Mask out unsupported bits/exceptions.  */
+  excepts &= FE_ALL_EXCEPT;
+
+  /* Bah, we have to clear selected exceptions.  Since there is no
+     `fldsw' instruction we have to do it the hard way.  */
+  __asm__ ("fnstenv %0" : "=m" (*&temp));
+
+  /* Clear the relevant bits.  */
+  temp.status_word &= excepts ^ FE_ALL_EXCEPT;
+
+  /* Put the new data in effect.  */
+  __asm__ ("fldenv %0" : : "m" (*&temp));
+}
diff --git a/sysdeps/i386/fpu/fegetenv.c b/sysdeps/i386/fpu/fegetenv.c
new file mode 100644
index 0000000000..452449d044
--- /dev/null
+++ b/sysdeps/i386/fpu/fegetenv.c
@@ -0,0 +1,27 @@
+/* Store current floating-point environment.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+void
+fegetenv (fenv_t *envp)
+{
+  __asm__ ("fnstenv %0" : "=m" (*envp));
+}
diff --git a/sysdeps/i386/fpu/fegetround.c b/sysdeps/i386/fpu/fegetround.c
new file mode 100644
index 0000000000..4dfa32d0b5
--- /dev/null
+++ b/sysdeps/i386/fpu/fegetround.c
@@ -0,0 +1,31 @@
+/* Return current rounding direction.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+fegetround (void)
+{
+  int cw;
+
+  __asm__ ("fnstcw %0" : "=m" (*&cw));
+
+  return cw & 0xc00;
+}
diff --git a/sysdeps/i386/fpu/feholdexcpt.c b/sysdeps/i386/fpu/feholdexcpt.c
new file mode 100644
index 0000000000..c9a0f73489
--- /dev/null
+++ b/sysdeps/i386/fpu/feholdexcpt.c
@@ -0,0 +1,36 @@
+/* Store current floating-point environment and clear exceptions.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+feholdexcept (fenv_t *envp)
+{
+  unsigned short int work;
+
+  /* Store the environment.  */
+  __asm__ ("fnstenv %0" : "=m" (*envp));
+
+  /* Now set all exceptions to non-stop.  */
+  work = envp->control_word | 0x3f;
+  __asm__ ("fldcw %0" : : "m" (*&work));
+
+  return 1;
+}
diff --git a/sysdeps/i386/fpu/fenvbits.h b/sysdeps/i386/fpu/fenvbits.h
new file mode 100644
index 0000000000..bea89a15b1
--- /dev/null
+++ b/sysdeps/i386/fpu/fenvbits.h
@@ -0,0 +1,91 @@
+/* Copyright (C) 1997 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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* This file should never be included directly.  */
+
+#ifndef _FENVBITS_H
+#define _FENVBITS_H	1
+
+/* Define bits representing the exception.  We use the bit positions
+   of the appropriate bits in the FPU control word.  */
+enum
+  {
+    FE_INVALID = 0x01,
+#define FE_INVALID	FE_INVALID
+    __FE_DENORM = 0x02,
+    FE_DIVBYZERO = 0x04,
+#define FE_DIVBYZERO	FE_DIVBYZERO
+    FE_OVERFLOW = 0x08,
+#define FE_OVERFLOW	FE_OVERFLOW
+    FE_UNDERFLOW = 0x10,
+#define FE_UNDERFLOW	FE_UNDERFLOW
+    FE_INEXACT = 0x20
+#define FE_INEXACT	FE_INEXACT
+  };
+
+#define FE_ALL_EXCEPT \
+	(FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
+
+/* The ix87 FPU supports all of the four defined rounding modes.  We
+   use again the bit positions in the FPU control word as the values
+   for the appropriate macros.  */
+enum
+  {
+    FE_TONEAREST = 0,
+#define FE_TONEAREST	FE_TONEAREST
+    FE_DOWNWARD = 0x400,
+#define FE_DOWNWARD	FE_DOWNWARD
+    FE_UPWARD = 0x800,
+#define FE_UPWARD	FE_UPWARD
+    FE_TOWARDSZERO = 0xc00
+#define FE_TOWARDSZERO	FE_TOWARDSZERO
+  };
+
+
+/* Type representing exception flags.  */
+typedef unsigned short int fexcept_t;
+
+
+/* Type representing floating-point environment.  This function corresponds to the layout of the block written by the `fstenv'.  */
+typedef struct
+  {
+    unsigned short int control_word;
+    unsigned short int __unused1;
+    unsigned short int status_word;
+    unsigned short int __unused2;
+    unsigned short int tags;
+    unsigned short int __unused3;
+    unsigned int eip;
+    unsigned short int cs_selector;
+    unsigned int opcode:11;
+    unsigned int __unused4:5;
+    unsigned int data_offset;
+    unsigned short int data_selector;
+    unsigned short int __unused5;
+  }
+fenv_t;
+
+/* If the default argument is used we use this value.  */
+#define FE_DFL_ENV	((fenv_t *) -1)
+
+#ifdef __USE_GNU
+/* Floating-point environment where none of the exception is masked.  */
+# define FE_NOMASK_ENV	((fenv_t *) -2)
+#endif
+
+#endif /* fenvbits.h */
diff --git a/sysdeps/i386/fpu/fesetenv.c b/sysdeps/i386/fpu/fesetenv.c
new file mode 100644
index 0000000000..e7300ea1e6
--- /dev/null
+++ b/sysdeps/i386/fpu/fesetenv.c
@@ -0,0 +1,76 @@
+/* Install given floating-point environment.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+#include <assert.h>
+
+
+void
+fesetenv (const fenv_t *envp)
+{
+  fenv_t temp;
+
+  /* The memory block used by fstenv/fldenv has a size of 28 bytes.  */
+  assert (sizeof (fenv_t) == 28);
+
+  /* Install the environment specified by ENVP.  But there are a few
+     values which we do not want to come from the saved environment.
+     Therefore, we get the current environment and replace the values
+     we want to use from the environment specified by the parameter.  */
+  __asm__ ("fnstenv %0" : "=m" (*&temp));
+
+  if (envp == FE_DFL_ENV)
+    {
+      temp.control_word |= FE_ALL_EXCEPT;
+      temp.control_word &= ~FE_TOWARDSZERO;
+      temp.status_word &= ~FE_ALL_EXCEPT;
+      temp.eip = 0;
+      temp.cs_selector = 0;
+      temp.opcode = 0;
+      temp.data_offset = 0;
+      temp.data_selector = 0;
+    }
+  else if (envp == FE_NOMASK_ENV)
+    {
+      temp.control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDSZERO);
+      temp.status_word &= ~FE_ALL_EXCEPT;
+      temp.eip = 0;
+      temp.cs_selector = 0;
+      temp.opcode = 0;
+      temp.data_offset = 0;
+      temp.data_selector = 0;
+    }
+  else
+    {
+      temp.control_word &= ~(FE_ALL_EXCEPT | FE_TOWARDSZERO);
+      temp.control_word |= (envp->control_word
+			    & (FE_ALL_EXCEPT | FE_TOWARDSZERO));
+      temp.status_word &= ~FE_ALL_EXCEPT;
+      temp.status_word |= envp->status_word & FE_ALL_EXCEPT;
+      temp.eip = envp->eip;
+      temp.cs_selector = envp->cs_selector;
+      temp.opcode = envp->opcode;
+      temp.data_offset = envp->data_offset;
+      temp.data_selector = envp->data_selector;
+    }
+
+  __asm__ ("fldenv %0" : : "m" (temp));
+}
diff --git a/sysdeps/i386/fpu/fesetround.c b/sysdeps/i386/fpu/fesetround.c
new file mode 100644
index 0000000000..844c58663e
--- /dev/null
+++ b/sysdeps/i386/fpu/fesetround.c
@@ -0,0 +1,38 @@
+/* Set current rounding direction.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+fesetround (int round)
+{
+  unsigned short int cw;
+
+  if ((round & ~0xc00) != 0)
+    /* ROUND is no valid rounding mode.  */
+    return 0;
+
+  __asm__ ("fnstcw %0" : "=m" (*&cw));
+  cw &= ~0xc00;
+  cw |= round;
+  __asm__ ("fldcw %0" : : "m" (*&cw));
+
+  return 1;
+}
diff --git a/sysdeps/i386/fpu/feupdateenv.c b/sysdeps/i386/fpu/feupdateenv.c
new file mode 100644
index 0000000000..0f7abc2344
--- /dev/null
+++ b/sysdeps/i386/fpu/feupdateenv.c
@@ -0,0 +1,39 @@
+/* Install given floating-point environment and raise exceptions.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+void
+feupdateenv (const fenv_t *envp)
+{
+  fexcept_t temp;
+
+  /* Save current exceptions.  */
+  __asm__ ("fnstsw %0" : "=m" (*&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 ((int) temp);
+}
diff --git a/sysdeps/i386/fpu/fgetexcptflg.c b/sysdeps/i386/fpu/fgetexcptflg.c
new file mode 100644
index 0000000000..1db3953eae
--- /dev/null
+++ b/sysdeps/i386/fpu/fgetexcptflg.c
@@ -0,0 +1,32 @@
+/* Store current representation for exceptions.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+void
+fegetexceptflag (fexcept_t *flagp, int excepts)
+{
+  fexcept_t temp;
+
+  /* Get the current exceptions.  */
+  __asm__ ("fnstsw %0" : "=m" (*&temp));
+
+  *flagp = temp & excepts & FE_ALL_EXCEPT;
+}
diff --git a/sysdeps/i386/fpu/fraiseexcpt.c b/sysdeps/i386/fpu/fraiseexcpt.c
new file mode 100644
index 0000000000..90e992aaec
--- /dev/null
+++ b/sysdeps/i386/fpu/fraiseexcpt.c
@@ -0,0 +1,75 @@
+/* Raise given exceptions.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+#include <math.h>
+
+void
+feraiseexcept (int excepts)
+{
+  /* Raise exceptions represented by EXPECTS.  But we must raise only
+     one signal at a time.  It is important the 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) != 0)
+    {
+      /* One example of a invalid operation is 0 * Infinity.  */
+      double d = 0.0 * HUGE_VAL;
+      (void) &d;
+      /* Now force the exception.  */
+      __asm__ ("fwait");
+    }
+
+  /* Next: division by zero.  */
+  if ((FE_DIVBYZERO & excepts) != 0)
+    {
+      double d;
+      __asm__ ("fld1; fldz; fdivp %%st, %%st(1); fwait" : "=t" (d));
+      (void) &d;
+    }
+
+  /* Next: overflow.  */
+  if ((FE_OVERFLOW & excepts) != 0)
+    {
+      long double d = LDBL_MAX * LDBL_MAX;
+      (void) &d;
+      /* Now force the exception.  */
+      __asm__ ("fwait");
+    }
+
+  /* Next: underflow.  */
+  if ((FE_UNDERFLOW & excepts) != 0)
+    {
+      long double d = LDBL_MIN / 16.0;
+      (void) &d;
+      /* Now force the exception.  */
+      __asm__ ("fwait");
+    }
+
+  /* Last: inexact.  */
+  if ((FE_INEXACT & excepts) != 0)
+    {
+      long double d;
+      __asm__ ("fld1; fldpi; fdivp %%st, %%st(1); fwait" : "=t" (d));
+      (void) &d;
+    }
+}
diff --git a/sysdeps/i386/fpu/fsetexcptflg.c b/sysdeps/i386/fpu/fsetexcptflg.c
new file mode 100644
index 0000000000..598b8d2233
--- /dev/null
+++ b/sysdeps/i386/fpu/fsetexcptflg.c
@@ -0,0 +1,40 @@
+/* Set floating-point environment exception handling.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+#include <math.h>
+
+void
+fesetexceptflag (const fexcept_t *flagp, int excepts)
+{
+  fenv_t temp;
+
+  /* Get the current environment.  We have to do this since we cannot
+     separately set the status word.  */
+  __asm__ ("fnstenv %0" : "=m" (*&temp));
+
+  temp.status_word &= ~(excepts & FE_ALL_EXCEPT);
+  temp.status_word |= *flagp & excepts & FE_ALL_EXCEPT;
+
+  /* Store the new status word (along with the rest of the environment.
+     Possibly new exceptions are set but they won't get executed unless
+     the next floating-point instruction.  */
+  __asm__ ("fldenv %0" : : "m" (*&temp));
+}
diff --git a/sysdeps/i386/fpu/ftestexcept.c b/sysdeps/i386/fpu/ftestexcept.c
new file mode 100644
index 0000000000..c69170fb2c
--- /dev/null
+++ b/sysdeps/i386/fpu/ftestexcept.c
@@ -0,0 +1,32 @@
+/* Test exception in current environment.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+fetestexcept (int excepts)
+{
+  int temp;
+
+  /* Get current exceptions.  */
+  __asm__ ("fnstsw %0" : "=a" (temp));
+
+  return temp & excepts & FE_ALL_EXCEPT;
+}
diff --git a/sysdeps/i386/fpu/mathbits.h b/sysdeps/i386/fpu/mathbits.h
new file mode 100644
index 0000000000..7885afeec0
--- /dev/null
+++ b/sysdeps/i386/fpu/mathbits.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1997 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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifndef _MATHBITS_H
+#define _MATHBITS_H	1
+
+/* The ix87 FPUs evaluate all values in the 80 bit floating-point format
+   which is also available for the user as `long double'.  Therefore
+   we define:  */
+typedef long double float_t;	/* `float' expressions are evaluated as
+				   `long double'.  */
+typedef long double double_t;	/* `double' expressions are evaluated as
+				   `long double'.  */
+
+/* Signal that both types are `long double'.  */
+#define FLT_EVAL_METHOD	2
+
+/* Define `INFINITY' as value of type `float_t'.  */
+#define INFINITY	HUGE_VALL
+
+#endif /* mathbits.h */