aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2020-09-21 09:57:09 +0000
committerGuillaume Chatelet <gchatelet@google.com>2020-09-21 09:57:09 +0000
commit68fa8704794b6d3edbe08f7246a108fbc0334d34 (patch)
treeab3e2dc7c116933cf10b201b7a909150bec308cf
parent3dc868037a89d2741b0fa6ca1add1966b156eaa0 (diff)
downloadcpu_features-68fa8704794b6d3edbe08f7246a108fbc0334d34.tar.gz
[Doc] Add C++ namespace to docs
Fixes #117
-rw-r--r--README.md8
1 files changed, 8 insertions, 0 deletions
diff --git a/README.md b/README.md
index f67f339..801ad7a 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,10 @@ instructions) at runtime.
- **Unit tested.**
<a name="codesample"></a>
+## Code samples
+
+**Note:** For C++ code, the library functions are defined in the `CpuFeatures` namespace.
+
### Checking features at runtime
Here's a simple example that executes a codepath if the CPU supports both the
@@ -38,6 +42,7 @@ AES and the SSE4.2 instruction sets:
```c
#include "cpuinfo_x86.h"
+// For C++, add `using namespace CpuFeatures;`
static const X86Features features = GetX86Info().features;
void Compute(void) {
@@ -59,6 +64,7 @@ features and then check whether AES and NEON are supported.
#include <stdbool.h>
#include "cpuinfo_arm.h"
+// For C++, add `using namespace CpuFeatures;`
static const ArmFeatures features = GetArmInfo().features;
static const bool has_aes_and_neon = features.aes && features.neon;
@@ -78,6 +84,7 @@ instruction set (e.g., `g++ -mavx`) and sets `has_avx` accordingly.
#include <stdbool.h>
#include "cpuinfo_x86.h"
+// For C++, add `using namespace CpuFeatures;`
static const X86Features features = GetX86Info().features;
static const bool has_avx = CPU_FEATURES_COMPILED_X86_AVX || features.avx;
@@ -100,6 +107,7 @@ set&mdash;but only if it's not Sandy Bridge.
#include <stdbool.h>
#include "cpuinfo_x86.h"
+// For C++, add `using namespace CpuFeatures;`
static const X86Info info = GetX86Info();
static const X86Microarchitecture uarch = GetX86Microarchitecture(&info);
static const bool has_fast_avx = info.features.avx && uarch != INTEL_SNB;