Skip to content

Commit d6e4a42

Browse files
authored
[SYCL][NFC] Apply clang-format to bitreverse test (#13095)
Apply clang-format to llvm.bitreverse lowering testcase --------- Signed-off-by: Lu, John <[email protected]>
1 parent 92945f4 commit d6e4a42

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

sycl/test-e2e/LLVMIntrinsicLowering/bitreverse.cpp

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,35 @@
8383
// CHECK-SPV: LinkageAttributes "llvm_bitreverse_v16i16" Export
8484
// CHECK-SPV: LinkageAttributes "llvm_bitreverse_v16i32" Export
8585

86+
#include "common.hpp"
87+
#include <iostream>
8688
#include <string.h>
8789
#include <sycl/sycl.hpp>
88-
#include <iostream>
89-
#include "common.hpp"
9090

9191
using namespace sycl;
9292

9393
template <typename TYPE>
94-
__attribute__((optnone, noinline)) TYPE reference_reverse(TYPE a, const int bitlength) {
94+
__attribute__((optnone, noinline)) TYPE reference_reverse(TYPE a,
95+
const int bitlength) {
9596
TYPE ret = 0;
96-
for (auto i = 0; i<bitlength; i++) {
97-
ret<<=1;
97+
for (auto i = 0; i < bitlength; i++) {
98+
ret <<= 1;
9899
ret |= a & 0x1;
99-
a>>=1;
100+
a >>= 1;
100101
}
101102
return ret;
102103
}
103104

104105
template <typename TYPE>
105106
__attribute__((noinline)) TYPE reverse(TYPE a, int bitlength) {
106-
if (bitlength==8) {
107+
if (bitlength == 8) {
107108
// Avoid bug with __builtin_elementwise_bitreverse(a) on scalar 8-bit types.
108109
a = ((0x55 & a) << 1) | (0x55 & (a >> 1));
109110
a = ((0x33 & a) << 2) | (0x33 & (a >> 2));
110111
return (a << 4) | (a >> 4);
111-
} else if (bitlength==16) {
112-
// Avoid bug with __builtin_elementwise_bitreverse(a) on scalar 16-bit types.
112+
} else if (bitlength == 16) {
113+
// Avoid bug with __builtin_elementwise_bitreverse(a) on scalar 16-bit
114+
// types.
113115
a = ((0x5555 & a) << 1) | (0x5555 & (a >> 1));
114116
a = ((0x3333 & a) << 2) | (0x3333 & (a >> 2));
115117
a = ((0x0F0F & a) << 4) | (0x0F0F & (a >> 4));
@@ -122,83 +124,89 @@ template <class T> class BitreverseTest;
122124

123125
#define NUM_TESTS 1024
124126

125-
template <typename TYPE>
126-
void do_scalar_bitreverse_test() {
127+
template <typename TYPE> void do_scalar_bitreverse_test() {
127128
queue q;
128129

129-
TYPE *Input = (TYPE *) malloc_shared(sizeof(TYPE) * NUM_TESTS, q.get_device(), q.get_context());
130-
TYPE *Output = (TYPE *) malloc_shared(sizeof(TYPE) * NUM_TESTS, q.get_device(), q.get_context());
130+
TYPE *Input = (TYPE *)malloc_shared(sizeof(TYPE) * NUM_TESTS, q.get_device(),
131+
q.get_context());
132+
TYPE *Output = (TYPE *)malloc_shared(sizeof(TYPE) * NUM_TESTS, q.get_device(),
133+
q.get_context());
131134

132-
for (unsigned i=0; i<NUM_TESTS; i++)
135+
for (unsigned i = 0; i < NUM_TESTS; i++)
133136
Input[i] = get_rand<TYPE>();
134137
q.submit([=](handler &cgh) {
135-
cgh.single_task<BitreverseTest<TYPE>> ([=]() {
136-
for (unsigned i=0; i<NUM_TESTS; i++)
137-
Output[i] = reverse(Input[i],sizeof(TYPE)*8);
138+
cgh.single_task<BitreverseTest<TYPE>>([=]() {
139+
for (unsigned i = 0; i < NUM_TESTS; i++)
140+
Output[i] = reverse(Input[i], sizeof(TYPE) * 8);
138141
});
139142
});
140143
q.wait();
141-
for (unsigned i=0; i<NUM_TESTS; i++)
142-
if (Output[i]!=reference_reverse(Input[i],sizeof(TYPE)*8)) {
143-
std::cerr << "Failed for scalar " << std::hex << Input[i] << " sizeof=" << sizeof(TYPE) << "\n";
144+
for (unsigned i = 0; i < NUM_TESTS; i++)
145+
if (Output[i] != reference_reverse(Input[i], sizeof(TYPE) * 8)) {
146+
std::cerr << "Failed for scalar " << std::hex << Input[i]
147+
<< " sizeof=" << sizeof(TYPE) << "\n";
144148
exit(-1);
145149
}
146150

147151
free(Input, q.get_context());
148152
free(Output, q.get_context());
149153
}
150154

151-
template <typename VTYPE>
152-
void do_vector_bitreverse_test() {
155+
template <typename VTYPE> void do_vector_bitreverse_test() {
153156
queue q;
154157

155-
VTYPE *Input = (VTYPE *) malloc_shared(sizeof(VTYPE) * NUM_TESTS, q.get_device(), q.get_context());
156-
VTYPE *Output = (VTYPE *) malloc_shared(sizeof(VTYPE) * NUM_TESTS, q.get_device(), q.get_context());
158+
VTYPE *Input = (VTYPE *)malloc_shared(sizeof(VTYPE) * NUM_TESTS,
159+
q.get_device(), q.get_context());
160+
VTYPE *Output = (VTYPE *)malloc_shared(sizeof(VTYPE) * NUM_TESTS,
161+
q.get_device(), q.get_context());
157162

158-
for (unsigned i=0; i<NUM_TESTS; i++)
159-
for (unsigned j=0; j<__builtin_vectorelements(VTYPE); j++)
160-
Input[i][j] = get_rand<typename std::decay<decltype(Input[0][0])>::type>();
163+
for (unsigned i = 0; i < NUM_TESTS; i++)
164+
for (unsigned j = 0; j < __builtin_vectorelements(VTYPE); j++)
165+
Input[i][j] =
166+
get_rand<typename std::decay<decltype(Input[0][0])>::type>();
161167

162168
q.submit([=](handler &cgh) {
163-
cgh.single_task<BitreverseTest<VTYPE>> ([=]() {
164-
for (unsigned i=0; i<NUM_TESTS; i++)
165-
Output[i] = reverse(Input[i],sizeof(Input[0][0])*8);
169+
cgh.single_task<BitreverseTest<VTYPE>>([=]() {
170+
for (unsigned i = 0; i < NUM_TESTS; i++)
171+
Output[i] = reverse(Input[i], sizeof(Input[0][0]) * 8);
166172
});
167173
});
168174
q.wait();
169-
for (unsigned i=0; i<NUM_TESTS; i++) {
170-
auto Reference=reference_reverse(Input[i],sizeof(Input[0][0])*8);
171-
for (unsigned j=0; j<__builtin_vectorelements(VTYPE); j++)
172-
if (Output[i][j]!=Reference[j]) {
173-
std::cerr << "Failed for vector " << std::hex << Input[i][j] << " sizeof=" << sizeof(Input[0][0]) << " elements=" << __builtin_vectorelements(VTYPE) << "\n";
175+
for (unsigned i = 0; i < NUM_TESTS; i++) {
176+
auto Reference = reference_reverse(Input[i], sizeof(Input[0][0]) * 8);
177+
for (unsigned j = 0; j < __builtin_vectorelements(VTYPE); j++)
178+
if (Output[i][j] != Reference[j]) {
179+
std::cerr << "Failed for vector " << std::hex << Input[i][j]
180+
<< " sizeof=" << sizeof(Input[0][0])
181+
<< " elements=" << __builtin_vectorelements(VTYPE) << "\n";
174182
exit(-1);
175183
}
176184
}
177185
free(Input, q.get_context());
178186
free(Output, q.get_context());
179187
}
180188

181-
using uint8_t2 = uint8_t __attribute__((ext_vector_type(2)));
189+
using uint8_t2 = uint8_t __attribute__((ext_vector_type(2)));
182190
using uint16_t2 = uint16_t __attribute__((ext_vector_type(2)));
183191
using uint32_t2 = uint32_t __attribute__((ext_vector_type(2)));
184192
using uint64_t2 = uint64_t __attribute__((ext_vector_type(2)));
185193

186-
using uint8_t3 = uint8_t __attribute__((ext_vector_type(3)));
194+
using uint8_t3 = uint8_t __attribute__((ext_vector_type(3)));
187195
using uint16_t3 = uint16_t __attribute__((ext_vector_type(3)));
188196
using uint32_t3 = uint32_t __attribute__((ext_vector_type(3)));
189197
using uint64_t3 = uint64_t __attribute__((ext_vector_type(3)));
190198

191-
using uint8_t4 = uint8_t __attribute__((ext_vector_type(4)));
199+
using uint8_t4 = uint8_t __attribute__((ext_vector_type(4)));
192200
using uint16_t4 = uint16_t __attribute__((ext_vector_type(4)));
193201
using uint32_t4 = uint32_t __attribute__((ext_vector_type(4)));
194202
using uint64_t4 = uint64_t __attribute__((ext_vector_type(4)));
195203

196-
using uint8_t8 = uint8_t __attribute__((ext_vector_type(8)));
204+
using uint8_t8 = uint8_t __attribute__((ext_vector_type(8)));
197205
using uint16_t8 = uint16_t __attribute__((ext_vector_type(8)));
198206
using uint32_t8 = uint32_t __attribute__((ext_vector_type(8)));
199207
using uint64_t8 = uint64_t __attribute__((ext_vector_type(8)));
200208

201-
using uint8_t16 = uint8_t __attribute__((ext_vector_type(16)));
209+
using uint8_t16 = uint8_t __attribute__((ext_vector_type(16)));
202210
using uint16_t16 = uint16_t __attribute__((ext_vector_type(16)));
203211
using uint32_t16 = uint32_t __attribute__((ext_vector_type(16)));
204212
using uint64_t16 = uint64_t __attribute__((ext_vector_type(16)));
@@ -218,7 +226,7 @@ int main() {
218226
do_vector_bitreverse_test<uint8_t3>();
219227
do_vector_bitreverse_test<uint16_t3>();
220228
do_vector_bitreverse_test<uint32_t3>();
221-
229+
222230
do_vector_bitreverse_test<uint8_t4>();
223231
do_vector_bitreverse_test<uint16_t4>();
224232
do_vector_bitreverse_test<uint32_t4>();
@@ -233,4 +241,3 @@ int main() {
233241

234242
return 0;
235243
}
236-

sycl/test-e2e/LLVMIntrinsicLowering/common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <stdint.h>
1112
#include <stdlib.h>
1213
#include <sycl/bit_cast.hpp>
1314

0 commit comments

Comments
 (0)