]> git.sesse.net Git - ffmpeg/commitdiff
intreadwrite: Use the __unaligned keyword on MSVC for ARM and x86_64
authorMartin Storsjö <martin@martin.st>
Mon, 1 Aug 2016 07:04:42 +0000 (10:04 +0300)
committerMartin Storsjö <martin@martin.st>
Tue, 2 Aug 2016 08:33:23 +0000 (11:33 +0300)
AV_WN64 is meant for unaligned data, but the existing av_alias* unions
(without a definition for the av_alias attribute - we don't have one
for MSVC) indicate to the compiler that they would have sufficient
alignment for normal access, i.e. the compiler is free to assume
8 byte alignment.

On ARM, this makes sure that AV_WN64 (or two consecutive AV_WN32) is
done with two str instructions instead of one strd.

Signed-off-by: Martin Storsjö <martin@martin.st>
libavutil/intreadwrite.h

index 5f65957ce5f3b1125ca26e1d28386a5218b0905f..32747b21cba0123bd078d79724f6d0dc63606e42 100644 (file)
@@ -197,6 +197,11 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
 #   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
 #   define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
 
+#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_X64)) && AV_HAVE_FAST_UNALIGNED
+
+#   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
+#   define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
+
 #elif AV_HAVE_FAST_UNALIGNED
 
 #   define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)