1.0.2 API documentation: compute_vector_decl.hpp Source File

| 1.0.2 API documentation

compute_vector_decl.hpp
1
2 #pragma once
3 #include <functional>
4 #include "_vectorize.hpp"
5
6 namespace glm {
7 namespace detail
8 {
9 template<length_t L, typename T, qualifier Q, bool UseSimd>
10 struct compute_vec_add {};
11
12 template<length_t L, typename T, qualifier Q, bool UseSimd>
13 struct compute_vec_sub {};
14
15 template<length_t L, typename T, qualifier Q, bool UseSimd>
16 struct compute_vec_mul {};
17
18 template<length_t L, typename T, qualifier Q, bool UseSimd>
19 struct compute_vec_div {};
20
21 template<length_t L, typename T, qualifier Q, bool UseSimd>
22 struct compute_vec_mod {};
23
24 template<length_t L, typename T, qualifier Q, bool UseSimd>
25 struct compute_splat {};
26
27 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
28 struct compute_vec_and {};
29
30 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
31 struct compute_vec_or {};
32
33 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
34 struct compute_vec_xor {};
35
36 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
37 struct compute_vec_shift_left {};
38
39 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
40 struct compute_vec_shift_right {};
41
42 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
43 struct compute_vec_equal {};
44
45 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
46 struct compute_vec_nequal {};
47
48 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size, bool UseSimd>
49 struct compute_vec_bitwise_not {};
50
51 template<length_t L, typename T, qualifier Q>
52 struct compute_vec_add<L, T, Q, false>
53 {
54 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
55 {
56 return detail::functor2<vec, L, T, Q>::call(std::plus<T>(), a, b);
57 }
58 };
59
60 template<length_t L, typename T, qualifier Q>
61 struct compute_vec_sub<L, T, Q, false>
62 {
63 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
64 {
65 return detail::functor2<vec, L, T, Q>::call(std::minus<T>(), a, b);
66 }
67 };
68
69 template<length_t L, typename T, qualifier Q>
70 struct compute_vec_mul<L, T, Q, false>
71 {
72 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
73 {
74 return detail::functor2<vec, L, T, Q>::call(std::multiplies<T>(), a, b);
75 }
76 };
77
78 template<length_t L, typename T, qualifier Q>
79 struct compute_vec_div<L, T, Q, false>
80 {
81 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
82 {
83 return detail::functor2<vec, L, T, Q>::call(std::divides<T>(), a, b);
84 }
85 };
86
87 template<length_t L, typename T, qualifier Q>
88 struct compute_vec_mod<L, T, Q, false>
89 {
90 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
91 {
92 return detail::functor2<vec, L, T, Q>::call(std::modulus<T>(), a, b);
93 }
94 };
95
96 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
97 struct compute_vec_and<L, T, Q, IsInt, Size, false>
98 {
99 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
100 {
101 vec<L, T, Q> v(a);
102 for (length_t i = 0; i < L; ++i)
103 v[i] &= static_cast<T>(b[i]);
104 return v;
105 }
106 };
107
108 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
109 struct compute_vec_or<L, T, Q, IsInt, Size, false>
110 {
111 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
112 {
113 vec<L, T, Q> v(a);
114 for (length_t i = 0; i < L; ++i)
115 v[i] |= static_cast<T>(b[i]);
116 return v;
117 }
118 };
119
120 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
121 struct compute_vec_xor<L, T, Q, IsInt, Size, false>
122 {
123 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
124 {
125 vec<L, T, Q> v(a);
126 for (length_t i = 0; i < L; ++i)
127 v[i] ^= static_cast<T>(b[i]);
128 return v;
129 }
130 };
131
132 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
133 struct compute_vec_shift_left<L, T, Q, IsInt, Size, false>
134 {
135 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
136 {
137 vec<L, T, Q> v(a);
138 for (length_t i = 0; i < L; ++i)
139 v[i] <<= static_cast<T>(b[i]);
140 return v;
141 }
142 };
143
144 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
145 struct compute_vec_shift_right<L, T, Q, IsInt, Size, false>
146 {
147 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
148 {
149 vec<L, T, Q> v(a);
150 for (length_t i = 0; i < L; ++i)
151 v[i] >>= static_cast<T>(b[i]);
152 return v;
153 }
154 };
155
156 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
157 struct compute_vec_equal<L, T, Q, IsInt, Size, false>
158 {
159 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(vec<L, T, Q> const& v1, vec<L, T, Q> const& v2)
160 {
161 bool b = true;
162 for (length_t i = 0; b && i < L; ++i)
163 b = detail::compute_equal<T, std::numeric_limits<T>::is_iec559>::call(v1[i], v2[i]);
164 return b;
165 }
166 };
167
168 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
169 struct compute_vec_nequal<L, T, Q, IsInt, Size, false>
170 {
171 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2)
172 {
173 return !compute_vec_equal<L, T, Q, detail::is_int<T>::value, sizeof(T) * 8, detail::is_aligned<Q>::value>::call(v1, v2);
174 }
175 };
176
177 template<length_t L, typename T, qualifier Q, int IsInt, std::size_t Size>
178 struct compute_vec_bitwise_not<L, T, Q, IsInt, Size, false>
179 {
180 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(vec<L, T, Q> const& a)
181 {
182 vec<L, T, Q> v(a);
183 for (length_t i = 0; i < L; ++i)
184 v[i] = ~v[i];
185 return v;
186 }
187 };
188
189 }
190 }