1 From ecd4eceae98cfb1c83133bdeaa9095546ca8b7c6 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Thu, 26 May 2016 15:05:48 +0200
4 Subject: [PATCH] Use <fenv.h> when available instead of <fpu_control.h>
6 musl libc (http://musl-libc.org lack the non-standard <fpu_control.h>
7 header, which is used in src/os/linux/{i386,x86_64}/init.c files to
8 setup the floating point precision. This patch makes it use the
9 standard C <fenv.h> header instead when available.
11 Original patch at Felix Janda at
12 https://sourceforge.net/p/jamvm/patches/6/, adapted to still use
13 <fpu_control.h> if <fenv.h> is not provided.
15 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
18 src/os/linux/i386/init.c | 15 +++++++++++++++
19 src/os/linux/x86_64/init.c | 15 +++++++++++++--
20 3 files changed, 29 insertions(+), 3 deletions(-)
22 diff --git a/configure.ac b/configure.ac
23 index 19f77e6..ce59a3e 100644
26 @@ -279,7 +279,7 @@ fi
28 dnl Checks for header files.
30 -AC_CHECK_HEADERS(sys/time.h unistd.h endian.h sys/param.h locale.h alloca.h)
31 +AC_CHECK_HEADERS(sys/time.h unistd.h endian.h sys/param.h locale.h alloca.h fenv.h)
33 if test "$enable_zip" != no; then
34 AC_CHECK_HEADER(zlib.h,,AC_MSG_ERROR(zlib.h is missing))
35 diff --git a/src/os/linux/i386/init.c b/src/os/linux/i386/init.c
36 index d9c6648..8fefe7d 100644
37 --- a/src/os/linux/i386/init.c
38 +++ b/src/os/linux/i386/init.c
40 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
45 +#if defined(HAVE_FENV_H)
48 #include <fpu_control.h>
51 /* Change floating point precision to double (64-bit) from
52 * the extended (80-bit) Linux default. */
54 void setDoublePrecision() {
55 +#if defined(HAVE_FENV_H)
59 + fenv.__control_word &= ~0x300; /* _FPU_EXTENDED */
60 + fenv.__control_word |= 0x200; /* _FPU_DOUBLE */
72 void initialisePlatform() {
73 diff --git a/src/os/linux/x86_64/init.c b/src/os/linux/x86_64/init.c
74 index 9d55229..b42b14e 100644
75 --- a/src/os/linux/x86_64/init.c
76 +++ b/src/os/linux/x86_64/init.c
78 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
84 +#if defined(HAVE_FENV_H)
87 #include <fpu_control.h>
93 void setDoublePrecision() {
95 +#if defined(HAVE_FENV_H)
99 + fenv.__control_word &= ~0x300; /*_FPU_EXTENDED */
100 + fenv.__control_word |= 0x200; /*_FPU_DOUBLE */