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