Abs.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SIMD_ABS_H_
36 #define _BLAZE_MATH_SIMD_ABS_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/system/Inline.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // 8-BIT INTEGRAL SIMD TYPES
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
65 BLAZE_ALWAYS_INLINE const SIMDint8 abs( const SIMDint8& a ) noexcept
66 #if BLAZE_AVX512BW_MODE
67 {
68  return _mm512_abs_epi8( a.value );
69 }
70 #elif BLAZE_AVX2_MODE
71 {
72  return _mm256_abs_epi8( a.value );
73 }
74 #elif BLAZE_SSSE3_MODE
75 {
76  return _mm_abs_epi8( a.value );
77 }
78 #else
79 = delete;
80 #endif
81 //*************************************************************************************************
82 
83 
84 
85 
86 //=================================================================================================
87 //
88 // 16-BIT INTEGRAL SIMD TYPES
89 //
90 //=================================================================================================
91 
92 //*************************************************************************************************
101 BLAZE_ALWAYS_INLINE const SIMDint16 abs( const SIMDint16& a ) noexcept
102 #if BLAZE_AVX512BW_MODE
103 {
104  return _mm512_abs_epi16( a.value );
105 }
106 #elif BLAZE_AVX2_MODE
107 {
108  return _mm256_abs_epi16( a.value );
109 }
110 #elif BLAZE_SSSE3_MODE
111 {
112  return _mm_abs_epi16( a.value );
113 }
114 #else
115 = delete;
116 #endif
117 //*************************************************************************************************
118 
119 
120 
121 
122 //=================================================================================================
123 //
124 // 32-BIT INTEGRAL SIMD TYPES
125 //
126 //=================================================================================================
127 
128 //*************************************************************************************************
137 BLAZE_ALWAYS_INLINE const SIMDint32 abs( const SIMDint32& a ) noexcept
138 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
139 {
140  return _mm512_abs_epi32( a.value );
141 }
142 #elif BLAZE_AVX2_MODE
143 {
144  return _mm256_abs_epi32( a.value );
145 }
146 #elif BLAZE_SSSE3_MODE
147 {
148  return _mm_abs_epi32( a.value );
149 }
150 #else
151 = delete;
152 #endif
153 //*************************************************************************************************
154 
155 
156 
157 
158 //=================================================================================================
159 //
160 // 64-BIT INTEGRAL SIMD TYPES
161 //
162 //=================================================================================================
163 
164 //*************************************************************************************************
173 BLAZE_ALWAYS_INLINE const SIMDint64 abs( const SIMDint64& a ) noexcept
174 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
175 {
176  return _mm512_abs_epi64( a.value );
177 }
178 #else
179 = delete;
180 #endif
181 //*************************************************************************************************
182 
183 
184 
185 
186 //=================================================================================================
187 //
188 // 32-BIT FLOATING POINT SIMD TYPES
189 //
190 //=================================================================================================
191 
192 //*************************************************************************************************
201 template< typename T > // Type of the operand
202 BLAZE_ALWAYS_INLINE const SIMDfloat abs( const SIMDf32<T>& a ) noexcept
203 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
204 {
205  return _mm512_abs_ps( (~a).eval().value );
206 }
207 #elif BLAZE_AVX_MODE
208 {
209  const __m256 mask( _mm256_castsi256_ps( _mm256_set1_epi32( 0x80000000 ) ) );
210  return _mm256_andnot_ps( mask, (~a).eval().value );
211 }
212 #elif BLAZE_SSE2_MODE
213 {
214  const __m128 mask( _mm_castsi128_ps( _mm_set1_epi32( 0x80000000 ) ) );
215  return _mm_andnot_ps( mask, (~a).eval().value );
216 }
217 #else
218 = delete;
219 #endif
220 //*************************************************************************************************
221 
222 
223 
224 
225 //=================================================================================================
226 //
227 // 64-BIT FLOATING POINT SIMD TYPES
228 //
229 //=================================================================================================
230 
231 //*************************************************************************************************
240 template< typename T > // Type of the operand
241 BLAZE_ALWAYS_INLINE const SIMDdouble abs( const SIMDf64<T>& a ) noexcept
242 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
243 {
244  return _mm512_abs_pd( (~a).eval().value );
245 }
246 #elif BLAZE_AVX_MODE
247 {
248  const __m256d mask( _mm256_castsi256_pd(
249  _mm256_set_epi32( 0x80000000, 0x0, 0x80000000, 0x0, 0x80000000, 0x0, 0x80000000, 0x0 ) ) );
250  return _mm256_andnot_pd( mask, (~a).eval().value );
251 }
252 #elif BLAZE_SSE2_MODE
253 {
254  const __m128d mask( _mm_castsi128_pd( _mm_set_epi32( 0x80000000, 0x0, 0x80000000, 0x0 ) ) );
255  return _mm_andnot_pd( mask, (~a).eval().value );
256 }
257 #else
258 = delete;
259 #endif
260 //*************************************************************************************************
261 
262 } // namespace blaze
263 
264 #endif
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
decltype(auto) eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:794
decltype(auto) abs(const DenseMatrix< MT, SO > &dm)
Applies the abs() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1176
Header file for the basic SIMD types.
System settings for the SSE mode.
System settings for the inline keywords.