14#include "common/math/simd_util.h"
17#include "storage/common/column.h"
22 static inline bool operation(
const T &left,
const T &right)
27 static inline __m256 operation(
const __m256 &left,
const __m256 &right)
29 return _mm256_cmp_ps(left, right, _CMP_EQ_OS);
32 static inline __m256i operation(
const __m256i &left,
const __m256i &right) {
return _mm256_cmpeq_epi32(left, right); }
38 static inline bool operation(
const T &left,
const T &right)
43 static inline __m256 operation(
const __m256 &left,
const __m256 &right)
45 return _mm256_cmp_ps(left, right, _CMP_NEQ_OS);
48 static inline __m256i operation(
const __m256i &left,
const __m256i &right)
50 return _mm256_xor_si256(_mm256_set1_epi32(-1), _mm256_cmpeq_epi32(left, right));
58 static inline bool operation(
const T &left,
const T &right)
63 static inline __m256 operation(
const __m256 &left,
const __m256 &right)
65 return _mm256_cmp_ps(left, right, _CMP_GT_OS);
68 static inline __m256i operation(
const __m256i &left,
const __m256i &right) {
return _mm256_cmpgt_epi32(left, right); }
75 static inline bool operation(
const T &left,
const T &right)
81 static inline __m256 operation(
const __m256 &left,
const __m256 &right)
83 return _mm256_cmp_ps(left, right, _CMP_GE_OS);
86 static inline __m256i operation(
const __m256i &left,
const __m256i &right)
88 return _mm256_cmpgt_epi32(left, right) | _mm256_cmpeq_epi32(left, right);
96 static inline bool operation(
const T &left,
const T &right)
101 static inline __m256 operation(
const __m256 &left,
const __m256 &right)
103 return _mm256_cmp_ps(left, right, _CMP_LT_OS);
106 static inline __m256i operation(
const __m256i &left,
const __m256i &right) {
return _mm256_cmpgt_epi32(right, left); }
113 static inline bool operation(
const T &left,
const T &right)
115 return left <= right;
118 static inline __m256 operation(
const __m256 &left,
const __m256 &right)
120 return _mm256_cmp_ps(left, right, _CMP_LE_OS);
123 static inline __m256i operation(
const __m256i &left,
const __m256i &right)
125 return _mm256_or_si256(_mm256_cmpgt_epi32(right, left), _mm256_cmpeq_epi32(left, right));
133 static inline T operation(T left, T right)
139 static inline __m256 operation(__m256 left, __m256 right) {
return _mm256_add_ps(left, right); }
141 static inline __m256i operation(__m256i left, __m256i right) {
return _mm256_add_epi32(left, right); }
148 static inline T operation(T left, T right)
154 static inline __m256 operation(__m256 left, __m256 right) { exit(-1); }
156 static inline __m256i operation(__m256i left, __m256i right) { exit(-1); }
163 static inline T operation(T left, T right)
169 static inline __m256 operation(__m256 left, __m256 right) { exit(-1); }
171 static inline __m256i operation(__m256i left, __m256i right) { exit(-1); }
178 static inline T operation(T left, T right)
185 static inline __m256 operation(__m256 left, __m256 right) {
return _mm256_div_ps(left, right); }
186 static inline __m256i operation(__m256i left, __m256i right)
189 __m256 left_float = _mm256_cvtepi32_ps(left);
190 __m256 right_float = _mm256_cvtepi32_ps(right);
191 __m256 result_float = _mm256_div_ps(left_float, right_float);
192 return _mm256_cvttps_epi32(result_float);
201 static inline T operation(T input)
207template <
typename T,
bool LEFT_CONSTANT,
bool RIGHT_CONSTANT,
class OP>
208void compare_operation(T *left, T *right,
int n, vector<uint8_t> &result)
212 if constexpr (is_same<T, float>::value) {
213 for (; i <= n - SIMD_WIDTH; i += SIMD_WIDTH) {
214 __m256 left_value, right_value;
216 if constexpr (LEFT_CONSTANT) {
217 left_value = _mm256_set1_ps(left[0]);
219 left_value = _mm256_loadu_ps(&left[i]);
222 if constexpr (RIGHT_CONSTANT) {
223 right_value = _mm256_set1_ps(right[0]);
225 right_value = _mm256_loadu_ps(&right[i]);
228 __m256 result_values = OP::operation(left_value, right_value);
229 __m256i mask = _mm256_castps_si256(result_values);
231 for (
int j = 0; j < SIMD_WIDTH; j++) {
232 result[i + j] &= mm256_extract_epi32_var_indx(mask, j) ? 1 : 0;
235 }
else if constexpr (is_same<T, int>::value) {
236 for (; i <= n - SIMD_WIDTH; i += SIMD_WIDTH) {
237 __m256i left_value, right_value;
240 left_value = _mm256_set1_epi32(left[0]);
242 left_value = _mm256_loadu_si256((__m256i *)&left[i]);
245 if (RIGHT_CONSTANT) {
246 right_value = _mm256_set1_epi32(right[0]);
248 right_value = _mm256_loadu_si256((__m256i *)&right[i]);
251 __m256i result_values = OP::operation(left_value, right_value);
253 for (
int j = 0; j < SIMD_WIDTH; j++) {
254 result[i + j] &= mm256_extract_epi32_var_indx(result_values, j) ? 1 : 0;
260 auto &left_value = left[LEFT_CONSTANT ? 0 : i];
261 auto &right_value = right[RIGHT_CONSTANT ? 0 : i];
262 result[i] &= OP::operation(left_value, right_value) ? 1 : 0;
265 for (
int i = 0; i < n; i++) {
266 auto &left_value = left[LEFT_CONSTANT ? 0 : i];
267 auto &right_value = right[RIGHT_CONSTANT ? 0 : i];
268 result[i] &= OP::operation(left_value, right_value) ? 1 : 0;
273template <
bool LEFT_CONSTANT,
bool RIGHT_CONSTANT,
typename T,
class OP>
274void binary_operator(T *left_data, T *right_data, T *result_data,
int size)
279 if constexpr (is_same<T, float>::value) {
280 for (; i <= size - SIMD_WIDTH; i += SIMD_WIDTH) {
281 __m256 left_value, right_value;
284 left_value = _mm256_set1_ps(left_data[0]);
286 left_value = _mm256_loadu_ps(&left_data[i]);
289 if (RIGHT_CONSTANT) {
290 right_value = _mm256_set1_ps(right_data[0]);
292 right_value = _mm256_loadu_ps(&right_data[i]);
295 __m256 result_value = OP::operation(left_value, right_value);
296 _mm256_storeu_ps(&result_data[i], result_value);
298 }
else if constexpr (is_same<T, int>::value) {
299 for (; i <= size - SIMD_WIDTH; i += SIMD_WIDTH) {
300 __m256i left_value, right_value;
303 left_value = _mm256_set1_epi32(left_data[0]);
305 left_value = _mm256_loadu_si256((
const __m256i *)&left_data[i]);
308 if (RIGHT_CONSTANT) {
309 right_value = _mm256_set1_epi32(right_data[0]);
311 right_value = _mm256_loadu_si256((
const __m256i *)&right_data[i]);
314 __m256i result_value = OP::operation(left_value, right_value);
315 _mm256_storeu_si256((__m256i *)&result_data[i], result_value);
320 for (; i < size; i++) {
321 auto &left_value = left_data[LEFT_CONSTANT ? 0 : i];
322 auto &right_value = right_data[RIGHT_CONSTANT ? 0 : i];
323 result_data[i] = OP::template operation<T>(left_value, right_value);
326 for (
int i = 0; i < size; i++) {
327 auto &left_value = left_data[LEFT_CONSTANT ? 0 : i];
328 auto &right_value = right_data[RIGHT_CONSTANT ? 0 : i];
329 result_data[i] = OP::template operation<T>(left_value, right_value);
334template <
bool CONSTANT,
typename T,
class OP>
335void unary_operator(T *input, T *result_data,
int size)
337 for (
int i = 0; i < size; i++) {
338 auto &value = input[CONSTANT ? 0 : i];
339 result_data[i] = OP::template operation<T>(value);
344template <
typename T,
bool LEFT_CONSTANT,
bool RIGHT_CONSTANT>
345void compare_result(T *left, T *right,
int n, vector<uint8_t> &result,
CompOp op)
349 compare_operation<T, LEFT_CONSTANT, RIGHT_CONSTANT, Equal>(left, right, n, result);
353 compare_operation<T, LEFT_CONSTANT, RIGHT_CONSTANT, NotEqual>(left, right, n, result);
357 compare_operation<T, LEFT_CONSTANT, RIGHT_CONSTANT, GreatEqual>(left, right, n, result);
361 compare_operation<T, LEFT_CONSTANT, RIGHT_CONSTANT, GreatThan>(left, right, n, result);
365 compare_operation<T, LEFT_CONSTANT, RIGHT_CONSTANT, LessEqual>(left, right, n, result);
369 compare_operation<T, LEFT_CONSTANT, RIGHT_CONSTANT, LessThan>(left, right, n, result);
CompOp
描述比较运算符
Definition: parse_defs.h:46
@ GREAT_EQUAL
">="
Definition: parse_defs.h:51
@ LESS_THAN
"<"
Definition: parse_defs.h:50
@ EQUAL_TO
"="
Definition: parse_defs.h:47
@ LESS_EQUAL
"<="
Definition: parse_defs.h:48
@ GREAT_THAN
">"
Definition: parse_defs.h:52
@ NOT_EQUAL
"<>"
Definition: parse_defs.h:49
Definition: arithmetic_operator.hpp:131
Definition: arithmetic_operator.hpp:176
Definition: arithmetic_operator.hpp:20
Definition: arithmetic_operator.hpp:73
Definition: arithmetic_operator.hpp:56
Definition: arithmetic_operator.hpp:111
Definition: arithmetic_operator.hpp:94
Definition: arithmetic_operator.hpp:161
Definition: arithmetic_operator.hpp:199
Definition: arithmetic_operator.hpp:36
Definition: arithmetic_operator.hpp:146