Paste Code
Paste Blends
Paste Images
diff --git a/Makefile b/Makefile
index 3fe0615..c922db4 100644
--- a/Makefile
+++ b/Makefile
@@ -3,10 +3,11 @@
#
.SUFFIXES: .cpp .o .c .h
ifeq ($(DEBUG),1)
-CFLAGS = -fPIC -std=c99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined -fno-omit-frame-pointer -fsanitize=address
+CFLAGS = -fPIC -std=gnu99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined -fno-omit-frame-pointer -fsanitize=address
else
-CFLAGS = -fPIC -std=c99 -O3 -march=native -Wall -Wextra -Wshadow
+CFLAGS = -fPIC -std=gnu99 -O3 -march=native -Wall -Wextra -Wshadow
endif # debug
+LDLIBS=-lrt
all: despacebenchmark
HEADERS=./include/despacer.h ./include/despacer_tables.h

diff --git a/benchmarks/despacebenchmark.c b/benchmarks/despacebenchmark.c
index 510b8a3..607b3b9 100644
--- a/benchmarks/despacebenchmark.c
+++ b/benchmarks/despacebenchmark.c
@@ -5,6 +5,8 @@
#include <string.h>
#include "despacer.h"

+#include <time.h>
+
#define RDTSC_START(cycles)
do {
register unsigned cyc_high, cyc_low;
@@ -35,6 +37,8 @@
fflush(NULL);
uint64_t tm1, tm2;
uint64_t min_diff = (uint64_t)-1;
+ struct timespec start_time, end_time;
+ clock_gettime(CLOCK_MONOTONIC, &start_time);
for (int i = 0; i < repeat; i++) {
pre;
__asm volatile("" ::: /* pretend to clobber */ "memory");
@@ -45,7 +49,12 @@
if (tmus < min_diff)
min_diff = tmus;
}
+ clock_gettime(CLOCK_MONOTONIC, &end_time);
+ uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec;
+ uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec;
+ uint64_t nsecs = end_ns - start_ns;
printf(" %f cycles / ops", min_diff * 1.0 / number);
+ printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9);
printf("n");
fflush(NULL);
} while (0)
@@ -56,6 +65,8 @@
fflush(NULL);
uint64_t tm1, tm2;
uint64_t min_diff = (uint64_t)-1;
+ struct timespec start_time, end_time;
+ clock_gettime(CLOCK_MONOTONIC, &start_time);
for (int i = 0; i < repeat; i++) {
pre;
__asm volatile("" ::: /* pretend to clobber */ "memory");
@@ -67,7 +78,12 @@
if (tmus < min_diff)
min_diff = tmus;
}
+ clock_gettime(CLOCK_MONOTONIC, &end_time);
+ uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec;
+ uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec;
+ uint64_t nsecs = end_ns - start_ns;
printf(" %f cycles / ops", min_diff * 1.0 / number);
+ printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9);
printf("n");
fflush(NULL);
} while (0)
@@ -96,7 +112,7 @@ size_t fillwithtext(char *buffer, size_t size) {
}

int main() {
- const int N = 1024;
+ const int N = 1024; //*1024;
char *buffer = malloc(N);
char *tmpbuffer = malloc(N);
int repeat = 100;
  1. diff --git a/Makefile b/Makefile
  2. index 3fe0615..c922db4 100644
  3. --- a/Makefile
  4. +++ b/Makefile
  5. @@ -3,10 +3,11 @@
  6.  #
  7.  .SUFFIXES: .cpp .o .c .h
  8.  ifeq ($(DEBUG),1)
  9. -CFLAGS = -fPIC  -std=c99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined  -fno-omit-frame-pointer -fsanitize=address
  10. +CFLAGS = -fPIC  -std=gnu99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined  -fno-omit-frame-pointer -fsanitize=address
  11.  else
  12. -CFLAGS = -fPIC -std=c99 -O3  -march=native -Wall -Wextra -Wshadow
  13. +CFLAGS = -fPIC -std=gnu99 -O3  -march=native -Wall -Wextra -Wshadow
  14.  endif # debug
  15. +LDLIBS=-lrt
  16.  all: despacebenchmark
  17.  HEADERS=./include/despacer.h ./include/despacer_tables.h
  18.  
  19. diff --git a/benchmarks/despacebenchmark.c b/benchmarks/despacebenchmark.c
  20. index 510b8a3..607b3b9 100644
  21. --- a/benchmarks/despacebenchmark.c
  22. +++ b/benchmarks/despacebenchmark.c
  23. @@ -5,6 +5,8 @@
  24.  #include <string.h>
  25.  #include "despacer.h"
  26.  
  27. +#include <time.h>
  28. +
  29.  #define RDTSC_START(cycles)                                                    
  30.    do {                                                                        
  31.      register unsigned cyc_high, cyc_low;                                      
  32. @@ -35,6 +37,8 @@
  33.      fflush(NULL);                                                              
  34.      uint64_t tm1, tm2;                                                        
  35.      uint64_t min_diff = (uint64_t)-1;                                          
  36. +    struct timespec start_time, end_time;
  37. +    clock_gettime(CLOCK_MONOTONIC, &start_time);
  38.      for (int i = 0; i < repeat; i++) {                                        
  39.        pre;                                                                    
  40.        __asm volatile("" ::: /* pretend to clobber */ "memory");                
  41. @@ -45,7 +49,12 @@
  42.        if (tmus < min_diff)                                                    
  43.          min_diff = tmus;                                                      
  44.      }                                                                          
  45. +    clock_gettime(CLOCK_MONOTONIC, &end_time);
  46. +    uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec;
  47. +    uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec;
  48. +    uint64_t nsecs = end_ns - start_ns;
  49.      printf(" %f cycles / ops", min_diff * 1.0 / number);                      
  50. +    printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9);
  51.      printf("n");                                                              
  52.      fflush(NULL);                                                              
  53.    } while (0)
  54. @@ -56,6 +65,8 @@
  55.      fflush(NULL);                                                              
  56.      uint64_t tm1, tm2;                                                        
  57.      uint64_t min_diff = (uint64_t)-1;                                          
  58. +    struct timespec start_time, end_time;
  59. +    clock_gettime(CLOCK_MONOTONIC, &start_time);
  60.      for (int i = 0; i < repeat; i++) {                                        
  61.        pre;                                                                    
  62.        __asm volatile("" ::: /* pretend to clobber */ "memory");                
  63. @@ -67,7 +78,12 @@
  64.        if (tmus < min_diff)                                                    
  65.          min_diff = tmus;                                                      
  66.      }                                                                          
  67. +    clock_gettime(CLOCK_MONOTONIC, &end_time);
  68. +    uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec;
  69. +    uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec;
  70. +    uint64_t nsecs = end_ns - start_ns;
  71.      printf(" %f cycles / ops", min_diff * 1.0 / number);                      
  72. +    printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9);
  73.      printf("n");                                                              
  74.      fflush(NULL);                                                              
  75.    } while (0)
  76. @@ -96,7 +112,7 @@ size_t fillwithtext(char *buffer, size_t size) {
  77.  }
  78.  
  79.  int main() {
  80. -  const int N = 1024;
  81. +  const int N = 1024; //*1024;
  82.    char *buffer = malloc(N);
  83.    char *tmpbuffer = malloc(N);
  84.    int repeat = 100;
  85.  
go to heaven