Commit 7870e06c authored by s_kleplj's avatar s_kleplj
Browse files

.

parent 17a1e97a
#ifndef bsearchsol_hpp_
#define bsearchsol_hpp_
#define USE_AVX
#include <algorithm>
#include <cstdint>
#include <utility>
#include <limits>
#include <iostream>
#include <vector>
#include <immintrin.h>
......@@ -61,18 +60,6 @@ struct policy_data {
static constexpr std::size_t pack_size = sizeof(data_packed) / sizeof(data_element);
};
template<typename policy, std::size_t size>
struct get_jump_long {
private:
static constexpr std::size_t pack_size = policy_data<policy>::pack_size;
public:
using value_type = std::size_t;
static constexpr value_type value =
size > pack_size
? get_jump_long<policy, size / pack_size>::value * pack_size + pack_size
: 0;
};
template<typename policy, std::size_t size>
struct get_jump {
private:
......@@ -81,7 +68,7 @@ public:
using value_type = std::size_t;
static constexpr value_type value =
size > pack_size * pack_size
? get_jump_long<policy, size / pack_size>::value * pack_size + pack_size
? get_jump<policy, size / pack_size>::value * pack_size + pack_size
: size / pack_size;
};
......@@ -159,7 +146,7 @@ class bsearch_inner {
private:
template<std::size_t size>
static std::size_t constexpr _find(const data_element* offset, const std::size_t accumulator, const data_element num);
static std::size_t _find(const data_element* offset, const std::size_t accumulator, const data_element num);
std::vector<data_element> structure;
std::size_t isize;
......@@ -167,16 +154,16 @@ class bsearch_inner {
template<typename policy>
template<std::size_t size>
inline constexpr std::size_t bsearch_inner<policy>::_find(const data_element* offset, std::size_t accumulator, const data_element num)
inline std::size_t bsearch_inner<policy>::_find(const data_element* offset, std::size_t accumulator, const data_element num)
{
return 0;
}
template<>
template<std::size_t size>
inline constexpr std::size_t bsearch_inner<policy_sse>::_find(const data_element* offset, const std::size_t accumulator, const data_element num)
inline std::size_t bsearch_inner<policy_sse>::_find(const data_element* offset, const std::size_t accumulator, const data_element num)
{
const auto tmp = ~_mm_movemask_epi8(_mm_cmplt_epi32(_mm_set1_epi32(num), _mm_loadu_si128((data_packed*)offset)));
const auto tmp = ~_mm_movemask_epi8(_mm_cmplt_epi32(_mm_set1_epi32(num), _mm_lddq_si128((data_packed*)offset)));
const std::size_t jump = _mm_popcnt_u32(tmp & 0xFFFF) >> 2;
if constexpr (next_size<policy_sse,size>::value == 1) {
return accumulator + jump;
......@@ -197,7 +184,7 @@ template<>
template<std::size_t size>
inline std::size_t bsearch_inner<policy_avx>::_find(const data_element* offset, const std::size_t accumulator, const data_element num)
{
const auto tmp = ~_mm256_movemask_epi8(_mm256_cmpgt_epi32(_mm256_loadu_si256((data_packed*)offset), _mm256_set1_epi32(num)));
const auto tmp = ~_mm256_movemask_epi8(_mm256_cmpgt_epi32(_mm256_lddqu_si256((data_packed*)offset), _mm256_set1_epi32(num)));
const std::size_t jump = _mm_popcnt_u32(tmp) >> 2;
if constexpr (next_size<policy_avx,size>::value == 1) {
return accumulator + jump;
......@@ -212,6 +199,7 @@ inline std::size_t bsearch_inner<policy_avx>::_find(const data_element* offset,
}
}
}
template<>
template<>
inline std::size_t bsearch_inner<policy_avx>::_find<4>(const data_element* offset, const std::size_t accumulator, const data_element num)
......@@ -224,7 +212,11 @@ template<>
template<>
inline std::size_t bsearch_inner<policy_avx>::_find<2>(const data_element* offset, const std::size_t accumulator, const data_element num)
{
return 0;
return accumulator + (*offset<=num
? *(offset+1) <= num
? 2
: 1
: 0);
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment