board/csky: fixup gdb instructions in readme.txt
[buildroot-gz.git] / package / jamvm / 0001-Use-fenv.h-when-available-instead-of-fpu_control.h.patch
blob78ee9b7e1848d59f656d7d84c5653d7b3ad51e85
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>
16 ---
17 configure.ac | 2 +-
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
24 --- a/configure.ac
25 +++ b/configure.ac
26 @@ -279,7 +279,7 @@ fi
28 dnl Checks for header files.
29 AC_HEADER_STDC
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
39 @@ -19,18 +19,33 @@
40 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
43 +#include "config.h"
45 +#if defined(HAVE_FENV_H)
46 +#include <fenv.h>
47 +#else
48 #include <fpu_control.h>
49 +#endif
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)
56 + fenv_t fenv;
58 + fegetenv(&fenv);
59 + fenv.__control_word &= ~0x300; /* _FPU_EXTENDED */
60 + fenv.__control_word |= 0x200; /* _FPU_DOUBLE */
61 + fesetenv(&fenv);
62 +#else
63 fpu_control_t cw;
65 _FPU_GETCW(cw);
66 cw &= ~_FPU_EXTENDED;
67 cw |= _FPU_DOUBLE;
68 _FPU_SETCW(cw);
69 +#endif
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
77 @@ -19,7 +19,11 @@
78 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
81 -#ifdef __linux__
82 +#include "config.h"
84 +#if defined(HAVE_FENV_H)
85 +#include <fenv.h>
86 +#else
87 #include <fpu_control.h>
88 #endif
90 @@ -30,7 +34,14 @@
93 void setDoublePrecision() {
94 -#ifdef __linux__
95 +#if defined(HAVE_FENV_H)
96 + fenv_t fenv;
98 + fegetenv(&fenv);
99 + fenv.__control_word &= ~0x300; /*_FPU_EXTENDED */
100 + fenv.__control_word |= 0x200; /*_FPU_DOUBLE */
101 + fesetenv(&fenv);
102 +#else
103 fpu_control_t cw;
105 _FPU_GETCW(cw);
107 2.7.4