]> git.sesse.net Git - x264/commitdiff
checkasm: add memory clobber to read_time inline asm
authorJanne Grunau <janne-x264@jannau.net>
Wed, 2 Apr 2014 14:31:28 +0000 (16:31 +0200)
committerFiona Glaser <fiona@x264.com>
Tue, 26 Aug 2014 16:19:19 +0000 (09:19 -0700)
The memory acts as compiler barrier preventing aggressive reordering
of read_time calls. gcc 4.8 reorders some of initial read_time calls
after the second when targeting arm.

tools/checkasm.c

index cb889660c6e9d90f758a8971118cf7c213870d33..837fd1a121b66fceb47dc00a1c16555124740af9 100644 (file)
@@ -90,11 +90,11 @@ static inline uint32_t read_time(void)
 {
     uint32_t a = 0;
 #if HAVE_X86_INLINE_ASM
-    asm volatile( "rdtsc" :"=a"(a) ::"edx" );
+    asm volatile( "rdtsc" : "=a"(a) :: "edx", "memory" );
 #elif ARCH_PPC
-    asm volatile( "mftb %0" : "=r" (a) );
+    asm volatile( "mftb %0" : "=r"(a) :: "memory" );
 #elif ARCH_ARM     // ARMv7 only
-    asm volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(a) );
+    asm volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(a) :: "memory" );
 #endif
     return a;
 }