about summary refs log tree commit diff
path: root/sysdeps/ieee754
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/ieee754')
-rw-r--r--sysdeps/ieee754/dbl-64/s_getpayload.c37
-rw-r--r--sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c33
-rw-r--r--sysdeps/ieee754/flt-32/s_getpayloadf.c33
-rw-r--r--sysdeps/ieee754/ldbl-128/s_getpayloadl.c57
-rw-r--r--sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c34
-rw-r--r--sysdeps/ieee754/ldbl-96/s_getpayloadl.c32
6 files changed, 226 insertions, 0 deletions
diff --git a/sysdeps/ieee754/dbl-64/s_getpayload.c b/sysdeps/ieee754/dbl-64/s_getpayload.c
new file mode 100644
index 0000000000..2e7f03375f
--- /dev/null
+++ b/sysdeps/ieee754/dbl-64/s_getpayload.c
@@ -0,0 +1,37 @@
+/* Get NaN payload.  dbl-64 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fix-int-fp-convert-zero.h>
+#include <math.h>
+#include <math_private.h>
+#include <stdint.h>
+
+double
+getpayload (const double *x)
+{
+  uint32_t hx, lx;
+  EXTRACT_WORDS (hx, lx, *x);
+  hx &= 0x7ffff;
+  uint64_t ix = ((uint64_t) hx << 32) | lx;
+  if (FIX_INT_FP_CONVERT_ZERO && ix == 0)
+    return 0.0f;
+  return (double) ix;
+}
+#ifdef NO_LONG_DOUBLE
+weak_alias (getpayload, getpayloadl)
+#endif
diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c
new file mode 100644
index 0000000000..c1cf56e0cc
--- /dev/null
+++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c
@@ -0,0 +1,33 @@
+/* Get NaN payload.  dbl-64/wordsize-64 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <stdint.h>
+
+double
+getpayload (const double *x)
+{
+  uint64_t ix;
+  EXTRACT_WORDS64 (ix, *x);
+  ix &= 0x7ffffffffffffULL;
+  return (double) ix;
+}
+#ifdef NO_LONG_DOUBLE
+weak_alias (getpayload, getpayloadl)
+#endif
diff --git a/sysdeps/ieee754/flt-32/s_getpayloadf.c b/sysdeps/ieee754/flt-32/s_getpayloadf.c
new file mode 100644
index 0000000000..fcc9e32716
--- /dev/null
+++ b/sysdeps/ieee754/flt-32/s_getpayloadf.c
@@ -0,0 +1,33 @@
+/* Get NaN payload.  flt-32 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fix-int-fp-convert-zero.h>
+#include <math.h>
+#include <math_private.h>
+#include <stdint.h>
+
+float
+getpayloadf (const float *x)
+{
+  uint32_t ix;
+  GET_FLOAT_WORD (ix, *x);
+  ix &= 0x3fffff;
+  if (FIX_INT_FP_CONVERT_ZERO && ix == 0)
+    return 0.0f;
+  return (float) ix;
+}
diff --git a/sysdeps/ieee754/ldbl-128/s_getpayloadl.c b/sysdeps/ieee754/ldbl-128/s_getpayloadl.c
new file mode 100644
index 0000000000..ac7f6edce2
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128/s_getpayloadl.c
@@ -0,0 +1,57 @@
+/* Get NaN payload.  ldbl-128 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <stdint.h>
+
+long double
+getpayloadl (const long double *x)
+{
+  uint64_t hx, lx;
+  GET_LDOUBLE_WORDS64 (hx, lx, *x);
+  hx &= 0x7fffffffffffULL;
+  /* Construct the representation of the return value directly, since
+     128-bit integers may not be available.  */
+  int lz;
+  if (hx == 0)
+    {
+      if (lx == 0)
+	return 0.0L;
+      else
+	lz = __builtin_clzll (lx) + 64;
+    }
+  else
+    lz = __builtin_clzll (hx);
+  int shift = lz - 15;
+  if (shift >= 64)
+    {
+      hx = lx << (shift - 64);
+      lx = 0;
+    }
+  else
+    {
+      /* 2 <= SHIFT <= 63.  */
+      hx = (hx << shift) | (lx >> (64 - shift));
+      lx <<= shift;
+    }
+  hx = (hx & 0xffffffffffffULL) | ((0x3fffULL + 127 - lz) << 48);
+  long double ret;
+  SET_LDOUBLE_WORDS64 (ret, hx, lx);
+  return ret;
+}
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c b/sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c
new file mode 100644
index 0000000000..c23ba0c9d5
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c
@@ -0,0 +1,34 @@
+/* Get NaN payload.  ldbl-128ibm version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fix-int-fp-convert-zero.h>
+#include <math.h>
+#include <math_private.h>
+#include <stdint.h>
+
+long double
+getpayloadl (const long double *x)
+{
+  double xhi = ldbl_high (*x);
+  uint64_t ix;
+  EXTRACT_WORDS64 (ix, xhi);
+  ix &= 0x7ffffffffffffULL;
+  if (FIX_INT_FP_CONVERT_ZERO && ix == 0)
+    return 0.0L;
+  return (long double) ix;
+}
diff --git a/sysdeps/ieee754/ldbl-96/s_getpayloadl.c b/sysdeps/ieee754/ldbl-96/s_getpayloadl.c
new file mode 100644
index 0000000000..3ef90d07de
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-96/s_getpayloadl.c
@@ -0,0 +1,32 @@
+/* Get NaN payload.  ldbl-96 version.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <stdint.h>
+
+long double
+getpayloadl (const long double *x)
+{
+  uint16_t se __attribute__ ((unused));
+  uint32_t hx, lx;
+  GET_LDOUBLE_WORDS (se, hx, lx, *x);
+  hx &= 0x3fffffff;
+  uint64_t ix = ((uint64_t) hx << 32) | lx;
+  return (long double) ix;
+}