Skip to content

Commit e2f5351

Browse files
committed
Document containers (esp. Vc::span)
Signed-off-by: Matthias Kretz <[email protected]>
1 parent 7182f0d commit e2f5351

File tree

7 files changed

+92
-7
lines changed

7 files changed

+92
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The documentation is generated via [doxygen](http://doxygen.org). You can build
112112
the documentation by running `doxygen` in the `doc` subdirectory.
113113
Alternatively, you can find nightly builds of the documentation at:
114114

115-
* [master branch](https://web-docs.gsi.de/~mkretz/Vc-master/)
115+
* [1.3 branch](https://web-docs.gsi.de/~mkretz/Vc-1.3/)
116116
* [1.3.0 release](https://web-docs.gsi.de/~mkretz/Vc-1.3.0/)
117117
* [1.2.0 release](https://web-docs.gsi.de/~mkretz/Vc-1.2.0/)
118118
* [1.1.0 release](https://web-docs.gsi.de/~mkretz/Vc-1.1.0/)

common/interleavedmemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct InterleavedMemoryAccess : public InterleavedMemoryReadAccess<StructSize,
171171
* members inside the struct.
172172
*
173173
* \see operator[]
174-
* \ingroup Utilities
174+
* \ingroup Containers
175175
* \headerfile interleavedmemory.h <Vc/Memory>
176176
*/
177177
template<typename S, typename V> class InterleavedMemoryWrapper

common/memory.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ template<typename V, size_t Size> struct _MemorySizeCalculation
118118
};
119119

120120
/**
121-
* \ingroup Utilities
121+
* \ingroup Containers
122122
* \headerfile memory.h <Vc/Memory>
123123
*
124124
* A helper class for fixed-size two-dimensional arrays.
@@ -282,7 +282,7 @@ class Memory : public AlignedBase<V::MemoryAlignment>,
282282
*
283283
* \see Memory<V, 0u>
284284
*
285-
* \ingroup Utilities
285+
* \ingroup Containers
286286
* \headerfile memory.h <Vc/Memory>
287287
*/
288288
template <typename V, size_t Size, bool InitPadding>
@@ -451,7 +451,7 @@ class Memory<V, Size, 0u, InitPadding> :
451451
*
452452
* \see Memory<V, Size>
453453
*
454-
* \ingroup Utilities
454+
* \ingroup Containers
455455
* \headerfile memory.h <Vc/Memory>
456456
*/
457457
template<typename V> class Memory<V, 0u, 0u, true> : public MemoryBase<V, Memory<V, 0u, 0u, true>, 1, void>

common/span.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,28 @@ span(const Container&)->span<const typename Container::value_type>;
609609

610610
} // namespace Common
611611

612+
/**
613+
* \ingroup Containers
614+
* \headerfile span.h <Vc/span>
615+
*
616+
* An adapted `std::span` with additional subscript operators supporting gather and scatter operations.
617+
*
618+
* The [std::span](https://en.cppreference.com/w/cpp/container/span) documentation applies.
619+
*
620+
* Example:
621+
* \code
622+
* struct Point {
623+
* float x, y;
624+
* };
625+
* Point data[100];
626+
* // initialize values in data
627+
*
628+
* Vc::span<Point, 100> view(data);
629+
* float_v::IndexType indexes = ...; // values between 0-99
630+
* float_v x = view[indexes][&Point::x];
631+
* float_v y = view[indexes][&Point::y];
632+
* \endcode
633+
*/
612634
template <typename T, ptrdiff_t Extent>
613635
using span = Common::AdaptSubscriptOperator<Common::span<T, Extent>>;
614636

doc/dox.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This documentation is structured in three main areas:
5555
\li \ref Simdize
5656
\li \ref Math
5757
\li \ref Utilities
58+
\li \ref Containers
5859
5960
3. The *Indexes* section contains automatically generated indexes to the same API
6061
documentation.
@@ -444,7 +445,7 @@ If your project does not use CMake all you need to do is the following:
444445
\defgroup Simdize simdize<T>
445446
\defgroup Math Math
446447
\defgroup Utilities Utilities
447-
448+
\defgroup Containers Containers
448449
449450
\addtogroup Vectors
450451
@@ -512,6 +513,27 @@ Additional classes, macros, and functions that help to work more easily with the
512513
types.
513514
514515
516+
\addtogroup Containers
517+
518+
For some problems, standard (or third-party) containers can be used.
519+
Simply use a `value_type` of `Vc::Vector<T>`.
520+
However, this requires:
521+
\li You actually have control over the data structures and can design/modify them for easy
522+
vectorization usage.
523+
\li The access patterns are non-random. Because random access to individual `value_type`
524+
\em elements is going to be a pain (two subscripts, first into the container, then
525+
into the `Vc::Vector`)
526+
527+
Therefore, for some problems you need to work with containers over elements of
528+
non-`Vector` type (e.g. of type `double` or a `struct`).
529+
Vc provides some help:
530+
\li Vc::vector
531+
\li Vc::array
532+
\li Vc::span
533+
\li Vc::Common::Memory (discouraged)
534+
\li Vc::Common::InterleavedMemoryWrapper
535+
536+
515537
\addtogroup Math
516538
517539
Functions that implement math functions. Take care that some of the implementations will return

include/Vc/array

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4646

4747
namespace Vc_VERSIONED_NAMESPACE
4848
{
49+
/**
50+
* \ingroup Containers
51+
* This is `std::array` with additional subscript operators supporting gather and scatter operations.
52+
*
53+
* The [std::array](https://en.cppreference.com/w/cpp/container/array) documentation applies.
54+
*
55+
* Gathers from structured data (AoS: arrays of struct) are possible via a special
56+
* subscript operator.
57+
* Example:
58+
* \code
59+
* Vc::array<float, 100> data;
60+
* std::iota(data.begin(), data.end(), 0.f); // fill with values 0, 1, 2, ...
61+
* auto indexes = float_v::IndexType::IndexesFromZero();
62+
* float_v gathered = data[indexes]; // gathered == [0, 1, 2, ...]
63+
* \endcode
64+
*
65+
* This also works for gathers into arrays of structures:
66+
* \code
67+
* struct Point { float x, y, z; };
68+
* Vc::array<Point, 100> points;
69+
* // fill points ...
70+
* auto indexes = float_v::IndexType::IndexesFromZero();
71+
* float_v xs = data[indexes][&Point::x]; // [points[0].x, points[1].x, points[2].x, ...]
72+
* float_v ys = data[indexes][&Point::y]; // [points[0].y, points[1].y, points[2].y, ...]
73+
* float_v zs = data[indexes][&Point::z]; // [points[0].z, points[1].z, points[2].z, ...]
74+
* \endcode
75+
*
76+
* Arrays may also be nested:
77+
* \code:
78+
* Vc::array<Vc::array<float, 3>, 100> points;
79+
* // fill points ...
80+
* auto indexes = float_v::IndexType::IndexesFromZero();
81+
* float_v xs = data[indexes][0]; // [points[0][0], points[1][0], points[2][0], ...]
82+
* float_v ys = data[indexes][1]; // [points[0][1], points[1][1], points[2][1], ...]
83+
* float_v zs = data[indexes][2]; // [points[0][2], points[1][2], points[2][2], ...]
84+
* \endcode
85+
*/
4986
template <class T, size_t Size> struct array {
5087
// types:
5188
typedef array self_;

include/Vc/vector

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@
3030
namespace Vc_VERSIONED_NAMESPACE
3131
{
3232
/**
33-
* \ingroup Utilities
33+
* \ingroup Containers
34+
* \headerfile vector <Vc/vector>
35+
*
3436
* An adapted `std::vector` container with an additional subscript operator which
3537
* implements gather and scatter operations.
3638
*
39+
* The [std::vector](https://en.cppreference.com/w/cpp/container/vector) documentation applies.
40+
*
3741
* Example:
3842
* \code
3943
* struct Point {

0 commit comments

Comments
 (0)