2016-11-06 22:19:38 +01:00
|
|
|
From ecd4eceae98cfb1c83133bdeaa9095546ca8b7c6 Mon Sep 17 00:00:00 2001
|
2016-05-26 15:08:15 +02:00
|
|
|
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
|
|
Date: Thu, 26 May 2016 15:05:48 +0200
|
2016-11-06 22:19:38 +01:00
|
|
|
Subject: [PATCH] Use <fenv.h> when available instead of <fpu_control.h>
|
2016-05-26 15:08:15 +02:00
|
|
|
|
|
|
|
musl libc (http://musl-libc.org lack the non-standard <fpu_control.h>
|
|
|
|
header, which is used in src/os/linux/{i386,x86_64}/init.c files to
|
|
|
|
setup the floating point precision. This patch makes it use the
|
2016-11-06 22:19:38 +01:00
|
|
|
standard C <fenv.h> header instead when available.
|
2016-05-26 15:08:15 +02:00
|
|
|
|
|
|
|
Original patch at Felix Janda at
|
2016-11-06 22:19:38 +01:00
|
|
|
https://sourceforge.net/p/jamvm/patches/6/, adapted to still use
|
|
|
|
<fpu_control.h> if <fenv.h> is not provided.
|
2016-05-26 15:08:15 +02:00
|
|
|
|
|
|
|
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
|
|
---
|
2016-11-06 22:19:38 +01:00
|
|
|
configure.ac | 2 +-
|
|
|
|
src/os/linux/i386/init.c | 15 +++++++++++++++
|
|
|
|
src/os/linux/x86_64/init.c | 15 +++++++++++++--
|
|
|
|
3 files changed, 29 insertions(+), 3 deletions(-)
|
2016-05-26 15:08:15 +02:00
|
|
|
|
2016-11-06 22:19:38 +01:00
|
|
|
diff --git a/configure.ac b/configure.ac
|
|
|
|
index 19f77e6..ce59a3e 100644
|
|
|
|
--- a/configure.ac
|
|
|
|
+++ b/configure.ac
|
|
|
|
@@ -279,7 +279,7 @@ fi
|
|
|
|
|
|
|
|
dnl Checks for header files.
|
|
|
|
AC_HEADER_STDC
|
|
|
|
-AC_CHECK_HEADERS(sys/time.h unistd.h endian.h sys/param.h locale.h alloca.h)
|
|
|
|
+AC_CHECK_HEADERS(sys/time.h unistd.h endian.h sys/param.h locale.h alloca.h fenv.h)
|
|
|
|
|
|
|
|
if test "$enable_zip" != no; then
|
|
|
|
AC_CHECK_HEADER(zlib.h,,AC_MSG_ERROR(zlib.h is missing))
|
2016-05-26 15:08:15 +02:00
|
|
|
diff --git a/src/os/linux/i386/init.c b/src/os/linux/i386/init.c
|
2016-11-06 22:19:38 +01:00
|
|
|
index d9c6648..8fefe7d 100644
|
2016-05-26 15:08:15 +02:00
|
|
|
--- a/src/os/linux/i386/init.c
|
|
|
|
+++ b/src/os/linux/i386/init.c
|
2016-11-06 22:19:38 +01:00
|
|
|
@@ -19,18 +19,33 @@
|
2016-05-26 15:08:15 +02:00
|
|
|
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2016-11-06 22:19:38 +01:00
|
|
|
+#include "config.h"
|
|
|
|
+
|
|
|
|
+#if defined(HAVE_FENV_H)
|
2016-05-26 15:08:15 +02:00
|
|
|
+#include <fenv.h>
|
2016-11-06 22:19:38 +01:00
|
|
|
+#else
|
|
|
|
#include <fpu_control.h>
|
|
|
|
+#endif
|
2016-05-26 15:08:15 +02:00
|
|
|
|
|
|
|
/* Change floating point precision to double (64-bit) from
|
|
|
|
* the extended (80-bit) Linux default. */
|
|
|
|
|
|
|
|
void setDoublePrecision() {
|
2016-11-06 22:19:38 +01:00
|
|
|
+#if defined(HAVE_FENV_H)
|
2016-05-26 15:08:15 +02:00
|
|
|
+ fenv_t fenv;
|
2016-11-06 22:19:38 +01:00
|
|
|
+
|
2016-05-26 15:08:15 +02:00
|
|
|
+ fegetenv(&fenv);
|
|
|
|
+ fenv.__control_word &= ~0x300; /* _FPU_EXTENDED */
|
|
|
|
+ fenv.__control_word |= 0x200; /* _FPU_DOUBLE */
|
|
|
|
+ fesetenv(&fenv);
|
2016-11-06 22:19:38 +01:00
|
|
|
+#else
|
|
|
|
fpu_control_t cw;
|
|
|
|
|
|
|
|
_FPU_GETCW(cw);
|
|
|
|
cw &= ~_FPU_EXTENDED;
|
|
|
|
cw |= _FPU_DOUBLE;
|
|
|
|
_FPU_SETCW(cw);
|
|
|
|
+#endif
|
2016-05-26 15:08:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void initialisePlatform() {
|
|
|
|
diff --git a/src/os/linux/x86_64/init.c b/src/os/linux/x86_64/init.c
|
2016-11-06 22:19:38 +01:00
|
|
|
index 9d55229..b42b14e 100644
|
2016-05-26 15:08:15 +02:00
|
|
|
--- a/src/os/linux/x86_64/init.c
|
|
|
|
+++ b/src/os/linux/x86_64/init.c
|
2016-11-06 22:19:38 +01:00
|
|
|
@@ -19,7 +19,11 @@
|
2016-05-26 15:08:15 +02:00
|
|
|
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
-#ifdef __linux__
|
2016-11-06 22:19:38 +01:00
|
|
|
+#include "config.h"
|
|
|
|
+
|
|
|
|
+#if defined(HAVE_FENV_H)
|
2016-05-26 15:08:15 +02:00
|
|
|
+#include <fenv.h>
|
2016-11-06 22:19:38 +01:00
|
|
|
+#else
|
|
|
|
#include <fpu_control.h>
|
|
|
|
#endif
|
2016-05-26 15:08:15 +02:00
|
|
|
|
2016-11-06 22:19:38 +01:00
|
|
|
@@ -30,7 +34,14 @@
|
2016-05-26 15:08:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void setDoublePrecision() {
|
|
|
|
-#ifdef __linux__
|
2016-11-06 22:19:38 +01:00
|
|
|
+#if defined(HAVE_FENV_H)
|
2016-05-26 15:08:15 +02:00
|
|
|
+ fenv_t fenv;
|
2016-11-06 22:19:38 +01:00
|
|
|
+
|
2016-05-26 15:08:15 +02:00
|
|
|
+ fegetenv(&fenv);
|
|
|
|
+ fenv.__control_word &= ~0x300; /*_FPU_EXTENDED */
|
|
|
|
+ fenv.__control_word |= 0x200; /*_FPU_DOUBLE */
|
|
|
|
+ fesetenv(&fenv);
|
2016-11-06 22:19:38 +01:00
|
|
|
+#else
|
|
|
|
fpu_control_t cw;
|
2016-05-26 15:08:15 +02:00
|
|
|
|
2016-11-06 22:19:38 +01:00
|
|
|
_FPU_GETCW(cw);
|
2016-05-26 15:08:15 +02:00
|
|
|
--
|
|
|
|
2.7.4
|
|
|
|
|