1/* Copyright (C) 2017 Povilas Kanapickas <povilas@radix.lt>
2
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8#ifndef LIBSIMDPP_SIMDPP_CORE_I_REDUCE_POPCNT_H
9#define LIBSIMDPP_SIMDPP_CORE_I_REDUCE_POPCNT_H
10
11#ifndef LIBSIMDPP_SIMD_H
12 #error "This file must be included through simd.h"
13#endif
14
15#include <simdpp/types.h>
16#include <simdpp/detail/insn/i_reduce_popcnt.h>
17
18namespace simdpp {
19namespace SIMDPP_ARCH_NAMESPACE {
20
21
22/** Computes the population count of all values in the vector.
23
24 @code
25 result = popcnt(a0) + popcnt(a1) + ...
26 @endcode
27*/
28template<unsigned N, class E> SIMDPP_INL
29uint32_t reduce_popcnt(const int8<N,E>& a)
30{
31 return detail::insn::i_reduce_popcnt(uint32<N/4>(a.eval()));
32}
33
34template<unsigned N, class E> SIMDPP_INL
35uint32_t reduce_popcnt(const uint8<N,E>& a)
36{
37 return detail::insn::i_reduce_popcnt(uint32<N/4>(a.eval()));
38}
39
40template<unsigned N, class E> SIMDPP_INL
41uint32_t reduce_popcnt(const int16<N,E>& a)
42{
43 return detail::insn::i_reduce_popcnt(uint32<N/2>(a.eval()));
44}
45
46template<unsigned N, class E> SIMDPP_INL
47uint32_t reduce_popcnt(const uint16<N,E>& a)
48{
49 return detail::insn::i_reduce_popcnt(uint32<N/2>(a.eval()));
50}
51
52template<unsigned N, class E> SIMDPP_INL
53uint32_t reduce_popcnt(const int32<N,E>& a)
54{
55 return detail::insn::i_reduce_popcnt(uint32<N>(a.eval()));
56}
57
58template<unsigned N, class E> SIMDPP_INL
59uint32_t reduce_popcnt(const uint32<N,E>& a)
60{
61 return detail::insn::i_reduce_popcnt(a.eval());
62}
63
64template<unsigned N, class E> SIMDPP_INL
65uint32_t reduce_popcnt(const int64<N,E>& a)
66{
67 return detail::insn::i_reduce_popcnt(uint32<N*2>(a.eval()));
68}
69
70template<unsigned N, class E> SIMDPP_INL
71uint32_t reduce_popcnt(const uint64<N,E>& a)
72{
73 return detail::insn::i_reduce_popcnt(uint32<N*2>(a.eval()));
74}
75
76} // namespace SIMDPP_ARCH_NAMESPACE
77} // namespace simdpp
78
79#endif
80
81