Commit ddbac0c6 authored by Alexander Strange's avatar Alexander Strange Committed by Fiona Glaser

Use __attribute__((may_alias)) for type-punning

GCC thinks pointer casts to unions aren't valid with strict aliasing.
See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Optimize-Options.html#Type_002dpunning.
Also use M32() in y4m.c.
Enable -Wstrict-aliasing again since all such warnings are fixed.
parent 69163c3b
......@@ -79,13 +79,13 @@ do {\
#include <assert.h>
#include <limits.h>
/* Unions for type-punning without aliasing violations.
/* Unions for type-punning.
* Mn: load or store n bits, aligned, native-endian
* CPn: copy n bits, aligned, native-endian
* we don't use memcpy for CPn because memcpy's args aren't assumed to be aligned */
typedef union { uint16_t i; uint8_t c[2]; } x264_union16_t;
typedef union { uint32_t i; uint16_t b[2]; uint8_t c[4]; } x264_union32_t;
typedef union { uint64_t i; uint32_t a[2]; uint16_t b[4]; uint8_t c[8]; } x264_union64_t;
typedef union { uint16_t i; uint8_t c[2]; } MAY_ALIAS x264_union16_t;
typedef union { uint32_t i; uint16_t b[2]; uint8_t c[4]; } MAY_ALIAS x264_union32_t;
typedef union { uint64_t i; uint32_t a[2]; uint16_t b[4]; uint8_t c[8]; } MAY_ALIAS x264_union64_t;
#define M16(src) (((x264_union16_t*)(src))->i)
#define M32(src) (((x264_union32_t*)(src))->i)
#define M64(src) (((x264_union64_t*)(src))->i)
......
......@@ -69,11 +69,13 @@
#define UNUSED __attribute__((unused))
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#define NOINLINE __attribute__((noinline))
#define MAY_ALIAS __attribute__((may_alias))
#define x264_constant_p(x) __builtin_constant_p(x)
#else
#define UNUSED
#define ALWAYS_INLINE inline
#define NOINLINE
#define MAY_ALIAS
#define x264_constant_p(x) 0
#endif
......
......@@ -61,7 +61,7 @@ pic="no"
vis="no"
shared="no"
CFLAGS="$CFLAGS -Wall -I. -Wno-strict-aliasing"
CFLAGS="$CFLAGS -Wall -I."
LDFLAGS="$LDFLAGS"
ASFLAGS="$ASFLAGS"
HAVE_GETOPT_LONG=1
......
......@@ -188,7 +188,7 @@ static int read_frame_internal( x264_picture_t *p_pic, y4m_hnd_t *h )
if( strncmp( header, Y4M_FRAME_MAGIC, slen ) )
{
fprintf( stderr, "Bad header magic (%"PRIx32" <=> %s)\n",
*((uint32_t*)header), header );
M32(header), header );
return -1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment