[x264-devel] checkasm: Use 64-bit cycle counters

Henrik Gramner git at videolan.org
Mon May 20 23:06:46 CEST 2013


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Sat May  4 16:21:32 2013 +0200| [c3b166a6cf55afaeea5bbc94ebb275b92efbd3d8] | committer: Jason Garrett-Glaser

checkasm: Use 64-bit cycle counters

Prevents overflows that can occur in some cases.

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

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

diff --git a/tools/checkasm.c b/tools/checkasm.c
index 4aaa445..ba363ef 100644
--- a/tools/checkasm.c
+++ b/tools/checkasm.c
@@ -61,7 +61,7 @@ typedef struct
 {
     void *pointer; // just for detecting duplicates
     uint32_t cpu;
-    uint32_t cycles;
+    uint64_t cycles;
     uint32_t den;
 } bench_t;
 
@@ -137,12 +137,12 @@ static int cmp_bench( const void *a, const void *b )
 
 static void print_bench(void)
 {
-    uint16_t nops[10000] = {0};
+    uint16_t nops[10000];
     int nfuncs, nop_time=0;
 
     for( int i = 0; i < 10000; i++ )
     {
-        int t = read_time();
+        uint32_t t = read_time();
         nops[i] = read_time() - t;
     }
     qsort( nops, 10000, sizeof(uint16_t), cmp_nop );
@@ -241,7 +241,7 @@ void x264_checkasm_stack_clobber( uint64_t clobber, ... );
 #define call_bench(func,cpu,...)\
     if( do_bench && !strncmp(func_name, bench_pattern, bench_pattern_len) )\
     {\
-        uint32_t tsum = 0;\
+        uint64_t tsum = 0;\
         int tcount = 0;\
         call_a1(func, __VA_ARGS__);\
         for( int ti = 0; ti < (cpu?BENCH_RUNS:BENCH_RUNS/4); ti++ )\
@@ -252,7 +252,7 @@ void x264_checkasm_stack_clobber( uint64_t clobber, ... );
             func(__VA_ARGS__);\
             func(__VA_ARGS__);\
             t = read_time() - t;\
-            if( t*tcount <= tsum*4 && ti > 0 )\
+            if( (uint64_t)t*tcount <= tsum*4 && ti > 0 )\
             {\
                 tsum += t;\
                 tcount++;\



More information about the x264-devel mailing list