summaryrefslogtreecommitdiff
path: root/ext/fputils/include
diff options
context:
space:
mode:
authorAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-10-16 05:49:58 -0400
committerAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-10-16 05:49:58 -0400
commite6ad39adac7e77e36a294f63da47ad79ca446e93 (patch)
treef3d182a99cb9febbce10d634673a2bda18dae8a7 /ext/fputils/include
parent2d2006ddb3df926d79d0d744af81e8260f5c466c (diff)
downloadgem5-e6ad39adac7e77e36a294f63da47ad79ca446e93.tar.xz
ext: Update fputils to rev 6a47fd8358
This patch updates fputils to the latest revision (6a47fd8358) from the upstream repository (github.com/andysan/fputils). Most notably, this includes changes that export a limited set of 64-bit float manipulation and avoids a warning about unused 64-bit floats in clang.
Diffstat (limited to 'ext/fputils/include')
-rw-r--r--ext/fputils/include/fputils/fp64.h73
-rw-r--r--ext/fputils/include/fputils/fp80.h60
-rw-r--r--ext/fputils/include/fputils/fptypes.h86
3 files changed, 199 insertions, 20 deletions
diff --git a/ext/fputils/include/fputils/fp64.h b/ext/fputils/include/fputils/fp64.h
new file mode 100644
index 000000000..91ebf6b12
--- /dev/null
+++ b/ext/fputils/include/fputils/fp64.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2014, Andreas Sandberg
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _FP64_H
+#define _FP64_H 1
+
+#include <fputils/fptypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @defgroup fp64 64-bit Floats
+ * Functions handling 64-bit floats.
+ *
+ * @{
+ */
+
+
+/** Constant representing +inf */
+extern const fp64_t fp64_pinf;
+/** Constant representing -inf */
+extern const fp64_t fp64_ninf;
+
+/** Constant representing a quiet NaN */
+extern const fp64_t fp64_qnan;
+/** Constant representing a negative quiet NaN */
+extern const fp64_t fp64_nqnan;
+/** Constant representing a quiet indefinite NaN */
+extern const fp64_t fp64_qnani;
+/** Constant representing a signaling NaN */
+extern const fp64_t fp64_snan;
+/** Constant representing a negative signaling NaN */
+extern const fp64_t fp64_nsnan;
+
+/** Alias for fp64_qnan */
+extern const fp64_t fp64_nan;
+
+/** @} */
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/ext/fputils/include/fputils/fp80.h b/ext/fputils/include/fputils/fp80.h
index 70acb6cb1..c824baa1c 100644
--- a/ext/fputils/include/fputils/fp80.h
+++ b/ext/fputils/include/fputils/fp80.h
@@ -30,10 +30,12 @@
#ifndef _FP80_H
#define _FP80_H 1
-#include <math.h>
-#include <stdint.h>
+#include <math.h> /* FP_NAN et al. */
#include <stdio.h>
+#include <fputils/fptypes.h>
+
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -45,15 +47,6 @@ extern "C" {
* @{
*/
-/** Internal representation of an 80-bit float. */
-typedef union {
- char bits[10];
- struct {
- uint64_t fi;
- uint16_t se;
- } repr;
-} fp80_t;
-
/** Constant representing +inf */
extern const fp80_t fp80_pinf;
/** Constant representing -inf */
@@ -190,6 +183,21 @@ int fp80_iszero(fp80_t fp80);
*/
int fp80_issubnormal(fp80_t fp80);
+
+/**
+ * Convert an 80-bit float to a 64-bit double.
+ *
+ * Convenience wrapper around fp80_cvtfp64() that returns a double
+ * instead of the internal fp64_t representation.
+ *
+ * Note that this conversion is lossy, see fp80_cvtfp64() for details
+ * of the conversion.
+ *
+ * @param fp80 Source value to convert.
+ * @return value represented as double.
+ */
+double fp80_cvtd(fp80_t fp80);
+
/**
* Convert an 80-bit float to a 64-bit double.
*
@@ -214,24 +222,36 @@ int fp80_issubnormal(fp80_t fp80);
* @param fp80 Source value to convert.
* @return 64-bit version of the float.
*/
-double fp80_cvtd(fp80_t fp80);
+fp64_t fp80_cvtfp64(fp80_t fp80);
/**
- * Convert an 64-bit double to an 80-bit float.
- *
- * This function converts a standard 64-bit double into an 80-bit
- * float. This conversion is completely lossless since the 80-bit
- * float represents a superset of what a 64-bit double can
- * represent.
+ * Convert a double to an 80-bit float.
*
- * @note Denormals will be converted to normalized values.
+ * This is a convenience wrapper around fp80_cvffp64() and provides a
+ * convenient way of using the native double type instead of the
+ * internal fp64_t representation.
*
* @param fpd Source value to convert.
- * @return 64-bit version of the float.
+ * @return 80-bit version of the float.
*/
fp80_t fp80_cvfd(double fpd);
/**
+ * Convert a 64-bit float to an 80-bit float.
+ *
+ * This function converts the internal representation of a 64-bit
+ * float into an 80-bit float. This conversion is completely lossless
+ * since the 80-bit float represents a superset of what a 64-bit
+ * float can represent.
+ *
+ * @note Denormals will be converted to normalized values.
+ *
+ * @param fp64 64-bit float to convert.
+ * @return 80-bit version of the float.
+ */
+fp80_t fp80_cvffp64(fp64_t fp64);
+
+/**
* Dump the components of an 80-bit float to a file.
*
* @warning This function is intended for debugging and the format of
diff --git a/ext/fputils/include/fputils/fptypes.h b/ext/fputils/include/fputils/fptypes.h
new file mode 100644
index 000000000..714ddd439
--- /dev/null
+++ b/ext/fputils/include/fputils/fptypes.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2014, Andreas Sandberg
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _FPTYPES_H
+#define _FPTYPES_H 1
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup fp64
+ * @{
+ */
+
+/** Internal representation of a 64-bit float */
+typedef union {
+ /**
+ * Raw value exposed as an unsigned integer. Mainly used for bit
+ * manipulation.
+ */
+ uint64_t bits;
+ /** Representation using the built-in double type */
+ double value;
+} fp64_t;
+
+/** @} */
+
+
+/**
+ * @addtogroup fp80
+ * @{
+ */
+
+/** Internal representation of an 80-bit float. */
+typedef union {
+ struct {
+ /** Raw representation of the integer part bit and the
+ * fraction. Note that unlike 64-bit floating point
+ * representations the integer bit is explicit. */
+ uint64_t fi;
+ /** Raw representation of sign bit and exponent */
+ uint16_t se;
+ } repr;
+ /**
+ * Represented as a char array, mainly intended for debug dumping
+ * and serialization.
+ */
+ char bits[10];
+} fp80_t;
+
+/** @} */
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif