IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
AssignRegImpl.h
Go to the documentation of this file.
1 // AssignRegImpl.h:
3 // ------------
4 //
14 
15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_DETAIL_SSE2_ASSIGNREGIMPL_H__
16 #define __IPSDKUTIL_INSTRUCTIONSET_DETAIL_SSE2_ASSIGNREGIMPL_H__
17 
19 
20 namespace ipsdk {
21 namespace simd {
22 namespace detail {
23 
26 
27 template <typename T>
28 IPSDK_FORCEINLINE
29 typename Sse2Type<T>::Type
30 AssignReg<eInstructionSet::eIS_Sse2, T,
31  typename boost::enable_if<
32  typename boost::mpl::and_<typename boost::is_integral<T>::type,
33  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<1> >::type
34  >::type
35  >::type
36 >
37 ::act(const T& value)
38 {
39  return _mm_set1_epi8(value);
40 }
41 
42 template <typename T>
43 IPSDK_FORCEINLINE
44 void
45 AssignReg<eInstructionSet::eIS_Sse2, T,
46  typename boost::enable_if<
47  typename boost::mpl::and_<typename boost::is_integral<T>::type,
48  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<1> >::type
49  >::type
50  >::type
51 >
52 ::act(typename Sse2Type<T>::Type& reg, const T& value)
53 {
54  reg = _mm_set1_epi8(value);
55 }
56 
57 template <typename T>
58 IPSDK_FORCEINLINE
59 typename Sse2Type<T>::Type
60 AssignReg<eInstructionSet::eIS_Sse2, T,
61  typename boost::enable_if<
62  typename boost::mpl::and_<typename boost::is_integral<T>::type,
63  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<2> >::type
64  >::type
65  >::type
66 >::act(const T& value)
67 {
68  return _mm_set1_epi16(value);
69 }
70 
71 template <typename T>
72 IPSDK_FORCEINLINE
73 void
74 AssignReg<eInstructionSet::eIS_Sse2, T,
75  typename boost::enable_if<
76  typename boost::mpl::and_<typename boost::is_integral<T>::type,
77  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<2> >::type
78  >::type
79  >::type
80 >::act(typename Sse2Type<T>::Type& reg, const T& value)
81 {
82  reg = _mm_set1_epi16(value);
83 }
84 
85 template <typename T>
86 IPSDK_FORCEINLINE
87 typename Sse2Type<T>::Type
88 AssignReg<eInstructionSet::eIS_Sse2, T,
89  typename boost::enable_if<
90  typename boost::mpl::and_<typename boost::is_integral<T>::type,
91  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<4> >::type
92  >::type
93  >::type
94 >::act(const T& value)
95 {
96  return _mm_set1_epi32(value);
97 }
98 
99 template <typename T>
100 IPSDK_FORCEINLINE
101 void
102 AssignReg<eInstructionSet::eIS_Sse2, T,
103  typename boost::enable_if<
104  typename boost::mpl::and_<typename boost::is_integral<T>::type,
105  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<4> >::type
106  >::type
107  >::type
108 >::act(typename Sse2Type<T>::Type& reg, const T& value)
109 {
110  reg = _mm_set1_epi32(value);
111 }
112 
113 template <typename T>
114 IPSDK_FORCEINLINE
115 typename Sse2Type<T>::Type
116 AssignReg<eInstructionSet::eIS_Sse2, T,
117  typename boost::enable_if<
118  typename boost::mpl::and_<typename boost::is_integral<T>::type,
119  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<8> >::type
120  >::type
121  >::type
122 >::act(const T& value)
123 {
124  // there's no instruction such as "_mm_set1_epi32" for 64 bits integers,
125  // so we use a work-around...
126  T values[2];
127  values[0] = values[1] = value;
128  return _mm_loadu_si128(
129  reinterpret_cast<const typename Sse2Type<T>::Type*>(values));
130 }
131 
132 template <typename T>
133 IPSDK_FORCEINLINE
134 void
135 AssignReg<eInstructionSet::eIS_Sse2, T,
136  typename boost::enable_if<
137  typename boost::mpl::and_<typename boost::is_integral<T>::type,
138  typename boost::mpl::equal_to<boost::mpl::int_<sizeof(T)>, boost::mpl::int_<8> >::type
139  >::type
140  >::type
141 >::act(typename Sse2Type<T>::Type& reg, const T& value)
142 {
143  // there's no instruction such as "_mm_set1_epi32" for 64 bits integers,
144  // so we use a work-around...
145  T values[2];
146  values[0] = values[1] = value;
147  reg = _mm_loadu_si128(
148  reinterpret_cast<const typename Sse2Type<T>::Type*>(values));
149 }
150 
151 // assign implementation for SSE2 for real32 type
152 IPSDK_FORCEINLINE
153 Sse2Type<ipReal32>::Type
154 AssignReg<eInstructionSet::eIS_Sse2, ipReal32>::act(const ipReal32& value)
155 {
156  return _mm_set1_ps(value);
157 }
158 
159 IPSDK_FORCEINLINE
160 void
161 AssignReg<eInstructionSet::eIS_Sse2, ipReal32>::act(Sse2Type<ipReal32>::Type& reg,
162  const ipReal32& value)
163 {
164  reg = _mm_set1_ps(value);
165 }
166 
167 // assign implementation for SSE2 for real64 type
168 IPSDK_FORCEINLINE
169 Sse2Type<ipReal64>::Type
170 AssignReg<eInstructionSet::eIS_Sse2, ipReal64>::act(const ipReal64& value)
171 {
172  return _mm_set1_pd(value);
173 }
174 
175 IPSDK_FORCEINLINE
176 void
177 AssignReg<eInstructionSet::eIS_Sse2, ipReal64>::act(Sse2Type<ipReal64>::Type& reg,
178  const ipReal64& value)
179 {
180  reg = _mm_set1_pd(value);
181 }
182 
185 
186 } // end of namespace detail
187 } // end of namespace simd
188 } // end of namespace ipsdk
189 
190 #endif // __IPSDKUTIL_INSTRUCTIONSET_DETAIL_SSE2_ASSIGNREGIMPL_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
Streaming SIMD Extensions 2.
Definition: InstructionSetTypes.h:36
float ipReal32
Base types definition.
Definition: BaseTypes.h:56