Skip to content

Commit 038b18e

Browse files
authored
Adding style scripts. (simdjson#243)
* Adding style scripts.
1 parent 0610ebc commit 038b18e

12 files changed

Lines changed: 439 additions & 42 deletions

.drone.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ steps:
2929
- make amalgamate
3030
---
3131
kind: pipeline
32+
name: stylecheck
33+
34+
platform:
35+
os: linux
36+
arch: amd64
37+
38+
steps:
39+
- name: Build and Test
40+
image: ubuntu:18.04
41+
commands:
42+
- apt-get update -y
43+
- apt-get install -y python clang-format
44+
- ./style/run-clang-format.py -r include/ benchmark/ src/ tests/
45+
---
46+
kind: pipeline
3247
name: amd64_clang_cmake
3348

3449
platform:
@@ -43,7 +58,7 @@ steps:
4358
CXX: clang++
4459
commands:
4560
- apt-get update -y
46-
- apt-get install -y make $CC g++ cmake
61+
- apt-get install -y make $CC g++ cmake
4762
- $CC --version
4863
- mkdir build && cd build
4964
- cmake $CMAKE_FLAGS ..
@@ -65,7 +80,7 @@ steps:
6580
CXX: g++
6681
commands:
6782
- apt-get update -y
68-
- apt-get install -y make $CC g++ cmake
83+
- apt-get install -y make $CC g++ cmake
6984
- $CC --version
7085
- mkdir build && cd build
7186
- cmake $CMAKE_FLAGS ..
@@ -87,7 +102,7 @@ steps:
87102
CXX: clang++
88103
commands:
89104
- apt-get update -y
90-
- apt-get install -y make $CC g++ cmake
105+
- apt-get install -y make $CC g++ cmake
91106
- $CC --version
92107
- mkdir build && cd build
93108
- cmake $CMAKE_FLAGS ..

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ addons:
77
packages:
88
- gcc-7
99
- g++-7
10-
10+
- clang-format
11+
- python
1112
branches:
1213
only:
1314
- master
@@ -25,4 +26,5 @@ script:
2526
- ARCHFLAGS="-march=nehalem" make
2627
- ARCHFLAGS="-march=nehalem" make test
2728
- ARCHFLAGS="-march=nehalem" make everything
29+
- ./style/run-clang-format.py -r include/ benchmark/ src/ tests/
2830

benchmark/linux/linux-perf-events.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
#include <cstring> // for memset
1212
#include <stdexcept>
1313

14-
#include <vector>
1514
#include <iostream>
15+
#include <vector>
1616

1717
template <int TYPE = PERF_TYPE_HARDWARE> class LinuxEvents {
1818
int fd;
19-
bool working;
19+
bool working;
2020
perf_event_attr attribs;
2121
int num_events;
2222
std::vector<uint64_t> temp_result_vec;
2323
std::vector<uint64_t> ids;
24+
2425
public:
2526
explicit LinuxEvents(std::vector<int> config_vec) : fd(0), working(true) {
2627
memset(&attribs, 0, sizeof(attribs));
@@ -84,8 +85,9 @@ template <int TYPE = PERF_TYPE_HARDWARE> class LinuxEvents {
8485

8586
private:
8687
void report_error(const std::string &context) {
87-
if(working) std::cerr << (context + ": " + std::string(strerror(errno))) << std::endl;
88-
working = false;
88+
if (working)
89+
std::cerr << (context + ": " + std::string(strerror(errno))) << std::endl;
90+
working = false;
8991
}
9092
};
9193
#endif

include/simdjson/parsedjson.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#include "simdjson/simdjson.h"
88
#include <cinttypes>
99
#include <cmath>
10-
#include <limits>
1110
#include <cstring>
1211
#include <iomanip>
1312
#include <iostream>
13+
#include <limits>
1414

1515
#define JSON_VALUE_MASK 0xFFFFFFFFFFFFFF
1616

@@ -168,7 +168,8 @@ class ParsedJson {
168168
// we're at "d"
169169
inline double get_double() const {
170170
if (location + 1 >= tape_length) {
171-
return std::numeric_limits<double>::quiet_NaN(); // default value in case of error
171+
return std::numeric_limits<double>::quiet_NaN(); // default value in
172+
// case of error
172173
}
173174
double answer;
174175
memcpy(&answer, &pj.tape[location + 1], sizeof(answer));

include/simdjson/simdutf8check_haswell.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,31 +119,31 @@ static inline void avx_check_overlong(__m256i current_bytes,
119119
__m256i *has_error) {
120120
__m256i off1_hibits = push_last_byte_of_a_to_b(previous_hibits, hibits);
121121
__m256i initial_mins = _mm256_shuffle_epi8(
122-
_mm256_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128,
123-
-128, -128, -128, // 10xx => false
124-
0xC2u, -128, // 110x
125-
0xE1u, // 1110
126-
0xF1u, // 1111
127-
-128, -128, -128, -128, -128, -128, -128, -128, -128,
128-
-128, -128, -128, // 10xx => false
129-
0xC2u, -128, // 110x
130-
0xE1u, // 1110
131-
0xF1u), // 1111
122+
_mm256_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128,
123+
-128, -128, -128, // 10xx => false
124+
0xC2u, -128, // 110x
125+
0xE1u, // 1110
126+
0xF1u, // 1111
127+
-128, -128, -128, -128, -128, -128, -128, -128, -128,
128+
-128, -128, -128, // 10xx => false
129+
0xC2u, -128, // 110x
130+
0xE1u, // 1110
131+
0xF1u), // 1111
132132
off1_hibits);
133133

134134
__m256i initial_under = _mm256_cmpgt_epi8(initial_mins, off1_current_bytes);
135135

136136
__m256i second_mins = _mm256_shuffle_epi8(
137-
_mm256_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128,
138-
-128, -128, -128, // 10xx => false
139-
127, 127, // 110x => true
140-
0xA0u, // 1110
141-
0x90u, // 1111
142-
-128, -128, -128, -128, -128, -128, -128, -128, -128,
143-
-128, -128, -128, // 10xx => false
144-
127, 127, // 110x => true
145-
0xA0u, // 1110
146-
0x90u), // 1111
137+
_mm256_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128,
138+
-128, -128, -128, // 10xx => false
139+
127, 127, // 110x => true
140+
0xA0u, // 1110
141+
0x90u, // 1111
142+
-128, -128, -128, -128, -128, -128, -128, -128, -128,
143+
-128, -128, -128, // 10xx => false
144+
127, 127, // 110x => true
145+
0xA0u, // 1110
146+
0x90u), // 1111
147147
off1_hibits);
148148
__m256i second_under = _mm256_cmpgt_epi8(second_mins, current_bytes);
149149
*has_error = _mm256_or_si256(*has_error,

include/simdjson/simdutf8check_westmere.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ static inline void check_first_continuation_max(__m128i current_bytes,
8383
__m128i maskED = _mm_cmpeq_epi8(off1_current_bytes, _mm_set1_epi8(0xEDu));
8484
__m128i maskF4 = _mm_cmpeq_epi8(off1_current_bytes, _mm_set1_epi8(0xF4u));
8585

86-
__m128i badfollowED =
87-
_mm_and_si128(_mm_cmpgt_epi8(current_bytes, _mm_set1_epi8(0x9Fu)), maskED);
88-
__m128i badfollowF4 =
89-
_mm_and_si128(_mm_cmpgt_epi8(current_bytes, _mm_set1_epi8(0x8Fu)), maskF4);
86+
__m128i badfollowED = _mm_and_si128(
87+
_mm_cmpgt_epi8(current_bytes, _mm_set1_epi8(0x9Fu)), maskED);
88+
__m128i badfollowF4 = _mm_and_si128(
89+
_mm_cmpgt_epi8(current_bytes, _mm_set1_epi8(0x8Fu)), maskF4);
9090

9191
*has_error = _mm_or_si128(*has_error, _mm_or_si128(badfollowED, badfollowF4));
9292
}
@@ -102,8 +102,8 @@ static inline void check_overlong(__m128i current_bytes,
102102
__m128i previous_hibits, __m128i *has_error) {
103103
__m128i off1_hibits = _mm_alignr_epi8(hibits, previous_hibits, 16 - 1);
104104
__m128i initial_mins = _mm_shuffle_epi8(
105-
_mm_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
106-
-128, -128, // 10xx => false
105+
_mm_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
106+
-128, -128, // 10xx => false
107107
0xC2u, -128, // 110x
108108
0xE1u, // 1110
109109
0xF1u),
@@ -112,10 +112,10 @@ static inline void check_overlong(__m128i current_bytes,
112112
__m128i initial_under = _mm_cmpgt_epi8(initial_mins, off1_current_bytes);
113113

114114
__m128i second_mins = _mm_shuffle_epi8(
115-
_mm_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
116-
-128, -128, // 10xx => false
117-
127, 127, // 110x => true
118-
0xA0u, // 1110
115+
_mm_setr_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
116+
-128, -128, // 10xx => false
117+
127, 127, // 110x => true
118+
0xA0u, // 1110
119119
0x90u),
120120
off1_hibits);
121121
__m128i second_under = _mm_cmpgt_epi8(second_mins, current_bytes);

include/simdjson/stage1_find_marks_haswell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ really_inline void find_whitespace_and_structurals<Architecture::HASWELL>(
169169
// end of naive approach
170170

171171
#else // SIMDJSON_NAIVE_STRUCTURAL
172+
// clang-format off
172173
const __m256i structural_table =
173174
_mm256_setr_epi8(44, 125, 0, 0, 0xc0u, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58, 123,
174175
44, 125, 0, 0, 0xc0u, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58, 123);
175176
const __m256i white_table = _mm256_setr_epi8(
176177
32, 100, 100, 100, 17, 100, 113, 2, 100, 9, 10, 112, 100, 13, 100, 100,
177178
32, 100, 100, 100, 17, 100, 113, 2, 100, 9, 10, 112, 100, 13, 100, 100);
179+
// clang-format on
178180
const __m256i struct_offset = _mm256_set1_epi8(0xd4u);
179181
const __m256i struct_mask = _mm256_set1_epi8(32);
180182

src/jsonparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "simdjson/isadetection.h"
21
#include "simdjson/jsonparser.h"
2+
#include "simdjson/isadetection.h"
33
#include "simdjson/portability.h"
44
#include "simdjson/simdjson.h"
55

src/parsedjsoniterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ParsedJson::Iterator::Iterator(ParsedJson &pj_)
2020
depth_index[0].scope_type = current_type;
2121
if (current_type == 'r') {
2222
tape_length = current_val & JSON_VALUE_MASK;
23-
if (location < tape_length) {
23+
if (location < tape_length) {
2424
// If we make it here, then depth_capacity must >=2, but the compiler
2525
// may not know this.
2626
current_val = pj.tape[location];

style/clang-format-check.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
3+
BASE=$SCRIPTPATH/..
4+
cd $BASE
5+
6+
STYLE=$(which clang-format)
7+
if [ $? -ne 0 ]; then
8+
echo "clang-format not installed. Unable to check source file format policy." >&2
9+
exit 1
10+
fi
11+
OURSTYLE='' # defer to .clang-format
12+
OURCONTENT="include benchmark tools tests src"
13+
RE=0
14+
ALLFILES=$(find $OURCONTENT -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.cc' -o -name '*.hh')
15+
for FILE in $ALLFILES; do
16+
echo "checking $FILE"
17+
eval "$STYLE $OURSTYLE $BASE/$FILE" | cmp -s $BASE/$FILE -
18+
if [ $? -ne 0 ]; then
19+
echo "$BASE/$FILE does not respect the coding style." >&2
20+
echo "consider typing $STYLE -i $BASE/$FILE $OURSTYLE to fix the problem." >&2
21+
RE=1
22+
fi
23+
done
24+
25+
exit $RE

0 commit comments

Comments
 (0)