1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
# libdivide C++ API
The entire content of ```libdivide.h``` is wrapped inside the ```libdivide``` namespace,
for clarity the ```libdivide``` namespace is omitted in the code sections below.
## divider class
```C++
// This is the main divider class for use by the user (C++ API).
// The actual division algorithm is selected using the dispatcher struct
// based on the integer and algorithm template parameters.
template<typename T, Branching ALGO = BRANCHFULL>
class divider {
public:
// Generate a libdivide divisor for d
divider(T d);
// Recover the original divider
T recover() const;
bool operator==(const divider<T, ALGO>& other) const;
bool operator!=(const divider<T, ALGO>& other) const;
// ...
private:
// Storage for the actual divisor
dispatcher<T, ALGO> div;
};
```
## branchfree_divider
```branchfree_divider``` is a convenience typedef which redirects to the divider class:
```C++
template <typename T>
using branchfree_divider = divider<T, BRANCHFREE>;
```
## Operator ```/``` and ```/=```
```C++
// Overload of operator /
template<typename T, Branching ALGO>
T operator/(T n, const divider<T, ALGO>& div);
// Overload of operator /=
template<typename T, Branching ALGO>
T& operator/=(T& n, const divider<T, ALGO>& div);
```
## NEON vector division
```C++
// Overload of operator /
template <Branching ALGO>
uint32x4_t operator/(uint32x4_t n, const divider<uint32_t, ALGO> &div)
template <Branching ALGO>
int32x4_t operator/(int32x4_t n, const divider<int32_t, ALGO> &div)
template <Branching ALGO>
uint64x2_t operator/(uint64x2_t n, const divider<uint64_t, ALGO> &div)
template <Branching ALGO>
int64x2_t operator/(int64x2_t n, const divider<int64_t, ALGO> &div)
// Overload of operator /=
template <Branching ALGO>
uint32x4_t operator/=(uint32x4_t &n, const divider<uint32_t, ALGO> &div)
template <Branching ALGO>
int32x4_t operator/=(int32x4_t &n, const divider<int32_t, ALGO> &div)
template <Branching ALGO>
uint64x2_t operator/=(uint64x2_t &n, const divider<uint64_t, ALGO> &div);
template <Branching ALGO>
int64x2_t operator/=(int64x2_t &n, const divider<int64_t, ALGO> &div)
```
You need to define ```LIBDIVIDE_NEON``` to enable SSE2 vector division.
## SSE2 vector division
```C++
// Overload of operator /
template<typename T, Branching ALGO>
__m128i operator/(__m128i n, const divider<T, ALGO>& div);
// Overload of operator /=
template<typename T, Branching ALGO>
__m128i& operator/=(__m128i& n, const divider<T, ALGO>& div);
```
You need to define ```LIBDIVIDE_SSE2``` to enable SSE2 vector division.
## AVX2 vector division
```C++
// Overload of operator /
template<typename T, Branching ALGO>
__m256i operator/(__m256i n, const divider<T, ALGO>& div);
// Overload of operator /=
template<typename T, Branching ALGO>
__m256i& operator/=(__m256i& n, const divider<T, ALGO>& div);
```
You need to define ```LIBDIVIDE_AVX2``` to enable AVX2 vector division.
## AVX512 vector division
```C++
// Overload of operator /
template<typename T, Branching ALGO>
__m512i operator/(__m512i n, const divider<T, ALGO>& div);
// Overload of operator /=
template<typename T, Branching ALGO>
__m512i& operator/=(__m512i& n, const divider<T, ALGO>& div);
```
You need to define ```LIBDIVIDE_AVX512``` to enable AVX512 vector division.
|