View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
---|---|---|---|---|---|---|---|---|---|
0000211 | mercury | Bug | public | 2011-08-22 16:58 | 2011-12-09 10:26 | ||||
Reporter | wangp | ||||||||
Assigned To | wangp | ||||||||
Priority | normal | Severity | minor | Reproducibility | have not tried | ||||
Status | resolved | Resolution | fixed | ||||||
Product Version | |||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0000211: single-precision float grades broken on 64-bit | ||||||||
Description | Both LLDS (and now high-level C grades) generate structures like this for static data. struct foo { MR_Word f1; MR_Float f2; MR_Float f3; }; which is then treated as an array of MR_Word. However, if using MR_Float==float on a 64-bit platform, the C compiler will pack the two float members into a single word. Two possible solutions are: 1. use C compiler extensions to force any MR_Float members to be word-aligned 2. replace the MR_Float members by a union, e.g. union MR_Float_Word { MR_Float f; MR_Word w; }; This requires additional braces in initialiser lists. | ||||||||
Tags | No tags attached. | ||||||||
Attached Files |
|
Notes | |
juliensf (administrator) 2011-08-22 21:51 |
I don't think (1) is a solution in this context. The source distribution .c files shouldn't make assumptions about the availability or otherwise of compiler extensions. |
wangp (developer) 2011-08-23 10:31 |
This only affects single-precision grades on 64-bit platforms, which likely no one uses anyway (why would they? Maybe we should just say it's not supported, and make the compiler issue an error.) Compiler extensions only need to be invoked a rare circumstance. /* if defined(MR_USE_SINGLE_PRECISION) && sizeof(MR_Float) < sizeof(MR_Word) */ #if defined(MR_GNUC) || defined(MR_CLANG) typedef MR_Float MR_Float_Aligned __attribute__((aligned(sizeof(MR_Word)))); #elif defined(MR_MSVC) typedef _declspec(align(sizeof(MR_Word))) MR_Float MR_Float_Aligned; #else #error MR_Float_Aligned not defined #endif /* otherwise */ typedef MR_Float MR_Float_Aligned; (2) is problematic for high-level data grades. Presumably we would need to use union MR_Float_Word in structures where ever MR_Float currently is, so all field references will need an extra .f suffix. |
juliensf (administrator) 2011-08-23 13:38 |
Given that the relevant extensions are supported by gcc, clang and visual C, I don't have any objections to (1). |
wangp (developer) 2011-12-09 10:26 |
Fix committed. |
Issue History | |||
Date Modified | Username | Field | Change |
---|---|---|---|
2011-08-22 16:58 | wangp | New Issue | |
2011-08-22 21:51 | juliensf | Note Added: 0000350 | |
2011-08-23 10:31 | wangp | Note Added: 0000351 | |
2011-08-23 13:38 | juliensf | Note Added: 0000352 | |
2011-12-09 10:26 | wangp | Note Added: 0000436 | |
2011-12-09 10:26 | wangp | Status | new => resolved |
2011-12-09 10:26 | wangp | Resolution | open => fixed |
2011-12-09 10:26 | wangp | Assigned To | => wangp |