From b4058a696ab507991b6b8c8cf6c0bdd9cb5c714f Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 9 May 2011 14:32:03 +0200 Subject: COMMON: Tweak some comments --- common/endian.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'common/endian.h') diff --git a/common/endian.h b/common/endian.h index e6c39d3a4c..afd7e2913e 100644 --- a/common/endian.h +++ b/common/endian.h @@ -149,8 +149,8 @@ */ #define MKTAG(a0,a1,a2,a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24))) -// Functions for reading/writing native Integers, -// this transparently handles the need for alignment +// Functions for reading/writing native integers, +// this transparently handles the need for alignment. #if !defined(SCUMM_NEED_ALIGNMENT) @@ -170,8 +170,10 @@ *(uint32 *)(ptr) = value; } -// test for GCC >= 4.0. these implementations will automatically use CPU-specific -// instructions for unaligned data when they are available (eg. MIPS) +// Test for GCC >= 4.0. These implementations will automatically use CPU-specific +// instructions for unaligned data when they are available (eg. MIPS). +// See also this email thread on scummvm-devel for details: +// #elif defined(__GNUC__) && (__GNUC__ >= 4) FORCEINLINE uint16 READ_UINT16(const void *ptr) { -- cgit v1.2.3 From 9511af6682f3a81e5956b43c1af1748c289191a8 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 10 May 2011 15:38:10 +0200 Subject: COMMON: Always prefer GCC 4.x versions of READ_UINT*/WRITE_UINT* In addition, we use them if in GCC >= 3.3 if unaligned access is possible. The GCC variants of these macros also contain protection against overzealous compilers' static aliasing optimizations. --- common/endian.h | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'common/endian.h') diff --git a/common/endian.h b/common/endian.h index afd7e2913e..c645243654 100644 --- a/common/endian.h +++ b/common/endian.h @@ -149,53 +149,57 @@ */ #define MKTAG(a0,a1,a2,a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24))) -// Functions for reading/writing native integers, -// this transparently handles the need for alignment. +// Functions for reading/writing native integers. +// They also transparently handle the need for alignment. -#if !defined(SCUMM_NEED_ALIGNMENT) +// Test for GCC >= 4.0. These implementations will automatically use +// CPU-specific instructions for unaligned data when they are available (eg. +// MIPS). See also this email thread on scummvm-devel for details: +// +// +// Moreover, we activate this code for GCC >= 3.3 but *only* if unaligned access +// is allowed. +#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 && !defined(SCUMM_NEED_ALIGNMENT))) FORCEINLINE uint16 READ_UINT16(const void *ptr) { - return *(const uint16 *)(ptr); + struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); + return ((const Unaligned16 *)ptr)->val; } FORCEINLINE uint32 READ_UINT32(const void *ptr) { - return *(const uint32 *)(ptr); + struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); + return ((const Unaligned32 *)ptr)->val; } FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) { - *(uint16 *)(ptr) = value; + struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); + ((Unaligned16 *)ptr)->val = value; } FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) { - *(uint32 *)(ptr) = value; + struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); + ((Unaligned32 *)ptr)->val = value; } -// Test for GCC >= 4.0. These implementations will automatically use CPU-specific -// instructions for unaligned data when they are available (eg. MIPS). -// See also this email thread on scummvm-devel for details: -// -#elif defined(__GNUC__) && (__GNUC__ >= 4) +#elif !defined(SCUMM_NEED_ALIGNMENT) FORCEINLINE uint16 READ_UINT16(const void *ptr) { - struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); - return ((const Unaligned16 *)ptr)->val; + return *(const uint16 *)(ptr); } FORCEINLINE uint32 READ_UINT32(const void *ptr) { - struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); - return ((const Unaligned32 *)ptr)->val; + return *(const uint32 *)(ptr); } FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) { - struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); - ((Unaligned16 *)ptr)->val = value; + *(uint16 *)(ptr) = value; } FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) { - struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); - ((Unaligned32 *)ptr)->val = value; + *(uint32 *)(ptr) = value; } + // use software fallback by loading each byte explicitely #else -- cgit v1.2.3 From 69b1485a22dc2b8a2cfe0bd10edcbaad0da0cf6e Mon Sep 17 00:00:00 2001 From: strangerke Date: Thu, 12 May 2011 01:13:57 +0200 Subject: GIT: Clean up: Suppress SVN tags, now useless --- common/endian.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'common/endian.h') diff --git a/common/endian.h b/common/endian.h index c645243654..9cb703858a 100644 --- a/common/endian.h +++ b/common/endian.h @@ -18,9 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ #ifndef COMMON_ENDIAN_H -- cgit v1.2.3