6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
//
9
- // The following text is present in each test file:
10
- //
11
- // These tests aim to capture real-world multithreaded use cases of atomic
12
- // builtins. Each test focuses on a single atomic operation. Those using
13
- // multiple operations can be compared with other tests using the same
14
- // operations to isolate bugs to a single atomic operation.
15
- //
16
- // Each test consists of a "looper" body and a test script. The test script
17
- // instantiates 10 threads, each running the looper. The loopers contend the
18
- // same memory address, performing atomic operations on it. Each looper executes
19
- // 10^6 times for a total of 10^7 operations. The resultant value in the
20
- // contended pointer is compared against a closed-form solution. It's expected
21
- // that the two values equate.
22
- //
23
- // For example, a looper that increments the shared pointer is expected to end
24
- // up with a value of 10^7. If its final value is not that, the test fails.
25
- //
26
- // Each test also tests the corresponding nonatomic operation with a separate
27
- // shared variable. Ideally, this value differs from the atomic "correct" value,
28
- // and the test can compare the two. In reality, some simpler operations (e.g.
29
- // those conducted through the ALU) can still end up with the correct answer,
30
- // even when performed nonatomically. These tests do not check the nonatomic
31
- // result, although it is still outputted to aid in debugging.
32
- //
33
- // Each test is performed on all relevant types.
34
- //
35
- // ===----------------------------------------------------------------------===//
36
- //
37
9
// This file tests atomic operations on floating point types with aligned
38
10
// memory addresses.
39
11
//
40
12
// The types tested are: float, double.
41
13
// The ops tested are: xchg, cmpxchg.
42
14
//
15
+ // Please read the README before contributing.
16
+ //
43
17
// ===----------------------------------------------------------------------===//
44
18
45
19
#include < sys/stat.h>
@@ -59,18 +33,13 @@ void test_float_scalar_xchg() {
59
33
std::vector<std::thread> pool;
60
34
61
35
for (int model : atomic_exchange_models) {
62
- T afloat = 0 , ffloat = 0 ;
36
+ T afloat = 0 ;
63
37
for (int n = 0 ; n < kThreads ; ++n)
64
38
pool.emplace_back (looper_numeric_xchg_atomic<T>, &afloat, model);
65
39
for (int n = 0 ; n < kThreads ; ++n)
66
40
pool[n].join ();
67
41
pool.clear ();
68
- for (int n = 0 ; n < kThreads ; ++n)
69
- pool.emplace_back (looper_numeric_xchg_nonatomic<T>, &ffloat, model);
70
- for (int n = 0 ; n < kThreads ; ++n)
71
- pool[n].join ();
72
- pool.clear ();
73
- if (lt (afloat, ffloat) || afloat < expected * (1 - kEpsilon ) ||
42
+ if (afloat < expected * (1 - kEpsilon ) ||
74
43
afloat > expected * (1 + kEpsilon ))
75
44
fail ();
76
45
}
@@ -85,14 +54,14 @@ void test_float_scalar_cmpxchg() {
85
54
86
55
for (int success_model : atomic_compare_exchange_models) {
87
56
for (int fail_model : atomic_compare_exchange_models) {
88
- T afloat = 0 , ffloat = 0 ;
57
+ T afloat = 0 ;
89
58
for (int n = 0 ; n < kThreads ; ++n)
90
- pool.emplace_back (looper_numeric_cmpxchg<T>, &afloat, &ffloat ,
91
- success_model, fail_model);
59
+ pool.emplace_back (looper_numeric_cmpxchg<T>, &afloat, success_model ,
60
+ fail_model);
92
61
for (int n = 0 ; n < kThreads ; ++n)
93
62
pool[n].join ();
94
63
pool.clear ();
95
- if (lt (afloat, ffloat) || afloat < expected * (1 - kEpsilon ) ||
64
+ if (afloat < expected * (1 - kEpsilon ) ||
96
65
afloat > expected * (1 + kEpsilon ))
97
66
fail ();
98
67
}
@@ -107,6 +76,10 @@ void test_floating_point() {
107
76
std::cout << " Testing double\n " ;
108
77
test_float_scalar_xchg<double >();
109
78
test_float_scalar_cmpxchg<double >();
79
+
80
+ std::cout << " Testing float128\n " ;
81
+ test_float_scalar_xchg<__float128>();
82
+ test_float_scalar_cmpxchg<__float128>();
110
83
}
111
84
112
85
int main () {
0 commit comments