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_TO_MASK_H
9 #define LIBSIMDPP_SIMDPP_CORE_TO_MASK_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/conv_to_mask.h>
17 
18 namespace simdpp {
19 namespace SIMDPP_ARCH_NAMESPACE {
20 
21 /** Converts a vector to mask.
22 
23     The values of the elements in the source vector must be either all ones
24     or all zeros. Otherwise the behavior is undefined.
25 */
26 template<unsigned N, class E> SIMDPP_INL
to_mask(const int8<N,E> & a)27 mask_int8<N,expr_empty> to_mask(const int8<N,E>& a)
28 {
29     return detail::insn::i_to_mask(uint8<N>(a.eval()));
30 }
31 template<unsigned N, class E> SIMDPP_INL
to_mask(const uint8<N,E> & a)32 mask_int8<N,expr_empty> to_mask(const uint8<N,E>& a)
33 {
34     return detail::insn::i_to_mask(a.eval());
35 }
36 template<unsigned N, class E> SIMDPP_INL
to_mask(const int16<N,E> & a)37 mask_int16<N,expr_empty> to_mask(const int16<N,E>& a)
38 {
39     return detail::insn::i_to_mask(uint16<N>(a.eval()));
40 }
41 template<unsigned N, class E> SIMDPP_INL
to_mask(const uint16<N,E> & a)42 mask_int16<N,expr_empty> to_mask(const uint16<N,E>& a)
43 {
44     return detail::insn::i_to_mask(a.eval());
45 }
46 template<unsigned N, class E> SIMDPP_INL
to_mask(const int32<N,E> & a)47 mask_int32<N,expr_empty> to_mask(const int32<N,E>& a)
48 {
49     return detail::insn::i_to_mask(uint32<N>(a.eval()));
50 }
51 template<unsigned N, class E> SIMDPP_INL
to_mask(const uint32<N,E> & a)52 mask_int32<N,expr_empty> to_mask(const uint32<N,E>& a)
53 {
54     return detail::insn::i_to_mask(a.eval());
55 }
56 template<unsigned N, class E> SIMDPP_INL
to_mask(const int64<N,E> & a)57 mask_int64<N,expr_empty> to_mask(const int64<N,E>& a)
58 {
59     return detail::insn::i_to_mask(uint64<N>(a.eval()));
60 }
61 template<unsigned N, class E> SIMDPP_INL
to_mask(const uint64<N,E> & a)62 mask_int64<N,expr_empty> to_mask(const uint64<N,E>& a)
63 {
64     return detail::insn::i_to_mask(a.eval());
65 }
66 template<unsigned N, class E> SIMDPP_INL
to_mask(const float32<N,E> & a)67 mask_float32<N,expr_empty> to_mask(const float32<N,E>& a)
68 {
69     return detail::insn::i_to_mask(a.eval());
70 }
71 template<unsigned N, class E> SIMDPP_INL
to_mask(const float64<N,E> & a)72 mask_float64<N,expr_empty> to_mask(const float64<N,E>& a)
73 {
74     return detail::insn::i_to_mask(a.eval());
75 }
76 
77 } // namespace SIMDPP_ARCH_NAMESPACE
78 } // namespace simdpp
79 
80 #endif
81 
82