#pragma once #if defined(__cforall) extern "C" { #endif #include #include // uint64_t #include // sysconf #if ! defined(__cforall) #include #include #else } #include #endif #define L1 l1 #define L2 L1, l2 #define L3 L2, l3 #define L4 L3, l4 #define L5 L4, l5 #define L6 L5, l6 #define L7 L6, l7 #define L8 L7, l8 static inline uint64_t bench_time() { struct timespec ts; clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); return 1000000000LL * ts.tv_sec + ts.tv_nsec; } // bench_time #if defined(__cforall) struct test_spinlock { volatile bool lock; }; static inline void lock( test_spinlock & this ) { for ( ;; ) { if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break; } } static inline void unlock( test_spinlock & this ) { __atomic_clear( &this.lock, __ATOMIC_RELEASE ); } #endif size_t threads = 1; #define BENCH_START() \ if ( argc > 2 ) exit( EXIT_FAILURE ); \ if ( argc == 2 ) { \ threads = atoi( argv[1] ); \ } #define BENCH(statement, output, done_flag) \ uint64_t count = 0; \ while (true) { \ statement; \ count++; \ if (done_flag) break; \ } \ __atomic_add_fetch(&output, count, __ATOMIC_SEQ_CST); // EndTime = bench_time(); \ // double output = (double)( EndTime - StartTime ) / times; #if defined(__cforall) Duration default_preemption() { return 0; } #endif #if defined(__U_CPLUSPLUS__) unsigned int uDefaultPreemption() { return 0; } #endif