ast-experimental
Last change
on this file since 53f6a11 was
1bcbf02,
checked in by Thierry Delisle <tdelisle@…>, 2 years ago
|
Changed declarations using _Thread_local to use thread.
I'm fairly sure they do exactly the same, but thread is:
- more consistent with uC++.
- Shorter.
- Better documented.
|
-
Property mode set to
100644
|
File size:
795 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 | |
---|
[1bcbf02] | 9 | __thread volatile bool value; |
---|
[7a8f5246] | 10 | |
---|
| 11 | void __attribute__((noinline)) do_call() { |
---|
| 12 | __atomic_store_n( &value, true, __ATOMIC_RELAXED ); |
---|
| 13 | __atomic_signal_fence(__ATOMIC_ACQUIRE); |
---|
| 14 | asm volatile (""); |
---|
| 15 | __atomic_store_n( &value, false, __ATOMIC_RELAXED ); |
---|
| 16 | __atomic_signal_fence(__ATOMIC_RELEASE); |
---|
| 17 | } |
---|
| 18 | |
---|
[b4107c8] | 19 | int main( int argc, char * argv[] ) { |
---|
| 20 | BENCH_START() |
---|
[7a8f5246] | 21 | BENCH( |
---|
[b4107c8] | 22 | for (size_t i = 0; i < times; i++) { |
---|
[7a8f5246] | 23 | do_call(); |
---|
| 24 | }, |
---|
| 25 | result |
---|
| 26 | ) |
---|
[b4107c8] | 27 | printf( "%g\n", result ); |
---|
[7a8f5246] | 28 | } |
---|
[b4107c8] | 29 | |
---|
| 30 | // Local Variables: // |
---|
| 31 | // tab-width: 4 // |
---|
| 32 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.