ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since cadec25 was
525b5ef,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
add documentation
|
-
Property mode set to
100644
|
File size:
835 bytes
|
Rev | Line | |
---|
[7a8f5246] | 1 | #include <stdbool.h> |
---|
| 2 | #include <stdio.h> |
---|
| 3 | |
---|
| 4 | #include "bench.h" |
---|
| 5 | |
---|
[525b5ef] | 6 | // Does not do a fetch & add. It mimics the cfa protocol to disable interrupts locally, by writing true or false to a |
---|
| 7 | // thread_local Boolean. This means the entire protocol is just to "mov" instructions making it extremely cheap. |
---|
| 8 | |
---|
[7a8f5246] | 9 | #define thread_local _Thread_local |
---|
| 10 | |
---|
[54db6ba] | 11 | thread_local volatile bool value; |
---|
[7a8f5246] | 12 | |
---|
| 13 | void __attribute__((noinline)) do_call() { |
---|
| 14 | __atomic_store_n( &value, true, __ATOMIC_RELAXED ); |
---|
| 15 | __atomic_signal_fence(__ATOMIC_ACQUIRE); |
---|
| 16 | asm volatile (""); |
---|
| 17 | __atomic_store_n( &value, false, __ATOMIC_RELAXED ); |
---|
| 18 | __atomic_signal_fence(__ATOMIC_RELEASE); |
---|
| 19 | } |
---|
| 20 | |
---|
[b4107c8] | 21 | int main( int argc, char * argv[] ) { |
---|
| 22 | BENCH_START() |
---|
[7a8f5246] | 23 | BENCH( |
---|
[b4107c8] | 24 | for (size_t i = 0; i < times; i++) { |
---|
[7a8f5246] | 25 | do_call(); |
---|
| 26 | }, |
---|
| 27 | result |
---|
| 28 | ) |
---|
[b4107c8] | 29 | printf( "%g\n", result ); |
---|
[7a8f5246] | 30 | } |
---|
[b4107c8] | 31 | |
---|
| 32 | // Local Variables: // |
---|
| 33 | // tab-width: 4 // |
---|
| 34 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.