[FFmpeg-devel] [PATCH] Macros to copy small, possibly unaligned, values
Jeff Downs
heydowns
Tue Jun 2 20:06:12 CEST 2009
Attached adds AV_CN* macros to provide a universal way to copy small,
possibly unaligned, constant-sized values.
This came out of the recent lcl decoder discussion on unaligned accesses
[1] -- while it may no longer be relevant there with the recent work
Reimar is doing, I figured I'd still post since I'd already written it and
it may be useful elsewhere. One potential use, replacing the AV_W/R
combination read/writes in dsputil.h's copy_block* functions.
I've no particular attachment to the macro names and am open to other
suggestions.
-Jeff
[1] https://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-May/070435.html
-------------- next part --------------
Index: libavutil/intreadwrite.h
===================================================================
--- libavutil/intreadwrite.h (revision 19076)
+++ libavutil/intreadwrite.h (working copy)
@@ -50,16 +50,19 @@
# define AV_RN(s, p) (((const struct unaligned_##s *) (p))->l)
# define AV_WN(s, p, v) (((struct unaligned_##s *) (p))->l) = (v)
+# define AV_CN(s, p, v) AV_WN(s, p, AV_RN(s, v))
#elif defined(__DECC)
# define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
# define AV_WN(s, p, v) *((__unaligned uint##s##_t*)(p)) = (v)
+# define AV_CN(s, p, v) AV_WN(s, p, AV_RN(s, v))
#elif HAVE_FAST_UNALIGNED
# define AV_RN(s, p) (*((const uint##s##_t*)(p)))
# define AV_WN(s, p, v) *((uint##s##_t*)(p)) = (v)
+# define AV_CN(s, p, v) AV_WN(s, p, AV_RN(s, v))
#else
@@ -83,6 +86,12 @@
((uint8_t*)(p))[1] = (d)>>8; } while(0)
#endif
+#ifndef AV_CN16
+#define AV_CN16(p, v) do { \
+ ((uint8_t*)(p))[0] = ((uint8_t*)(v))[0]; \
+ ((uint8_t*)(p))[1] = ((uint8_t*)(v))[1]; } while (0)
+#endif
+
#ifndef AV_RB32
#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
(((const uint8_t*)(x))[1] << 16) | \
@@ -111,6 +120,14 @@
((uint8_t*)(p))[3] = (d)>>24; } while(0)
#endif
+#ifndef AV_CN32
+#define AV_CN32(p, v) do { \
+ ((uint8_t*)(p))[0] = ((uint8_t*)(v))[0]; \
+ ((uint8_t*)(p))[1] = ((uint8_t*)(v))[1]; \
+ ((uint8_t*)(p))[2] = ((uint8_t*)(v))[2]; \
+ ((uint8_t*)(p))[3] = ((uint8_t*)(v))[3]; } while (0)
+#endif
+
#ifndef AV_RB64
#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
((uint64_t)((const uint8_t*)(x))[1] << 48) | \
@@ -155,6 +172,18 @@
((uint8_t*)(p))[7] = (d)>>56; } while(0)
#endif
+#ifndef AV_CN64
+#define AV_CN64(p, v) do { \
+ ((uint8_t*)(p))[0] = ((uint8_t*)(v))[0]; \
+ ((uint8_t*)(p))[1] = ((uint8_t*)(v))[1]; \
+ ((uint8_t*)(p))[2] = ((uint8_t*)(v))[2]; \
+ ((uint8_t*)(p))[3] = ((uint8_t*)(v))[3]; \
+ ((uint8_t*)(p))[4] = ((uint8_t*)(v))[4]; \
+ ((uint8_t*)(p))[5] = ((uint8_t*)(v))[5]; \
+ ((uint8_t*)(p))[6] = ((uint8_t*)(v))[6]; \
+ ((uint8_t*)(p))[7] = ((uint8_t*)(v))[7]; } while (0)
+#endif
+
#ifdef WORDS_BIGENDIAN
# define AV_RN(s, p) AV_RB##s(p)
# define AV_WN(s, p, v) AV_WB##s(p, v)
@@ -163,6 +192,8 @@
# define AV_WN(s, p, v) AV_WL##s(p, v)
#endif
+#define AV_CN(s, p, v) AV_CN##s(p, v)
+
#endif /* HAVE_FAST_UNALIGNED */
#ifndef AV_RN16
@@ -189,6 +220,18 @@
# define AV_WN64(p, v) AV_WN(64, p, v)
#endif
+#ifndef AV_CN16
+# define AV_CN16(p, v) AV_CN(16, p, v)
+#endif
+
+#ifndef AV_CN32
+# define AV_CN32(p, v) AV_CN(32, p, v)
+#endif
+
+#ifndef AV_CN64
+# define AV_CN64(p, v) AV_CN(64, p, v)
+#endif
+
#ifdef WORDS_BIGENDIAN
# define AV_RB(s, p) AV_RN(s, p)
# define AV_WB(s, p, v) AV_WN(s, p, v)
More information about the ffmpeg-devel
mailing list