001-Use-fenv.h-instead-of-fpu_control.h.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. musl libc (http://musl-libc.org lack the non-standard <fpu_control.h>
  6. header, which is used in src/os/linux/{i386,x86_64}/init.c files to
  7. setup the floating point precision. This patch makes it use the
  8. standard C <fenv.h> header instead.
  9. Original patch at Felix Janda at
  10. https://sourceforge.net/p/jamvm/patches/6/.
  11. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  12. ---
  13. src/os/linux/i386/init.c | 12 ++++++------
  14. src/os/linux/x86_64/init.c | 16 ++++++----------
  15. 2 files changed, 12 insertions(+), 16 deletions(-)
  16. diff --git a/src/os/linux/i386/init.c b/src/os/linux/i386/init.c
  17. index d9c6648..94a733e 100644
  18. --- a/src/os/linux/i386/init.c
  19. +++ b/src/os/linux/i386/init.c
  20. @@ -19,18 +19,18 @@
  21. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. */
  23. -#include <fpu_control.h>
  24. +#include <fenv.h>
  25. /* Change floating point precision to double (64-bit) from
  26. * the extended (80-bit) Linux default. */
  27. void setDoublePrecision() {
  28. - fpu_control_t cw;
  29. + fenv_t fenv;
  30. - _FPU_GETCW(cw);
  31. - cw &= ~_FPU_EXTENDED;
  32. - cw |= _FPU_DOUBLE;
  33. - _FPU_SETCW(cw);
  34. + fegetenv(&fenv);
  35. + fenv.__control_word &= ~0x300; /* _FPU_EXTENDED */
  36. + fenv.__control_word |= 0x200; /* _FPU_DOUBLE */
  37. + fesetenv(&fenv);
  38. }
  39. void initialisePlatform() {
  40. diff --git a/src/os/linux/x86_64/init.c b/src/os/linux/x86_64/init.c
  41. index 9d55229..a76a923 100644
  42. --- a/src/os/linux/x86_64/init.c
  43. +++ b/src/os/linux/x86_64/init.c
  44. @@ -19,9 +19,7 @@
  45. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  46. */
  47. -#ifdef __linux__
  48. -#include <fpu_control.h>
  49. -#endif
  50. +#include <fenv.h>
  51. /* Change the x87 FPU precision to double (64-bit) from the extended
  52. (80-bit) Linux default. Note, unlike on i386, my testcases pass
  53. @@ -30,14 +28,12 @@
  54. */
  55. void setDoublePrecision() {
  56. -#ifdef __linux__
  57. - fpu_control_t cw;
  58. + fenv_t fenv;
  59. - _FPU_GETCW(cw);
  60. - cw &= ~_FPU_EXTENDED;
  61. - cw |= _FPU_DOUBLE;
  62. - _FPU_SETCW(cw);
  63. -#endif
  64. + fegetenv(&fenv);
  65. + fenv.__control_word &= ~0x300; /*_FPU_EXTENDED */
  66. + fenv.__control_word |= 0x200; /*_FPU_DOUBLE */
  67. + fesetenv(&fenv);
  68. }
  69. void initialisePlatform() {
  70. --
  71. 2.7.4