[m-rev.] for review: Conform to memory alignment requirements on doubles.

Peter Wang novalazy at gmail.com
Tue Oct 29 17:40:12 AEDT 2013


On Mon, 7 Oct 2013 15:45:49 +1100, Peter Wang <novalazy at gmail.com> wrote:
> 
> Conform to memory alignment requirements on doubles.
> 
[snip]

Committed with additional changes.

Peter

diff --git a/compiler/llds_out_data.m b/compiler/llds_out_data.m
index 76c9964..372e94b 100644
--- a/compiler/llds_out_data.m
+++ b/compiler/llds_out_data.m
@@ -982,9 +982,9 @@ output_rval(Info, Rval, !IO) :-
                 Op = float_from_dword
             ->
                 ( is_aligned_dword_ptr(SubRvalA, SubRvalB, MemRef) ->
-                    io.write_string("MR_float_from_dword_ptr(", !IO),
+                    io.write_string("MR_float_from_dword_ptr(MR_dword_ptr(", !IO),
                     output_rval(Info, mem_addr(MemRef), !IO),
-                    io.write_string(")", !IO)
+                    io.write_string("))", !IO)
                 ;
                     io.write_string("MR_float_from_dword(", !IO),
                     output_rval(Info, SubRvalA, !IO),
@@ -1354,19 +1354,16 @@ output_float_rval(Info, Rval, IsPtr, !IO) :-
 
 is_aligned_dword_ptr(lval(LvalA), lval(LvalB), MemRef) :-
     (
-        LvalA = field(MaybeTag, Address, const(llconst_int(N))),
-        LvalB = field(MaybeTag, Address, const(llconst_int(N + 1))),
-        % Only output an aligned memory reference to a double-word,
-        % i.e. fields at even word offsets from the start of the cell.
-        int.even(N),
-        MemRef = heap_ref(Address, MaybeTag, const(llconst_int(N)))
-    ;
         LvalA = stackvar(N),
         LvalB = stackvar(N + 1),
         % Double-width variables on the det stack should have been aligned
         % by the allocator. In a downwards-growing stack the higher slot
         % number has the lower address.
         MemRef = stackvar_ref(const(llconst_int(N + 1)))
+    ;
+        LvalA = field(_MaybeTag, _Address, _Offset),
+        % We cannot guarantee that the Address is dword aligned.
+        fail
     ).
 
 output_test_rval(Info, Test, !IO) :-
diff --git a/runtime/mercury_deconstruct.c b/runtime/mercury_deconstruct.c
index a3af852..df6898c 100644
--- a/runtime/mercury_deconstruct.c
+++ b/runtime/mercury_deconstruct.c
@@ -357,7 +357,7 @@ MR_arg_value_uncommon(MR_Word *arg_ptr, const MR_DuArgLocn *arg_locn)
     */
     if (arg_locn->MR_arg_bits == -1) {
 #ifdef MR_BOXED_FLOAT
-        flt = MR_float_from_dword_ptr(arg_ptr);
+        flt = MR_float_from_dword(arg_ptr[0], arg_ptr[1]);
     #ifdef MR_HIGHLEVEL_CODE
         return (MR_Word) MR_box_float(flt);
     #else
diff --git a/runtime/mercury_layout_util.c b/runtime/mercury_layout_util.c
index 4aadd55..a33de59 100644
--- a/runtime/mercury_layout_util.c
+++ b/runtime/mercury_layout_util.c
@@ -748,8 +748,9 @@ MR_lookup_long_lval_base(MR_LongLval locn, MR_Word *saved_regs,
                 printf("long double stackvar%d\n", locn_num);
             }
 #ifdef MR_BOXED_FLOAT
-            value = MR_float_to_word(MR_float_from_dword_ptr(
-                &MR_based_stackvar(base_sp, locn_num + 1)));
+            value = MR_float_to_word(MR_float_from_dword(
+                MR_based_stackvar(base_sp, locn_num + 1),
+                MR_based_stackvar(base_sp, locn_num)));
             *succeeded = MR_TRUE;
 #endif
             break;
@@ -759,8 +760,9 @@ MR_lookup_long_lval_base(MR_LongLval locn, MR_Word *saved_regs,
                 printf("long double framevar%d\n", locn_num);
             }
 #ifdef MR_BOXED_FLOAT
-            value = MR_float_to_word(MR_float_from_dword_ptr(
-                &MR_based_framevar(base_sp, locn_num + 1)));
+            value = MR_float_to_word(MR_float_from_dword(
+                MR_based_framevar(base_curfr, locn_num + 1),
+                MR_based_framevar(base_curfr, locn_num)));
             *succeeded = MR_TRUE;
 #endif
             break;




More information about the reviews mailing list