Skip to content

Commit 6867030

Browse files
authored
Adding instructions regarding how to check for an unsupported CPU (simdjson#508)
* Adding instructions. * Slighty more documentation.
1 parent a98d841 commit 6867030

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ On x64 hardware, you should typically build your code by specifying the oldest/l
9090

9191
We also support 64-bit ARM. We assume NEON support. There is no runtime dispatch on ARM.
9292

93+
If you expect your code to run on older processors, you can check that the CPU is supported as follows:
94+
95+
```c++
96+
if (simdjson::active_implementation->name() == "unsupported") {
97+
printf("unsupported CPU\n");
98+
}
99+
```
100+
101+
This check is not useful on ARM processors since all 64-bit ARM processors are supported.
102+
103+
It is not necessary to do this check: if you omit it, you will get back the error code `UNSUPPORTED_ARCHITECTURE` when trying to parse documents.
104+
However, you can call `simdjson::active_implementation->name()` to check which CPU configuration has been detected (e.g., haswell, westmere).
105+
93106
## Computed GOTOs
94107

95108
For best performance, we use a technique called "computed goto", it is also sometimes described as "Labels as Values".
@@ -172,6 +185,7 @@ for (padded_string json : { string("[1, 2, 3]"), string("true"), string("[ true,
172185
}
173186
```
174187

188+
175189
## Newline-Delimited JSON (ndjson) and JSON lines
176190

177191
The simdjson library also support multithreaded JSON streaming through a large file containing many smaller JSON documents in either [ndjson](http://ndjson.org) or [JSON lines](http://jsonlines.org) format. We support files larger than 4GB.

tests/basictests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ bool skyprophet_test() {
570570
}
571571

572572
int main() {
573+
// this is put here deliberately to check that the documentation is correct (README),
574+
// should this fail to compile, you should update the documentation:
575+
if (simdjson::active_implementation->name() == "unsupported") {
576+
printf("unsupported CPU\n");
577+
}
573578
std::cout << "Running basic tests." << std::endl;
574579
if(!json_issue467())
575580
return EXIT_FAILURE;

0 commit comments

Comments
 (0)