Blaze 3.9
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
45#include <blaze/system/Inline.h>
47
48
49namespace blaze {
50
51//=================================================================================================
52//
53// 8-BIT INTEGRAL SIMD TYPES
54//
55//=================================================================================================
56
57//*************************************************************************************************
66BLAZE_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//*************************************************************************************************
102BLAZE_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//*************************************************************************************************
138BLAZE_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//*************************************************************************************************
174BLAZE_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//*************************************************************************************************
202template< typename T > // Type of the operand
203BLAZE_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//*************************************************************************************************
241template< typename T > // Type of the operand
242BLAZE_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
Header file for the basic SIMD types.
Compiler-specific system settings.
SIMD type for 64-bit double precision floating point data values.
SIMD type for 32-bit single precision floating point data values.
SIMD type for 16-bit signed integral data values.
SIMD type for 32-bit signed integral data values.
SIMD type for 64-bit integral data values.
SIMD type for 8-bit signed integral data values.
BLAZE_ALWAYS_INLINE const SIMDdouble abs(const SIMDf64< T > &a) noexcept=delete
Absolute of a vector of double precision floating point values.
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
System settings for the inline keywords.
System settings for the SSE mode.