Fix bele.h to use strict PODs. This should fix build problems reported on ARM.

committer: mfx <mfx> 1098709362 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2004-10-25 13:02:42 +00:00
parent 079b808a56
commit 8fcf2bcd59
3 changed files with 34 additions and 74 deletions

View File

@ -28,8 +28,8 @@ CXXFLAGS = $(call __mkflags,CXXFLAGS_W) $(call __mkflags,CXXFLAGS_M) $(call __m
##CFLAGS_WERROR = -Werror
CFLAGS_WERROR =
CFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wbad-function-cast -Wcast-align -Wcast-qual -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wwrite-strings
CXXFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wcast-align -Wcast-qual -Winline -Woverloaded-virtual -Wpointer-arith -Wshadow -Wsign-promo -Wsynth -Wwrite-strings
CFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wbad-function-cast -Wcast-align -Wcast-qual -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wwrite-strings
CXXFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wcast-align -Wcast-qual -Winline -Woverloaded-virtual -Wpointer-arith -Wshadow -Wsign-promo -Wwrite-strings
##CFLAGS_M += -fno-builtin
##CFLAGS_M += -malign-functions=0 -malign-jumps=0 -malign-loops=0

View File

@ -214,106 +214,66 @@ inline int get_le32_signed(const void *bb)
/*************************************************************************
// classes for portable unaligned access
//
// Important: these classes must be PODs (Plain Old Data), i.e. no
// constructor, no destructor, no virtual functions and no default
// assignment operator, and all fields must be public(!).
**************************************************************************/
class BE16
struct BE16
{
unsigned char d[2];
public:
BE16() { }
BE16& operator = (const BE16 &v) {
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
* (acc_uint32e_t *) d = * (const acc_uint32e_t *) v.d;
#else
memcpy(d, v.d, sizeof(d));
#endif
return *this;
}
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; }
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; }
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
operator unsigned () const { return get_be16(d); }
}
__attribute_packed;
class BE32
struct BE32
{
unsigned char d[4];
public:
BE32() { }
BE32& operator = (const BE32 &v) {
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
* (unsigned int *) d = * (const unsigned int *) v.d;
#else
memcpy(d, v.d, sizeof(d));
#endif
return *this;
}
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; }
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; }
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
operator unsigned () const { return get_be32(d); }
}
__attribute_packed;
class LE16
struct LE16
{
unsigned char d[2];
public:
LE16() { }
LE16& operator = (const LE16 &v) {
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
* (unsigned short *) d = * (const unsigned short *) v.d;
#else
memcpy(d, v.d, sizeof(d));
#endif
return *this;
}
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; }
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; }
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
operator unsigned () const { return get_le16(d); }
}
__attribute_packed;
class LE32
struct LE32
{
unsigned char d[4];
public:
LE32() { }
LE32& operator = (const LE32 &v) {
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
* (acc_uint32e_t *) d = * (const acc_uint32e_t *) v.d;
#else
memcpy(d, v.d, sizeof(d));
#endif
return *this;
}
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; }
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; }
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
operator unsigned () const { return get_le32(d); }
}
@ -386,7 +346,7 @@ int __acc_cdecl_qsort le32_compare_signed(const void *e1, const void *e2);
// just for testing...
#if 1 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_GNUC >= 0x030200)
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_GNUC >= 0x030200)
typedef unsigned short LE16_unaligned __attribute__((__aligned__(1)));
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
# define LE16 LE16_unaligned

View File

@ -294,7 +294,7 @@
#undef __attribute_packed
#if (ACC_CC_GNUC || ACC_CC_INTELC)
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
# if (1 && (ACC_ARCH_IA32))
# define __attribute_packed
# else
@ -323,12 +323,12 @@
#if 1
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z[7]; }; \
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z[7]; } __attribute_packed; \
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
}
#else
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
struct acc_tmp_t { b x; a y; b z[7]; }; \
struct acc_tmp_t { b x; a y; b z[7]; } __attribute_packed; \
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
}
#endif