Skip to content

Commit 41843bb

Browse files
committed
Making compliant with LLVM style, other minor changes.
1 parent e2ed34f commit 41843bb

File tree

6 files changed

+106
-183
lines changed

6 files changed

+106
-183
lines changed

Diff for: SingleSource/UnitTests/Atomic/CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
# These tests output numerical values to improve debuggability.
2+
# Setting FP_TOLERANCE causes the test checker to use fpcmp to compare
3+
# test and expected output.
4+
# Because the nonatomic output may vary wildly even in a passing run,
5+
# we set FP_TOLERANCE high so the test will never fail due to
6+
# differing numerical results.
7+
# The tests each have their own correctness checking and will fail
8+
# properly if something is actually wrong.
19
set(FP_TOLERANCE 1000000)
10+
11+
# Link the Clang built libatomic.
212
execute_process(COMMAND ${CMAKE_C_COMPILER} --print-file-name=libclang_rt.atomic.so
313
OUTPUT_VARIABLE _path_to_libatomic
414
OUTPUT_STRIP_TRAILING_WHITESPACE)
515
get_filename_component(_libatomic_dir ${_path_to_libatomic} DIRECTORY)
6-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_path_to_libatomic} -Wl,-rpath=${_libatomic_dir}")
16+
add_link_options("LINKER:${_path_to_libatomic},-rpath=${_libatomic_dir}")
717

818
llvm_singlesource()

Diff for: SingleSource/UnitTests/Atomic/big_test.cpp

+13-21
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,24 @@
5050
#include "util.h"
5151

5252
static constexpr int kBigSize = 10;
53-
struct big {
53+
struct big_t {
5454
int v[kBigSize];
5555
};
5656

5757
// The big struct cmpxchg test is identical to the numeric cmpxchg test, except
5858
// each element of the underlying array is incremented.
59-
void looper_big_cmpxchg(big *abig, big &bbig, int success_model,
59+
void looper_big_cmpxchg(big_t *abig, big_t &bbig, int success_model,
6060
int fail_model) {
6161
for (int n = 0; n < kIterations; ++n) {
62-
big desired, expected = {};
62+
big_t desired, expected = {};
6363
do {
6464
desired = expected;
65-
for (int k = 0; k < kBigSize; ++k) {
65+
for (int k = 0; k < kBigSize; ++k)
6666
desired.v[k]++;
67-
}
6867
} while (!__atomic_compare_exchange(abig, &expected, &desired, true,
6968
success_model, fail_model));
70-
for (int k = 0; k < kBigSize; ++k) {
69+
for (int k = 0; k < kBigSize; ++k)
7170
bbig.v[k]++;
72-
}
7371
}
7472
}
7573

@@ -78,32 +76,26 @@ void test_big_cmpxchg() {
7876

7977
for (int success_model : atomic_compare_exchange_models) {
8078
for (int fail_model : atomic_compare_exchange_models) {
81-
big abig = {};
82-
big bbig = {};
83-
for (int n = 0; n < kThreads; ++n) {
79+
big_t abig = {};
80+
big_t bbig = {};
81+
for (int n = 0; n < kThreads; ++n)
8482
pool.emplace_back(looper_big_cmpxchg, &abig, std::ref(bbig),
8583
success_model, fail_model);
86-
}
87-
for (int n = 0; n < kThreads; ++n) {
84+
for (int n = 0; n < kThreads; ++n)
8885
pool[n].join();
89-
}
9086
pool.clear();
9187
std::cout << "CMPXCHG: ";
9288
std::cout << "atomic: ";
93-
for (int n = 0; n < kBigSize; ++n) {
89+
for (int n = 0; n < kBigSize; ++n)
9490
std::cout << abig.v[n] << " ";
95-
}
9691
std::cout << "\n ";
9792
std::cout << "nonatomic: ";
98-
for (int n = 0; n < kBigSize; ++n) {
93+
for (int n = 0; n < kBigSize; ++n)
9994
std::cout << bbig.v[n] << " ";
100-
}
10195
std::cout << "\n";
102-
for (int n = 0; n < kBigSize; ++n) {
103-
if (lt(abig.v[n], bbig.v[n]) || abig.v[n] != kExpected) {
96+
for (int n = 0; n < kBigSize; ++n)
97+
if (lt(abig.v[n], bbig.v[n]) || abig.v[n] != kExpected)
10498
fail();
105-
}
106-
}
10799
}
108100
}
109101
}

Diff for: SingleSource/UnitTests/Atomic/float_test.cpp

+10-18
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,23 @@ void test_float_scalar_xchg() {
6161
for (int model : atomic_exchange_models) {
6262
T afloat = 0;
6363
T ffloat = 0;
64-
for (int n = 0; n < kThreads; ++n) {
64+
for (int n = 0; n < kThreads; ++n)
6565
pool.emplace_back(looper_numeric_xchg_atomic<T>, &afloat, model);
66-
}
67-
for (int n = 0; n < kThreads; ++n) {
66+
for (int n = 0; n < kThreads; ++n)
6867
pool[n].join();
69-
}
7068
pool.clear();
71-
for (int n = 0; n < kThreads; ++n) {
69+
for (int n = 0; n < kThreads; ++n)
7270
pool.emplace_back(looper_numeric_xchg_nonatomic<T>, std::ref(ffloat),
7371
model);
74-
}
75-
for (int n = 0; n < kThreads; ++n) {
72+
for (int n = 0; n < kThreads; ++n)
7673
pool[n].join();
77-
}
7874
pool.clear();
7975
std::cout << "SCALAR (FETCH ADD): "
8076
<< "atomic: " << afloat << " "
8177
<< "nonatomic: " << ffloat << "\n";
8278
if (lt(afloat, ffloat) || afloat < expected * (1 - kEpsilon) ||
83-
afloat > expected * (1 + kEpsilon)) {
79+
afloat > expected * (1 + kEpsilon))
8480
fail();
85-
}
8681
}
8782
}
8883

@@ -97,26 +92,23 @@ void test_float_scalar_cmpxchg() {
9792
for (int fail_model : atomic_compare_exchange_models) {
9893
T afloat = 0;
9994
T ffloat = 0;
100-
for (int n = 0; n < kThreads; ++n) {
95+
for (int n = 0; n < kThreads; ++n)
10196
pool.emplace_back(looper_numeric_cmpxchg<T>, &afloat, std::ref(ffloat),
10297
success_model, fail_model);
103-
}
104-
for (int n = 0; n < kThreads; ++n) {
98+
for (int n = 0; n < kThreads; ++n)
10599
pool[n].join();
106-
}
107100
pool.clear();
108101
std::cout << "SCALAR (FETCH ADD): "
109102
<< "atomic: " << afloat << " "
110103
<< "nonatomic: " << ffloat << "\n";
111104
if (lt(afloat, ffloat) || afloat < expected * (1 - kEpsilon) ||
112-
afloat > expected * (1 + kEpsilon)) {
105+
afloat > expected * (1 + kEpsilon))
113106
fail();
114-
}
115107
}
116108
}
117109
}
118110

119-
void test_float() {
111+
void test_floating_point() {
120112
printf("Testing float\n");
121113
test_float_scalar_xchg<float>();
122114
test_float_scalar_cmpxchg<float>();
@@ -130,6 +122,6 @@ int main() {
130122
printf("%d threads; %d iterations each; total of %d\n", kThreads, kIterations,
131123
kExpected);
132124

133-
test_float();
125+
test_floating_point();
134126
printf("PASSED\n");
135127
}

Diff for: SingleSource/UnitTests/Atomic/int_aligned_test.cpp

+20-40
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,16 @@ void test_int_fetch_add(T &aint, T &iint) {
7171
for (int model : atomic_fetch_models) {
7272
aint = 0;
7373
iint = 0;
74-
for (int n = 0; n < kThreads; ++n) {
74+
for (int n = 0; n < kThreads; ++n)
7575
pool.emplace_back(looper_int_fetch_add<T>, &aint, std::ref(iint), model);
76-
}
77-
for (int n = 0; n < kThreads; ++n) {
76+
for (int n = 0; n < kThreads; ++n)
7877
pool[n].join();
79-
}
8078
pool.clear();
8179
std::cout << "FETCH ADD: "
8280
<< "atomic: " << aint << " "
8381
<< "nonatomic: " << iint << "\n";
84-
if (lt(aint, iint) || aint != val * kExpected) {
82+
if (lt(aint, iint) || aint != val * kExpected)
8583
fail();
86-
}
8784
}
8885
}
8986

@@ -103,19 +100,16 @@ void test_int_fetch_sub(T &aint, T &iint) {
103100
for (int model : atomic_fetch_models) {
104101
aint = val * kExpected;
105102
iint = val * kExpected;
106-
for (int n = 0; n < kThreads; ++n) {
103+
for (int n = 0; n < kThreads; ++n)
107104
pool.emplace_back(looper_int_fetch_sub<T>, &aint, std::ref(iint), model);
108-
}
109-
for (int n = 0; n < kThreads; ++n) {
105+
for (int n = 0; n < kThreads; ++n)
110106
pool[n].join();
111-
}
112107
pool.clear();
113108
std::cout << "FETCH SUB: "
114109
<< "atomic: " << aint << " "
115110
<< "nonatomic: " << iint << "\n";
116-
if (lt(iint, aint) || aint != 0) {
111+
if (lt(iint, aint) || aint != 0)
117112
fail();
118-
}
119113
}
120114
}
121115

@@ -154,20 +148,17 @@ void test_int_fetch_and(T &aint, T &iint) {
154148
for (int model : atomic_fetch_models) {
155149
T acnt = 0, icnt = 0;
156150
aint = ~0, iint = ~0;
157-
for (int n = 0; n < kThreads; ++n) {
151+
for (int n = 0; n < kThreads; ++n)
158152
pool.emplace_back(looper_int_fetch_and<T>, n, &aint, std::ref(iint),
159153
&acnt, &icnt, model);
160-
}
161-
for (int n = 0; n < kThreads; ++n) {
154+
for (int n = 0; n < kThreads; ++n)
162155
pool[n].join();
163-
}
164156
pool.clear();
165157
std::cout << "FETCH AND: "
166158
<< "atomic: " << acnt << " "
167159
<< "nonatomic: " << icnt << "\n";
168-
if (acnt != kExpected) {
160+
if (acnt != kExpected)
169161
fail();
170-
}
171162
}
172163
}
173164

@@ -199,20 +190,17 @@ void test_int_fetch_or(T &aint, T &iint) {
199190
for (int model : atomic_fetch_models) {
200191
T acnt = 0, icnt = 0;
201192
aint = 0, iint = 0;
202-
for (int n = 0; n < kThreads; ++n) {
193+
for (int n = 0; n < kThreads; ++n)
203194
pool.emplace_back(looper_int_fetch_or<T>, n, &aint, std::ref(iint),
204195
&acnt, &icnt, model);
205-
}
206-
for (int n = 0; n < kThreads; ++n) {
196+
for (int n = 0; n < kThreads; ++n)
207197
pool[n].join();
208-
}
209198
pool.clear();
210199
std::cout << "FETCH OR: "
211200
<< "atomic: " << acnt << " "
212201
<< "nonatomic: " << icnt << "\n";
213-
if (acnt != kExpected) {
202+
if (acnt != kExpected)
214203
fail();
215-
}
216204
}
217205
}
218206

@@ -230,19 +218,16 @@ void test_int_fetch_xor(T &aint, T &iint) {
230218
for (int model : atomic_fetch_models) {
231219
aint = 0;
232220
iint = 0;
233-
for (int n = 0; n < kThreads; ++n) {
221+
for (int n = 0; n < kThreads; ++n)
234222
pool.emplace_back(looper_int_fetch_xor<T>, &aint, std::ref(iint), model);
235-
}
236-
for (int n = 0; n < kThreads; ++n) {
223+
for (int n = 0; n < kThreads; ++n)
237224
pool[n].join();
238-
}
239225
pool.clear();
240226
std::cout << "FETCH XOR: "
241227
<< "atomic: " << aint << " "
242228
<< "nonatomic: " << iint << "\n";
243-
if (aint != 0) {
229+
if (aint != 0)
244230
fail();
245-
}
246231
}
247232
}
248233

@@ -253,26 +238,21 @@ void test_int_xchg(T &aint, T &iint) {
253238
for (int model : atomic_exchange_models) {
254239
aint = 0;
255240
iint = 0;
256-
for (int n = 0; n < kThreads; ++n) {
241+
for (int n = 0; n < kThreads; ++n)
257242
pool.emplace_back(looper_numeric_xchg_atomic<T>, &aint, model);
258-
}
259-
for (int n = 0; n < kThreads; ++n) {
243+
for (int n = 0; n < kThreads; ++n)
260244
pool[n].join();
261-
}
262245
pool.clear();
263-
for (int n = 0; n < kThreads; ++n) {
246+
for (int n = 0; n < kThreads; ++n)
264247
pool.emplace_back(looper_numeric_xchg_nonatomic<T>, std::ref(iint),
265248
model);
266-
}
267-
for (int n = 0; n < kThreads; ++n) {
249+
for (int n = 0; n < kThreads; ++n)
268250
pool[n].join();
269-
}
270251
pool.clear();
271252
std::cout << "XCHG: ";
272253
print_int(aint, iint);
273-
if (lt(aint, iint) || aint != val * kExpected) {
254+
if (lt(aint, iint) || aint != val * kExpected)
274255
fail();
275-
}
276256
}
277257
}
278258

0 commit comments

Comments
 (0)