From cdd27ca9438906e8bd9d1942fecd69881ff14418 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Wed, 1 Sep 2010 12:41:16 +0000 Subject: COMMON: changed read/write endian function to use __may_alias__ attribute This is a better solution for the gcc aliasing problem that happens when aliasing a struct onto something else. What happens is that the compiler assumes no aliasing can happen when -O2 and -O3 are activated, and a call to READ_UINT32() followed by WRITE_UINT32() and another READ_UINT32() will be optimized to return the original read value instead of re-reading. svn-id: r52480 --- common/endian.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/endian.h b/common/endian.h index db47ff2d07..32f92fd02c 100644 --- a/common/endian.h +++ b/common/endian.h @@ -189,22 +189,22 @@ #elif defined(__GNUC__) && (__GNUC__ >= 4) FORCEINLINE uint16 READ_UINT16(const void *ptr) { - struct Unaligned16 { uint16 val; } __attribute__ ((__packed__)); + struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); return ((const Unaligned16 *)ptr)->val; } FORCEINLINE uint32 READ_UINT32(const void *ptr) { - struct Unaligned32 { uint32 val; } __attribute__ ((__packed__)); + struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); return ((const Unaligned32 *)ptr)->val; } FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) { - struct Unaligned16 { uint16 val; } __attribute__ ((__packed__)); + struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); ((Unaligned16 *)ptr)->val = value; } FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) { - struct Unaligned32 { uint32 val; } __attribute__ ((__packed__)); + struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); ((Unaligned32 *)ptr)->val = value; } -- cgit v1.2.3