[x264-devel] checkasm: add memory clobber to read_time inline asm

Janne Grunau git at videolan.org
Tue Aug 26 18:23:10 CEST 2014


x264 | branch: master | Janne Grunau <janne-x264 at jannau.net> | Wed Apr  2 16:31:28 2014 +0200| [c2df1fc65c98e213c444134d5dbbb79d439af4db] | committer: Fiona Glaser

checkasm: add memory clobber to read_time inline asm

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.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=c2df1fc65c98e213c444134d5dbbb79d439af4db
---

 tools/checkasm.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/checkasm.c b/tools/checkasm.c
index cb88966..837fd1a 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;
 }



More information about the x264-devel mailing list