50f95cde57d5f5ae97e4ed7cc8803385773279fb
[feed/packages.git] / lang / jamvm / patches / 001-Use-fenv.h-instead-of-fpu_control.h.patch
1 From 7152ded5219453c9ff1cd062cecbeaf4d77e4cab 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> instead of <fpu_control.h>
5
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.
10
11 Original patch at Felix Janda at
12 https://sourceforge.net/p/jamvm/patches/6/.
13
14 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
15 ---
16 src/os/linux/i386/init.c | 12 ++++++------
17 src/os/linux/x86_64/init.c | 16 ++++++----------
18 2 files changed, 12 insertions(+), 16 deletions(-)
19
20 diff --git a/src/os/linux/i386/init.c b/src/os/linux/i386/init.c
21 index d9c6648..94a733e 100644
22 --- a/src/os/linux/i386/init.c
23 +++ b/src/os/linux/i386/init.c
24 @@ -19,18 +19,18 @@
25 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27
28 -#include <fpu_control.h>
29 +#include <fenv.h>
30
31 /* Change floating point precision to double (64-bit) from
32 * the extended (80-bit) Linux default. */
33
34 void setDoublePrecision() {
35 - fpu_control_t cw;
36 + fenv_t fenv;
37
38 - _FPU_GETCW(cw);
39 - cw &= ~_FPU_EXTENDED;
40 - cw |= _FPU_DOUBLE;
41 - _FPU_SETCW(cw);
42 + fegetenv(&fenv);
43 + fenv.__control_word &= ~0x300; /* _FPU_EXTENDED */
44 + fenv.__control_word |= 0x200; /* _FPU_DOUBLE */
45 + fesetenv(&fenv);
46 }
47
48 void initialisePlatform() {
49 diff --git a/src/os/linux/x86_64/init.c b/src/os/linux/x86_64/init.c
50 index 9d55229..a76a923 100644
51 --- a/src/os/linux/x86_64/init.c
52 +++ b/src/os/linux/x86_64/init.c
53 @@ -19,9 +19,7 @@
54 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
55 */
56
57 -#ifdef __linux__
58 -#include <fpu_control.h>
59 -#endif
60 +#include <fenv.h>
61
62 /* Change the x87 FPU precision to double (64-bit) from the extended
63 (80-bit) Linux default. Note, unlike on i386, my testcases pass
64 @@ -30,14 +28,12 @@
65 */
66
67 void setDoublePrecision() {
68 -#ifdef __linux__
69 - fpu_control_t cw;
70 + fenv_t fenv;
71
72 - _FPU_GETCW(cw);
73 - cw &= ~_FPU_EXTENDED;
74 - cw |= _FPU_DOUBLE;
75 - _FPU_SETCW(cw);
76 -#endif
77 + fegetenv(&fenv);
78 + fenv.__control_word &= ~0x300; /*_FPU_EXTENDED */
79 + fenv.__control_word |= 0x200; /*_FPU_DOUBLE */
80 + fesetenv(&fenv);
81 }
82
83 void initialisePlatform() {
84 --
85 2.7.4
86