utils: faster GST_WRITE_* macros if unaligned access is possible

https://bugzilla.gnome.org/show_bug.cgi?id=599546
This commit is contained in:
Tim-Philipp Müller 2016-11-12 12:36:05 +00:00
parent 89b413ef15
commit cc5af6273f

View file

@ -135,6 +135,27 @@ static inline guint64 __gst_fast_read_swap64(const guint8 *v) {
}
# define _GST_FAST_READ(s, d) __gst_fast_read##s((const guint8 *)(d))
# define _GST_FAST_READ_SWAP(s, d) __gst_fast_read_swap##s((const guint8 *)(d))
static inline void __gst_fast_write16 (guint8 *p, guint16 v) {
*(guint16*)(void*)(p) = v;
}
static inline void __gst_fast_write32 (guint8 *p, guint32 v) {
*(guint32*)(void*)(p) = v;
}
static inline void __gst_fast_write64 (guint8 *p, guint64 v) {
*(guint64*)(void*)(p) = v;
}
static inline void __gst_fast_write_swap16 (guint8 *p, guint16 v) {
*(guint16*)(void*)(p) = GUINT16_SWAP_LE_BE (v);
}
static inline void __gst_fast_write_swap32 (guint8 *p, guint32 v) {
*(guint32*)(void*)(p) = GUINT32_SWAP_LE_BE (v);
}
static inline void __gst_fast_write_swap64 (guint8 *p, guint64 v) {
*(guint64*)(void*)(p) = GUINT64_SWAP_LE_BE (v);
}
# define _GST_FAST_WRITE(s, d, v) __gst_fast_write##s((guint8 *)(d), (v))
# define _GST_FAST_WRITE_SWAP(s, d, v) __gst_fast_write_swap##s((guint8 *)(d), (v))
#endif
#endif
@ -313,6 +334,22 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
*
* Store a 64 bit unsigned integer value in big endian format into the memory buffer.
*/
/**
* GST_WRITE_UINT64_LE:
* @data: memory location
* @num: value to store
*
* Store a 64 bit unsigned integer value in little endian format into the memory buffer.
*/
#if GST_HAVE_UNALIGNED_ACCESS
# if (G_BYTE_ORDER == G_BIG_ENDIAN)
# define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE(64,data,val)
# define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
# else
# define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
# define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE(64,data,val)
# endif
#else
#define GST_WRITE_UINT64_BE(data, num) do { \
gpointer __put_data = data; \
_GST_PUT (__put_data, 0, 64, 56, num); \
@ -325,13 +362,6 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
_GST_PUT (__put_data, 7, 64, 0, num); \
} while (0)
/**
* GST_WRITE_UINT64_LE:
* @data: memory location
* @num: value to store
*
* Store a 64 bit unsigned integer value in little endian format into the memory buffer.
*/
#define GST_WRITE_UINT64_LE(data, num) do { \
gpointer __put_data = data; \
_GST_PUT (__put_data, 0, 64, 0, num); \
@ -343,6 +373,7 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
_GST_PUT (__put_data, 6, 64, 48, num); \
_GST_PUT (__put_data, 7, 64, 56, num); \
} while (0)
#endif /* !GST_HAVE_UNALIGNED_ACCESS */
/**
* GST_WRITE_UINT32_BE:
@ -351,6 +382,22 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
*
* Store a 32 bit unsigned integer value in big endian format into the memory buffer.
*/
/**
* GST_WRITE_UINT32_LE:
* @data: memory location
* @num: value to store
*
* Store a 32 bit unsigned integer value in little endian format into the memory buffer.
*/
#if GST_HAVE_UNALIGNED_ACCESS
# if (G_BYTE_ORDER == G_BIG_ENDIAN)
# define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE(32,data,val)
# define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
# else
# define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
# define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE(32,data,val)
# endif
#else
#define GST_WRITE_UINT32_BE(data, num) do { \
gpointer __put_data = data; \
_GST_PUT (__put_data, 0, 32, 24, num); \
@ -359,13 +406,6 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
_GST_PUT (__put_data, 3, 32, 0, num); \
} while (0)
/**
* GST_WRITE_UINT32_LE:
* @data: memory location
* @num: value to store
*
* Store a 32 bit unsigned integer value in little endian format into the memory buffer.
*/
#define GST_WRITE_UINT32_LE(data, num) do { \
gpointer __put_data = data; \
_GST_PUT (__put_data, 0, 32, 0, num); \
@ -373,6 +413,7 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
_GST_PUT (__put_data, 2, 32, 16, num); \
_GST_PUT (__put_data, 3, 32, 24, num); \
} while (0)
#endif /* !GST_HAVE_UNALIGNED_ACCESS */
/**
* GST_WRITE_UINT24_BE:
@ -409,12 +450,6 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
*
* Store a 16 bit unsigned integer value in big endian format into the memory buffer.
*/
#define GST_WRITE_UINT16_BE(data, num) do { \
gpointer __put_data = data; \
_GST_PUT (__put_data, 0, 16, 8, num); \
_GST_PUT (__put_data, 1, 16, 0, num); \
} while (0)
/**
* GST_WRITE_UINT16_LE:
* @data: memory location
@ -422,11 +457,27 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) {
*
* Store a 16 bit unsigned integer value in little endian format into the memory buffer.
*/
#if GST_HAVE_UNALIGNED_ACCESS
# if (G_BYTE_ORDER == G_BIG_ENDIAN)
# define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE(16,data,val)
# define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
# else
# define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
# define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE(16,data,val)
# endif
#else
#define GST_WRITE_UINT16_BE(data, num) do { \
gpointer __put_data = data; \
_GST_PUT (__put_data, 0, 16, 8, num); \
_GST_PUT (__put_data, 1, 16, 0, num); \
} while (0)
#define GST_WRITE_UINT16_LE(data, num) do { \
gpointer __put_data = data; \
_GST_PUT (__put_data, 0, 16, 0, num); \
_GST_PUT (__put_data, 1, 16, 8, num); \
} while (0)
#endif /* !GST_HAVE_UNALIGNED_ACCESS */
/**
* GST_WRITE_UINT8: