Mercury Bugs - mercury
View Issue Details
0000299mercuryBugpublic2013-09-16 16:092013-10-29 17:33
Reporterwangp 
Assigned Towangp 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000299: unaligned memory access for unboxed doubles
DescriptionUnaligned memory access instructions occur on 32-bit architectures when an unboxed double begins on an odd-numbered slot, crashing on some architectures (e.g. SPARC).

I think we can "just" split the dword read/write into two instructions for odd-numbered slots.
TagsNo tags attached.
Attached Files? unaligned.m (1,323) 2013-09-16 16:36
https://bugs.mercurylang.org/file_download.php?file_id=182&type=bug

Notes
(0000566)
wangp   
2013-09-17 17:53   
We also have to prevent unaligned doubles on the stack, by allocating aligned stack slots and ensuring the stack pointer is always aligned. Alternatively, split up all reads/writes to double-width stack slots into two instructions.
(0000567)
wangp   
2013-09-18 14:38   
The nondet stack is complicated by multiple frame types (ordinary, temporary det, temporary nondet). Ordinary frames have 5 fixed slots + temporaries (except for mm grades, with 6 fixed slots). Temporary det frames are exactly 4 words big. Temporary nondet frames are exactly 3 words big. The size is used to recognise the different types.

Maintaining an invariant that the frame pointer rests on an aligned address (so that we can always allocate aligned double slots) would be tricky and probably not worthwhile.
(0000572)
pbone   
2013-10-03 15:11   
I would like to see these values aligned on the stack in all cases. However since this will be tricky a short term work around, such as using two read instructions for 64bit values on 32 bit platforms, would be okay.
(0000573)
wangp   
2013-10-29 17:33   
Fixed in 1094f42

Issue History
2013-09-16 16:09wangpNew Issue
2013-09-16 16:36wangpFile Added: unaligned.m
2013-09-17 17:53wangpNote Added: 0000566
2013-09-18 14:38wangpNote Added: 0000567
2013-10-03 15:11pboneNote Added: 0000572
2013-10-29 17:33wangpNote Added: 0000573
2013-10-29 17:33wangpStatusnew => resolved
2013-10-29 17:33wangpResolutionopen => fixed
2013-10-29 17:33wangpAssigned To => wangp