aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYotam Barnoy2010-09-01 12:41:16 +0000
committerYotam Barnoy2010-09-01 12:41:16 +0000
commitcdd27ca9438906e8bd9d1942fecd69881ff14418 (patch)
tree334240ee9f7e39d60171ec90bac47a4f21b99355
parent81eb3cfba157b3c45095734d5e9177a199d0c351 (diff)
downloadscummvm-rg350-cdd27ca9438906e8bd9d1942fecd69881ff14418.tar.gz
scummvm-rg350-cdd27ca9438906e8bd9d1942fecd69881ff14418.tar.bz2
scummvm-rg350-cdd27ca9438906e8bd9d1942fecd69881ff14418.zip
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
-rw-r--r--common/endian.h8
1 files changed, 4 insertions, 4 deletions
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;
}