IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
BoolMaskCast.h
Go to the documentation of this file.
1 // BoolMaskCast.h:
3 // ---------------
4 //
15 
16 #ifndef __IPSDKUTIL_INSTRUCTIONSET_DETAIL_BOOLMASKCAST_H__
17 #define __IPSDKUTIL_INSTRUCTIONSET_DETAIL_BOOLMASKCAST_H__
18 
19 #include <boost/core/enable_if.hpp>
20 #include <boost/type_traits/is_same.hpp>
21 #include <boost/mpl/and.hpp>
22 #include <boost/mpl/less.hpp>
23 #include <boost/mpl/greater.hpp>
24 #include <boost/mpl/equal_to.hpp>
25 #include <boost/mpl/sizeof.hpp>
26 #include <boost/mpl/plus.hpp>
27 #include <boost/mpl/not.hpp>
36 
37 namespace ipsdk {
38 namespace simd {
39 namespace detail {
40 
43 
44 
45 // template structure associated to cast function
46 template <eInstructionSet::domain IS,
47  typename TIn, typename TOut,
48  typename Enable = void>
49 struct BoolMaskCast;
50 
53 template <eInstructionSet::domain IS,
54  typename TIn, typename TOut>
55 struct BoolMaskCast<IS, TIn, TOut,
56  typename boost::enable_if<typename boost::is_same<TIn, TOut>::type>::type>
57 {
58  static IPSDK_FORCEINLINE void
59  act(const BasePack<IS2PackType<IS>::_packType, TIn>& in,
61  {
62  out = in;
63  }
64 };
65 
66 template <eInstructionSet::domain IS,
67  typename TIn, typename TOut>
68 struct BoolMaskCast<IS, TIn, TOut,
69  typename boost::enable_if<typename boost::mpl::and_<typename boost::is_integral<TIn>::type,
70  typename boost::is_integral<TOut>::type,
71  typename boost::mpl::not_<typename boost::is_same<TIn, TOut>::type>::type,
72  typename boost::mpl::equal_to<boost::mpl::sizeof_<TIn>,
73  boost::mpl::sizeof_<TOut> >::type>::type>::type>
74 {
75  static const ipUInt8 g_shiftFactor = 8 * (sizeof(TIn) - sizeof(TOut));
76 
77  static IPSDK_FORCEINLINE void
78  act(const BasePack<IS2PackType<IS>::_packType, TIn>& in,
80  {
81  cast<IS>(in, out);
82  }
83 };
84 
85 template <eInstructionSet::domain IS,
86  typename TOut>
87 struct BoolMaskCast<IS, ipReal32, TOut,
88  typename boost::enable_if<typename boost::is_integral<TOut>::type>::type>
89 {
90  static IPSDK_FORCEINLINE void
91  act(const BasePack<IS2PackType<IS>::_packType, ipReal32>& in,
92  BasePack<IS2PackType<IS>::_packType, TOut>& out)
93  {
94  BasePack<IS2PackType<IS>::_packType, ipUInt32> cvt;
95  bitwiseCast<IS>(in, cvt);
96  BoolMaskCast<IS, ipUInt32, TOut>::act(cvt, out);
97  }
98 };
99 
100 template <eInstructionSet::domain IS,
101  typename TIn>
102 struct BoolMaskCast<IS, TIn, ipReal32,
103  typename boost::enable_if<typename boost::is_integral<TIn>::type>::type>
104 {
105  static IPSDK_FORCEINLINE void
106  act(const BasePack<IS2PackType<IS>::_packType, TIn>& in,
107  BasePack<IS2PackType<IS>::_packType, ipReal32>& out)
108  {
109  BasePack<IS2PackType<IS>::_packType, ipUInt32> cvt;
110  BoolMaskCast<IS, TIn, ipUInt32>::act(in, cvt);
111  bitwiseCast<IS>(cvt, out);
112  }
113 };
114 
115 template <eInstructionSet::domain IS,
116  typename TIn, typename TOut>
117 struct BoolMaskCast<IS, TIn, TOut,
118  typename boost::enable_if<typename boost::mpl::and_<typename boost::is_integral<TIn>::type,
119  typename boost::is_integral<TOut>::type,
120  typename boost::mpl::greater<boost::mpl::sizeof_<TIn>,
121  boost::mpl::sizeof_<TOut> >::type>::type>::type>
122 {
123  static const ipUInt8 g_shiftFactor = 8 * (sizeof(TIn) - sizeof(TOut));
124 
125  static IPSDK_FORCEINLINE void
126  act(const BasePack<IS2PackType<IS>::_packType, TIn>& in,
127  BasePack<IS2PackType<IS>::_packType, TOut>& out)
128  {
129  BasePack<IS2PackType<IS>::_packType, TIn> tmp;
130  assign<IS>(tmp, static_cast<TIn>(AllBits<TOut>::value));
131  bitwiseAnd<IS>(in, tmp, tmp);
132  cast<IS>(tmp, out);
133  }
134 };
135 
136 template <eInstructionSet::domain IS,
137  typename TIn, typename TOut>
138 struct BoolMaskCast<IS, TIn, TOut,
139  typename boost::enable_if<typename boost::mpl::and_<typename boost::is_integral<TIn>::type,
140  typename boost::is_integral<TOut>::type,
141  typename boost::mpl::equal_to<boost::mpl::plus<boost::mpl::sizeof_<TIn>, boost::mpl::int_<1> >,
142  boost::mpl::sizeof_<TOut> >::type>::type>::type>
143 {
144  static IPSDK_FORCEINLINE void
145  act(const BasePack<IS2PackType<IS>::_packType, TIn>& in,
146  BasePack<IS2PackType<IS>::_packType, TOut>& out)
147  {
148  cast<IS>(in, out);
149  shiftLeft<IS>(out, 8, out);
150  bitwiseOr<IS>(out, in, out);
151  }
152 };
153 
154 template <eInstructionSet::domain IS,
155  typename TIn, typename TOut>
156 struct BoolMaskCast<IS, TIn, TOut,
157  typename boost::enable_if<typename boost::mpl::and_<typename boost::is_integral<TIn>::type,
158  typename boost::is_integral<TOut>::type,
159  typename boost::mpl::equal_to<boost::mpl::plus<boost::mpl::sizeof_<TIn>, boost::mpl::int_<2> >,
160  boost::mpl::sizeof_<TOut> >::type>::type>::type>
161 {
162  static IPSDK_FORCEINLINE void
163  act(const BasePack<IS2PackType<IS>::_packType, TIn>& in,
164  BasePack<IS2PackType<IS>::_packType, TOut>& out)
165  {
166  cast<IS>(in, out);
167  shiftLeft<IS>(out, 8, out);
168  bitwiseOr<IS>(out, in, out);
169  shiftLeft<IS>(out, 8, out);
170  bitwiseOr<IS>(out, in, out);
171  }
172 };
174 
177 
178 } // end of namespace detail
179 } // end of namespace simd
180 } // end of namespace ipsdk
181 
182 #endif // __IPSDKUTIL_INSTRUCTIONSET_DETAIL_BOOLMASKCAST_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
cast function; casts a Pack<instructionSet, TIn> to a Pack<instructionSet, TOut>
Definition: BoolMaskCast.h:49
bitwiseCast function; casts a Pack<instructionSet, TIn> to a Pack<instructionSet, TOut>...
Definition: DataItemNodeHdrMacrosDetails.h:48
uint8_t ipUInt8
Base types definition.
Definition: BaseTypes.h:49
Definition: PackTypes.h:56
float ipReal32
Base types definition.
Definition: BaseTypes.h:56
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53
structure containing intrinsic registers used to store vectorized data
Definition: BasePackDecl.h:29