source: benchmark/basic/fetch_add.c @ 29185fc

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 29185fc was 525b5ef, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add documentation

  • Property mode set to 100644
File size: 571 bytes
RevLine 
[6aa537a4]1#include <stdio.h>
2
3#include "bench.h"
4
[525b5ef]5// Does a "lock add" on entry and a "lock sub" on exit => 2 atomic instructions making it the most expensive
6// atomic test.
7
[6aa537a4]8volatile int value;
9
10void __attribute__((noinline)) do_call() {
11        __atomic_add_fetch( &value, 1, __ATOMIC_SEQ_CST );
12        asm volatile ("");
13        __atomic_sub_fetch( &value, 1, __ATOMIC_SEQ_CST );
14}
15
[b4107c8]16int main( int argc, char * argv[] ) {
17        BENCH_START()
[6aa537a4]18        BENCH(
[b4107c8]19                for (size_t i = 0; i < times; i++) {
[6aa537a4]20                        do_call();
21                },
22                result
23        )
[b4107c8]24        printf( "%g\n", result );
[6aa537a4]25}
[b4107c8]26
27// Local Variables: //
28// tab-width: 4 //
29// End: //
Note: See TracBrowser for help on using the repository browser.