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_POPCNT_H
9#define LIBSIMDPP_SIMDPP_CORE_I_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_popcnt.h>
17
18namespace simdpp {
19namespace SIMDPP_ARCH_NAMESPACE {
20
21/** Computes the population count of elements in the vector.
22
23 @code
24 r0 = popcnt(a0)
25 r1 = popcnt(a1)
26 ...
27 rN = popcnt(aN)
28 @endcode
29*/
30template<unsigned N, class E> SIMDPP_INL
31int8<N,expr_empty> popcnt(const int8<N,E>& a)
32{
33 return detail::insn::i_popcnt(uint8<N>(a.eval()));
34}
35
36template<unsigned N, class E> SIMDPP_INL
37uint8<N,expr_empty> popcnt(const uint8<N,E>& a)
38{
39 return detail::insn::i_popcnt(a.eval());
40}
41
42template<unsigned N, class E> SIMDPP_INL
43int16<N,expr_empty> popcnt(const int16<N,E>& a)
44{
45 return detail::insn::i_popcnt(uint16<N>(a.eval()));
46}
47
48template<unsigned N, class E> SIMDPP_INL
49uint16<N,expr_empty> popcnt(const uint16<N,E>& a)
50{
51 return detail::insn::i_popcnt(a.eval());
52}
53
54template<unsigned N, class E> SIMDPP_INL
55int32<N,expr_empty> popcnt(const int32<N,E>& a)
56{
57 return detail::insn::i_popcnt(uint32<N>(a.eval()));
58}
59
60template<unsigned N, class E> SIMDPP_INL
61uint32<N,expr_empty> popcnt(const uint32<N,E>& a)
62{
63 return detail::insn::i_popcnt(a.eval());
64}
65
66template<unsigned N, class E> SIMDPP_INL
67int64<N,expr_empty> popcnt(const int64<N,E>& a)
68{
69 return detail::insn::i_popcnt(uint64<N>(a.eval()));
70}
71
72template<unsigned N, class E> SIMDPP_INL
73uint64<N,expr_empty> popcnt(const uint64<N,E>& a)
74{
75 return detail::insn::i_popcnt(a.eval());
76}
77
78} // namespace SIMDPP_ARCH_NAMESPACE
79} // namespace simdpp
80
81#endif
82
83