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