66//
77// ===----------------------------------------------------------------------===//
88//
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- //
379// This file tests atomic operations on floating point types with aligned
3810// memory addresses.
3911//
4012// The types tested are: float, double.
4113// The ops tested are: xchg, cmpxchg.
4214//
15+ // Please read the README before contributing.
16+ //
4317// ===----------------------------------------------------------------------===//
4418
4519#include < sys/stat.h>
@@ -59,18 +33,13 @@ void test_float_scalar_xchg() {
5933 std::vector<std::thread> pool;
6034
6135 for (int model : atomic_exchange_models) {
62- T afloat = 0 , ffloat = 0 ;
36+ T afloat = 0 ;
6337 for (int n = 0 ; n < kThreads ; ++n)
6438 pool.emplace_back (looper_numeric_xchg_atomic<T>, &afloat, model);
6539 for (int n = 0 ; n < kThreads ; ++n)
6640 pool[n].join ();
6741 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 ) ||
7443 afloat > expected * (1 + kEpsilon ))
7544 fail ();
7645 }
@@ -85,14 +54,14 @@ void test_float_scalar_cmpxchg() {
8554
8655 for (int success_model : atomic_compare_exchange_models) {
8756 for (int fail_model : atomic_compare_exchange_models) {
88- T afloat = 0 , ffloat = 0 ;
57+ T afloat = 0 ;
8958 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);
9261 for (int n = 0 ; n < kThreads ; ++n)
9362 pool[n].join ();
9463 pool.clear ();
95- if (lt (afloat, ffloat) || afloat < expected * (1 - kEpsilon ) ||
64+ if (afloat < expected * (1 - kEpsilon ) ||
9665 afloat > expected * (1 + kEpsilon ))
9766 fail ();
9867 }
@@ -107,6 +76,10 @@ void test_floating_point() {
10776 std::cout << " Testing double\n " ;
10877 test_float_scalar_xchg<double >();
10978 test_float_scalar_cmpxchg<double >();
79+
80+ std::cout << " Testing float128\n " ;
81+ test_float_scalar_xchg<__float128>();
82+ test_float_scalar_cmpxchg<__float128>();
11083}
11184
11285int main () {
0 commit comments