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
18namespace simdpp {
19namespace 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*/
26template<unsigned N, class E> SIMDPP_INL
27mask_int8<N,expr_empty> to_mask(const int8<N,E>& a)
28{
29 return detail::insn::i_to_mask(uint8<N>(a.eval()));
30}
31template<unsigned N, class E> SIMDPP_INL
32mask_int8<N,expr_empty> to_mask(const uint8<N,E>& a)
33{
34 return detail::insn::i_to_mask(a.eval());
35}
36template<unsigned N, class E> SIMDPP_INL
37mask_int16<N,expr_empty> to_mask(const int16<N,E>& a)
38{
39 return detail::insn::i_to_mask(uint16<N>(a.eval()));
40}
41template<unsigned N, class E> SIMDPP_INL
42mask_int16<N,expr_empty> to_mask(const uint16<N,E>& a)
43{
44 return detail::insn::i_to_mask(a.eval());
45}
46template<unsigned N, class E> SIMDPP_INL
47mask_int32<N,expr_empty> to_mask(const int32<N,E>& a)
48{
49 return detail::insn::i_to_mask(uint32<N>(a.eval()));
50}
51template<unsigned N, class E> SIMDPP_INL
52mask_int32<N,expr_empty> to_mask(const uint32<N,E>& a)
53{
54 return detail::insn::i_to_mask(a.eval());
55}
56template<unsigned N, class E> SIMDPP_INL
57mask_int64<N,expr_empty> to_mask(const int64<N,E>& a)
58{
59 return detail::insn::i_to_mask(uint64<N>(a.eval()));
60}
61template<unsigned N, class E> SIMDPP_INL
62mask_int64<N,expr_empty> to_mask(const uint64<N,E>& a)
63{
64 return detail::insn::i_to_mask(a.eval());
65}
66template<unsigned N, class E> SIMDPP_INL
67mask_float32<N,expr_empty> to_mask(const float32<N,E>& a)
68{
69 return detail::insn::i_to_mask(a.eval());
70}
71template<unsigned N, class E> SIMDPP_INL
72mask_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