Skip to content

Commit

Permalink
Make some code build faster
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Jul 24, 2024
1 parent 5dd7ddb commit 4a1ae86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion test/libcxx/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ o/$(MODE)/test/libcxx/%.dbg: \

$(TEST_LIBCXX_OBJS): private OVERRIDE_CXXFLAGS += -fexceptions -frtti

o/$(MODE)/test/libcxx/openmp_test.o: private CXXFLAGS += -fopenmp
o/$(MODE)/test/libcxx/openmp_test.o: private CXXFLAGS += -fopenmp -O3
o/$(MODE)/test/libcxx/openmp_test.runs: private QUOTA += -C100

.PHONY: o/$(MODE)/test/libcxx
Expand Down
43 changes: 17 additions & 26 deletions test/libcxx/openmp_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <ctime>
#include "libc/stdio/rand.h"

#define PRECISION 2e-6
#define PRECISION 2e-5
#define LV1DCACHE 49152
#define THRESHOLD 3000000

Expand All @@ -35,20 +35,9 @@
#endif

#define OPTIMIZED __attribute__((__optimize__("-O3,-ffast-math")))
#define PORTABLE \
__target_clones("arch=znver4," \
"arch=znver3," \
"arch=sapphirerapids," \
"arch=alderlake," \
"arch=rocketlake," \
"arch=cooperlake," \
"arch=tigerlake," \
"arch=cascadelake," \
"arch=skylake-avx512," \
"arch=skylake," \
"arch=znver1," \
"arch=tremont," \
"fma," \
#define PORTABLE \
__target_clones("arch=znver4," \
"fma," \
"avx")

static bool is_self_testing;
Expand Down Expand Up @@ -358,17 +347,19 @@ long micros(void) {
return ts.tv_sec * 1000000 + (ts.tv_nsec + 999) / 1000;
}

#define bench(x) \
do { \
long t1 = micros(); \
for (long i = 0; i < ITERATIONS; ++i) { \
asm volatile("" ::: "memory"); \
x; \
asm volatile("" ::: "memory"); \
} \
long t2 = micros(); \
printf("%8" PRId64 " µs %s\n", (t2 - t1 + ITERATIONS - 1) / ITERATIONS, \
#x); \
#define bench(x) \
do { \
int N = 10; \
long long t1 = micros(); \
for (long long i = 0; i < N; ++i) { \
asm volatile("" ::: "memory"); \
x; \
asm volatile("" ::: "memory"); \
} \
long long t2 = micros(); \
printf("%8lld µs %2dx n=%5d m=%5d k=%5d %s %g gigaflops\n", \
(t2 - t1 + N - 1) / N, N, (int)n, (int)m, (int)k, #x, \
1e6 / ((t2 - t1 + N - 1) / N) * m * n * k * 1e-9); \
} while (0)

double real01(unsigned long x) { // (0,1)
Expand Down

0 comments on commit 4a1ae86

Please sign in to comment.