[x264-devel] [PATCH 6/8] checkasm: add memory clobber to read_time inline asm

Janne Grunau janne-x264 at jannau.net
Sun Jul 20 18:48:30 CEST 2014


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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/checkasm.c b/tools/checkasm.c
index cb88966..cd4d21a 100644
--- a/tools/checkasm.c
+++ b/tools/checkasm.c
@@ -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;
 }
-- 
2.0.1



More information about the x264-devel mailing list