Skip to content

Commit 3f24879

Browse files
committed
Stage2 refactored to simplify multiple implementations
1 parent aa78b70 commit 3f24879

File tree

8 files changed

+646
-616
lines changed

8 files changed

+646
-616
lines changed

benchmark/parse.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ int main(int argc, char *argv[]) {
157157
break;
158158
}
159159
unified.start();
160-
isok = isok && (simdjson::SUCCESS == unified_machine(p.data(), p.size(), pj));
160+
// The default template is simdjson::instruction_set::native.
161+
isok = isok && (simdjson::SUCCESS == unified_machine<>(p.data(), p.size(), pj));
161162
unified.end(results);
162163
cy2 += results[0];
163164
cl2 += results[1];
@@ -188,7 +189,7 @@ int main(int argc, char *argv[]) {
188189
auto start = std::chrono::steady_clock::now();
189190
// The default template is simdjson::instruction_set::native.
190191
isok = (find_structural_bits<>(p.data(), p.size(), pj) == simdjson::SUCCESS);
191-
isok = isok && (simdjson::SUCCESS == unified_machine(p.data(), p.size(), pj));
192+
isok = isok && (simdjson::SUCCESS == unified_machine<>(p.data(), p.size(), pj));
192193
auto end = std::chrono::steady_clock::now();
193194
std::chrono::duration<double> secs = end - start;
194195
res[i] = secs.count();

include/simdjson/jsonparser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ using json_parse_functype = int (const uint8_t *buf, size_t len, ParsedJson &pj,
2525
// Pointer that holds the json_parse implementation corresponding to the available SIMD instruction set
2626
extern json_parse_functype *json_parse_ptr;
2727

28-
2928
// json_parse_implementation is the generic function, it is specialized for various
3029
// SIMD instruction sets, e.g., as json_parse_implementation<simdjson::instruction_set::avx2>
3130
// or json_parse_implementation<simdjson::instruction_set::neon>
@@ -68,7 +67,7 @@ int json_parse_implementation(const uint8_t *buf, size_t len, ParsedJson &pj, bo
6867
pj.errorcode = stage1_is_ok;
6968
return pj.errorcode;
7069
}
71-
int res = unified_machine(buf, len, pj);
70+
int res = unified_machine<T>(buf, len, pj);
7271
if(reallocated) { aligned_free((void*)buf);}
7372
return res;
7473
}

include/simdjson/numberparsing.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
#include "simdjson/parsedjson.h"
77
#include "simdjson/portability.h"
88

9+
#ifdef JSON_TEST_NUMBERS // for unit testing
10+
void foundInvalidNumber(const uint8_t *buf);
11+
void foundInteger(int64_t result, const uint8_t *buf);
12+
void foundFloat(double result, const uint8_t *buf);
13+
#endif
14+
15+
916
// Allowable floating-point values range from std::numeric_limits<double>::lowest()
1017
// to std::numeric_limits<double>::max(), so from
1118
// -1.7976e308 all the way to 1.7975e308 in binary64. The lowest non-zero
@@ -375,9 +382,6 @@ static never_inline bool parse_large_integer(const uint8_t *const buf,
375382
return is_structural_or_whitespace(*p);
376383
}
377384

378-
379-
380-
381385
// parse the number at buf + offset
382386
// define JSON_TEST_NUMBERS for unit testing
383387
//

0 commit comments

Comments
 (0)