2024-11-21 23:40 AEDT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000211mercuryBugpublic2011-12-09 10:26
Reporterwangp 
Assigned Towangp 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000211: single-precision float grades broken on 64-bit
DescriptionBoth 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.
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0000350

juliensf (administrator)

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.

~0000351

wangp (developer)

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.

~0000352

juliensf (administrator)

Given that the relevant extensions are supported by gcc, clang and visual C, I don't have any objections
to (1).

~0000436

wangp (developer)

Fix committed.
+Notes

-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
+Issue History