1 // RUN: %clangxx_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
4 // bench.h needs pthread barriers which are not available on OS X
10 void thread(int tid
) {
14 for (int i
= 0; i
< bench_niter
; i
++)
15 *(volatile char *)&x
= 1;
18 for (int i
= 0; i
< bench_niter
; i
++)
19 *(volatile short *)&x
= 1;
22 for (int i
= 0; i
< bench_niter
; i
++)
23 *(volatile int *)&x
= 1;
26 for (int i
= 0; i
< bench_niter
; i
++)
27 *(volatile long *)&x
= 1;
30 for (int i
= 0; i
< bench_niter
; i
++)
34 for (int i
= 0; i
< bench_niter
; i
++)
35 *(volatile short *)&x
;
38 for (int i
= 0; i
< bench_niter
; i
++)
42 for (int i
= 0; i
< bench_niter
; i
++)
45 for (int i
= 0; i
< bench_niter
/ 10; i
++) {
46 ((volatile long *)&x
)[0];
47 ((volatile int *)&x
)[0];
48 ((volatile short *)&x
)[2];
49 ((volatile char *)&x
)[6];
50 ((volatile char *)&x
)[7];
51 ((volatile long *)&x
)[0] = 1;
52 ((volatile int *)&x
)[0] = 1;
53 ((volatile short *)&x
)[2] = 1;
54 ((volatile char *)&x
)[6] = 1;
55 ((volatile char *)&x
)[7] = 1;
59 volatile long size
= sizeof(x
);
60 for (int i
= 0; i
< bench_niter
; i
++)
61 memset((void *)&x
, i
, size
);
65 volatile long data
[2] = {};
66 volatile long size
= sizeof(data
) - 2;
67 for (int i
= 0; i
< bench_niter
; i
++)
68 memset(((char *)data
) + 1, i
, size
);
72 volatile long data
[2] = {};
73 for (int i
= 0; i
< bench_niter
/ 8 / 3; i
++) {
74 for (int off
= 0; off
< 8; off
++) {
75 __sanitizer_unaligned_store16(((char *)data
) + off
, i
);
76 __sanitizer_unaligned_store32(((char *)data
) + off
, i
);
77 __sanitizer_unaligned_store64(((char *)data
) + off
, i
);
84 // The compiler wants to optimize all this away.
85 // Use volatile to prevent optimization, but then use kBlock
86 // to avoid the additional non-vector load in the inner loop.
87 // Also use only even indexes to prevent compiler from
89 const int kBlock
= 128;
90 __m128i data
[kBlock
* 2];
91 __m128i
*volatile vptr
= data
;
92 for (int i
= 0; i
< bench_niter
/ kBlock
; i
++) {
94 for (int j
= 0; j
< kBlock
; j
++)
95 _mm_store_si128(&ptr
[j
* 2], _mm_setzero_si128());
104 start_thread_group(bench_nthread
, thread
);