Lose the 'packed' attribute for types declared in build.h.

Most of them are already aligned to their natural boundaries, so lowering
the alignment to 1 byte can only worsen things by making the C compiler
generate poorer (unaligned access) code for some platforms.

The layout of structures is not specified by the C Standard, but is rather
given by a particular platform + toolchain's ABI (application binary interface).
Most ABIs follow the expected pattern "alignment of scalars is their size,
alignment of arrays is that of its element type, alignment of structs is the
maximum alignment of its members". A couple of links to particular ABIs are
given in build.h.

Problems are expected with archs that care about unaligned access when a pointer
to a non-packed struct is taken that resides in a packed aggregate, but these
uses should be weeded out (I'm not sure if there are any in our codebase).

The following types are affected, only hitdata_t changes its size:
sectortype, walltype, spritetype, spriteext_t, spritesmooth_t,
struct validmode_t, picanm_t, palette_t, vec2_t, vec3_t, hitdata_t.

git-svn-id: https://svn.eduke32.com/eduke32@3455 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-02-03 12:48:11 +00:00
parent d5c62b7de3
commit 4e5cdba646
3 changed files with 16 additions and 4 deletions

View file

@ -211,7 +211,20 @@ static inline void sprite_tracker_hook(uintptr_t address);
#endif // __cplusplus
#pragma pack(push,1)
// Links to various ABIs specifying (or documenting non-normatively) the
// alignment requirements of aggregates:
//
// System V AMD64: http://www.x86-64.org/documentation/abi-0.99.pdf
// (x86-64.org down as of 2013-02-02?)
// "An array uses the same alignment as its elements, except that a local or global
// array variable of length at least 16 bytes or a C99 variable-length array variable
// always has alignment of at least 16 bytes."
// (Not reproducible with GCC or LuaJIT on Ubuntu)
//
// Win64: http://msdn.microsoft.com/en-us/library/9dbwhz68.aspx
//
// x86: http://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86
//ceilingstat/floorstat:
// bit 0: 1 = parallaxing, 0 = not "P"
@ -319,6 +332,7 @@ typedef struct {
uint8_t xpanning, ypanning;
uint8_t filler;
float alpha;
// NOTE: keep 'tspr' on an 8-byte boundary:
spritetype *tspr;
#if !defined UINTPTR_MAX
# error Need UINTPTR_MAX define to select between 32- and 64-bit structs
@ -702,7 +716,6 @@ typedef struct {
int16_t sprite, wall, sect;
} hitdata_t;
#pragma pack(pop)
int32_t preinitengine(void); // a partial setup of the engine used for launch windows
int32_t initengine(void);

View file

@ -101,7 +101,6 @@ end
-- TODO: provide getters for unsigned {hi,lo}tag?
ffi.cdef([[
#pragma pack(push,1)
typedef $ sectortype;
typedef $ walltype;
typedef $ spritetype;
@ -131,7 +130,6 @@ typedef struct {
vec3_t pos;
int16_t sprite, wall, sect;
} hitdata_t;
#pragma pack(pop)
]],
ffi.typeof(SECTOR_STRUCT), ffi.typeof(WALL_STRUCT),
ffi.typeof(SPRITE_STRUCT), ffi.typeof(SPRITE_STRUCT))

View file

@ -220,6 +220,7 @@ typedef struct {
uint8_t palette;
palette_t pals;
// UNUSED
char name[32];
#ifdef LUNATIC