[Scummvm-cvs-logs] SF.net SVN: scummvm:[52480] scummvm/trunk/common/endian.h
Bluddy at users.sourceforge.net
Bluddy at users.sourceforge.net
Wed Sep 1 14:41:16 CEST 2010
Revision: 52480
http://scummvm.svn.sourceforge.net/scummvm/?rev=52480&view=rev
Author: Bluddy
Date: 2010-09-01 12:41:16 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
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.
Modified Paths:
--------------
scummvm/trunk/common/endian.h
Modified: scummvm/trunk/common/endian.h
===================================================================
--- scummvm/trunk/common/endian.h 2010-09-01 09:48:00 UTC (rev 52479)
+++ scummvm/trunk/common/endian.h 2010-09-01 12:41:16 UTC (rev 52480)
@@ -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;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list