diff options
author | Mike Sperber <[email protected]> | 2012-03-22 18:00:31 +0100 |
---|---|---|
committer | Mike Sperber <[email protected]> | 2012-03-23 09:15:19 +0100 |
commit | 933e701dac1936c6f15c765b5687fbc623464ec7 (patch) | |
tree | 95bef4a51a14f512c23348e39cbfb336bc22475b /erts | |
parent | 3087769515ea9bfc75f7d7b8897bc897c7f13931 (diff) | |
download | otp-933e701dac1936c6f15c765b5687fbc623464ec7.tar.gz otp-933e701dac1936c6f15c765b5687fbc623464ec7.tar.bz2 otp-933e701dac1936c6f15c765b5687fbc623464ec7.zip |
Unbreak floating point on middle-endian machines.
On some ARMs (and maybe other platforms), doubles are stored with the
the two 32-bit words reversed with respect to more common
architectures.
The symptom is this:
> io_lib:write(1.0).
"0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005299808824"
Detect that and account for it when decoding floats.
Diffstat (limited to 'erts')
-rw-r--r-- | erts/aclocal.m4 | 63 | ||||
-rw-r--r-- | erts/configure.in | 1 | ||||
-rw-r--r-- | erts/emulator/beam/erl_bits.c | 10 |
3 files changed, 74 insertions, 0 deletions
diff --git a/erts/aclocal.m4 b/erts/aclocal.m4 index 339a15a2bb..9c5bcd6dc6 100644 --- a/erts/aclocal.m4 +++ b/erts/aclocal.m4 @@ -59,6 +59,7 @@ AC_ARG_VAR(erl_xcomp_isysroot, [Absolute cross system root include path (only us dnl Cross compilation variables AC_ARG_VAR(erl_xcomp_bigendian, [big endian system: yes|no (only used when cross compiling)]) +AC_ARG_VAR(erl_xcomp_double_middle_endian, [double-middle-endian system: yes|no (only used when cross compiling)]) AC_ARG_VAR(erl_xcomp_linux_clock_gettime_correction, [clock_gettime() can be used for time correction: yes|no (only used when cross compiling)]) AC_ARG_VAR(erl_xcomp_linux_nptl, [have Native POSIX Thread Library: yes|no (only used when cross compiling)]) AC_ARG_VAR(erl_xcomp_linux_usable_sigusrx, [SIGUSR1 and SIGUSR2 can be used: yes|no (only used when cross compiling)]) @@ -606,6 +607,60 @@ ifelse([$5], , , [$5 fi ]) +dnl ---------------------------------------------------------------------- +dnl +dnl AC_DOUBLE_MIDDLE_ENDIAN +dnl +dnl Checks whether doubles are represented in "middle-endian" format. +dnl Sets ac_cv_double_middle_endian={no,yes,unknown} accordingly, +dnl as well as DOUBLE_MIDDLE_ENDIAN. +dnl +dnl + +AC_DEFUN([AC_C_DOUBLE_MIDDLE_ENDIAN], +[AC_CACHE_CHECK(whether double word ordering is middle-endian, ac_cv_c_double_middle_endian, +[# It does not; compile a test program. +AC_RUN_IFELSE( +[AC_LANG_SOURCE([[int +main(void) +{ + int i = 0; + int zero = 0; + union + { + double d; + char c[sizeof (double)]; + } v; + v.d = 1.0; + + + while (i < sizeof(double) / 2) + { + if (v.c[i] != 0) + zero = 1; + ++i; + } + exit (zero); +} +]])], + [ac_cv_c_double_middle_endian=no], + [ac_cv_c_double_middle_endian=yes], + [ac_cv_c_double_middle=unknown])]) +case $ac_cv_c_double_middle_endian in + yes) + m4_default([$1], + [AC_DEFINE([DOUBLE_MIDDLE_ENDIAN], 1, + [Define to 1 if your processor stores the words in a double in + middle-endian format (like some ARMs).])]) ;; + no) + $2 ;; + *) + m4_default([$3], + [AC_MSG_ERROR([unknown double endianness +presetting ac_cv_c_double_middle_endian=no (or yes) will help])]) ;; +esac +])# AC_C_DOUBLE_MIDDLE_ENDIAN + dnl ---------------------------------------------------------------------- dnl @@ -1337,6 +1392,14 @@ if test "$ac_cv_c_bigendian" = "yes"; then AC_DEFINE(ETHR_BIGENDIAN, 1, [Define if bigendian]) fi +case X$erl_xcomp_double_middle_endian in + X) ;; + Xyes|Xno) ac_cv_c_double_middle_endian=$erl_xcomp_double_middle_endian;; + *) AC_MSG_ERROR([Bad erl_xcomp_double_middle_endian value: $erl_xcomp_double_middle_endian]);; +esac + +AC_C_DOUBLE_MIDDLE_ENDIAN + AC_ARG_ENABLE(native-ethr-impls, AS_HELP_STRING([--disable-native-ethr-impls], [disable native ethread implementations]), diff --git a/erts/configure.in b/erts/configure.in index b801994e14..6583db8116 100644 --- a/erts/configure.in +++ b/erts/configure.in @@ -1681,6 +1681,7 @@ case X$erl_xcomp_bigendian in esac AC_C_BIGENDIAN +AC_C_DOUBLE_MIDDLE_ENDIAN dnl fdatasync syscall (Unix only) AC_CHECK_FUNCS([fdatasync]) diff --git a/erts/emulator/beam/erl_bits.c b/erts/emulator/beam/erl_bits.c index 6f7309f493..b7c82935ff 100644 --- a/erts/emulator/beam/erl_bits.c +++ b/erts/emulator/beam/erl_bits.c @@ -1005,8 +1005,13 @@ erts_new_bs_put_float(Process *c_p, Eterm arg, Uint num_bits, int flags) if (is_float(arg)) { FloatDef *fdp = (FloatDef*)(float_val(arg) + 1); +#ifdef DOUBLE_MIDDLE_ENDIAN + a = fdp->fw[1]; + b = fdp->fw[0]; +#else a = fdp->fw[0]; b = fdp->fw[1]; +#endif } else if (is_small(arg)) { u.f64 = (double) signed_val(arg); a = u.i32[0]; @@ -1015,8 +1020,13 @@ erts_new_bs_put_float(Process *c_p, Eterm arg, Uint num_bits, int flags) if (big_to_double(arg, &u.f64) < 0) { return 0; } +#ifdef DOUBLE_MIDDLE_ENDIAN + a = u.i32[1]; + b = u.i32[0]; +#else a = u.i32[0]; b = u.i32[1]; +#endif } else { return 0; } |