Browse code

Add alias-safe aligned AV_[RW]N macros

Originally committed as revision 21880 to svn://svn.ffmpeg.org/ffmpeg/trunk

Måns Rullgård authored on 2010/02/18 22:44:38
Showing 1 changed files
... ...
@@ -422,6 +422,38 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
422 422
     } while(0)
423 423
 #endif
424 424
 
425
+/*
426
+ * The AV_[RW]NA macros access naturally aligned data
427
+ * in a type-safe way.
428
+ */
429
+
430
+#define AV_RNA(s, p)    (((const av_alias##s*)(p))->u##s)
431
+#define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
432
+
433
+#ifndef AV_RN16A
434
+#   define AV_RN16A(p) AV_RNA(16, p)
435
+#endif
436
+
437
+#ifndef AV_RN32A
438
+#   define AV_RN32A(p) AV_RNA(32, p)
439
+#endif
440
+
441
+#ifndef AV_RN64A
442
+#   define AV_RN64A(p) AV_RNA(64, p)
443
+#endif
444
+
445
+#ifndef AV_WN16A
446
+#   define AV_WN16A(p, v) AV_WNA(16, p, v)
447
+#endif
448
+
449
+#ifndef AV_WN32A
450
+#   define AV_WN32A(p, v) AV_WNA(32, p, v)
451
+#endif
452
+
453
+#ifndef AV_WN64A
454
+#   define AV_WN64A(p, v) AV_WNA(64, p, v)
455
+#endif
456
+
425 457
 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
426 458
  * naturally aligned. They may be implemented using MMX,
427 459
  * so emms_c() must be called before using any float code