Skip to content

Commit 6bc3405

Browse files
jan-wassenbergcopybara-github
authored andcommitted
documentation clarifications on dynamic dispatch/HWY_ATTR. Refs #1005
PiperOrigin-RevId: 481620845
1 parent 9cbed31 commit 6bc3405

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ Due to ADL restrictions, user code calling Highway ops must either:
167167
hn::Add()`; or
168168
* add using-declarations for each op used: `using hwy::HWY_NAMESPACE::Add;`.
169169

170-
Additionally, each function that calls Highway ops must either be prefixed with
171-
`HWY_ATTR`, OR reside between `HWY_BEFORE_NAMESPACE()` and
170+
Additionally, each function that calls Highway ops (such as `Load`) must either
171+
be prefixed with `HWY_ATTR`, OR reside between `HWY_BEFORE_NAMESPACE()` and
172172
`HWY_AFTER_NAMESPACE()`. Lambda functions currently require `HWY_ATTR` before
173173
their opening brace.
174174

@@ -190,6 +190,27 @@ they use static or dynamic dispatch.
190190
[quick-reference](g3doc/quick_reference.md)) if `HWY_TARGET_INCLUDE` is
191191
defined and `foreach_target.h` is included.
192192

193+
When using dynamic dispatch, `foreach_target.h` is included from translation
194+
units (.cc files), not headers. Headers containing vector code shared between
195+
several translation units require a special include guard, for example the
196+
following taken from `examples/skeleton-inl.h`:
197+
198+
```
199+
#if defined(HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_) == defined(HWY_TARGET_TOGGLE)
200+
#ifdef HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_
201+
#undef HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_
202+
#else
203+
#define HIGHWAY_HWY_EXAMPLES_SKELETON_INL_H_
204+
#endif
205+
206+
#include "hwy/highway.h"
207+
// Your vector code
208+
#endif
209+
```
210+
211+
By convention, we name such headers `-inl.h` because their contents (often
212+
function templates) are usually inlined.
213+
193214
## Compiler flags
194215

195216
Applications should be compiled with optimizations enabled - without inlining,

g3doc/quick_reference.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ The public headers are:
4949
* hwy/tests/test_util-inl.h: defines macros for invoking tests on all
5050
available targets, plus per-target functions useful in tests.
5151

52-
SIMD implementations must be preceded and followed by the following:
52+
Highway provides helper macros to simplify your vector code and ensure support
53+
for dynamic dispatch. To use these, add the following to the start and end of
54+
any vector code:
5355

5456
```
5557
#include "hwy/highway.h"
@@ -65,6 +67,10 @@ namespace HWY_NAMESPACE {
6567
HWY_AFTER_NAMESPACE();
6668
```
6769

70+
If you choose not to use the `BEFORE/AFTER` lines, you must prefix any function
71+
that calls Highway ops such as `Load` with `HWY_ATTR`. You can omit the
72+
`HWY_NAMESPACE` lines if not using dynamic dispatch.
73+
6874
## Notation in this doc
6975

7076
* `T` denotes the type of a vector lane (integer or floating-point);

0 commit comments

Comments
 (0)