]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/piotr_fhog/sse.hpp
Updated cmake. Now you can enable visualization of results, opecv cufft implementatio...
[hercules2020/kcf.git] / src / piotr_fhog / sse.hpp
1 /*******************************************************************************
2 * Piotr's Computer Vision Matlab Toolbox      Version 3.23
3 * Copyright 2014 Piotr Dollar.  [pdollar-at-gmail.com]
4 * Licensed under the Simplified BSD License [see external/bsd.txt]
5 *******************************************************************************/
6 #ifndef _SSE_HPP_
7 #define _SSE_HPP_
8
9 #ifdef __ARM_NEON
10 #include "SSE2NEON.h"
11 #else
12 #include <emmintrin.h> // SSE2:<e*.h>, SSE3:<p*.h>, SSE4:<s*.h>
13 #endif
14
15 #define RETf inline __m128
16 #define RETi inline __m128i
17
18 // set, load and store values
19 RETf SET( const float &x ) { return _mm_set1_ps(x); }
20 RETf SET( float x, float y, float z, float w ) { return _mm_set_ps(x,y,z,w); }
21 RETi SET( const int &x ) { return _mm_set1_epi32(x); }
22 RETf LD( const float &x ) { return _mm_load_ps(&x); }
23 RETf LDu( const float &x ) { return _mm_loadu_ps(&x); }
24 RETf STR( float &x, const __m128 y ) { _mm_store_ps(&x,y); return y; }
25 RETf STR1( float &x, const __m128 y ) { _mm_store_ss(&x,y); return y; }
26 RETf STRu( float &x, const __m128 y ) { _mm_storeu_ps(&x,y); return y; }
27 RETf STR( float &x, const float y ) { return STR(x,SET(y)); }
28
29 // arithmetic operators
30 RETi ADD( const __m128i x, const __m128i y ) { return _mm_add_epi32(x,y); }
31 RETf ADD( const __m128 x, const __m128 y ) { return _mm_add_ps(x,y); }
32 RETf ADD( const __m128 x, const __m128 y, const __m128 z ) {
33   return ADD(ADD(x,y),z); }
34 RETf ADD( const __m128 a, const __m128 b, const __m128 c, const __m128 &d ) {
35   return ADD(ADD(ADD(a,b),c),d); }
36 RETf SUB( const __m128 x, const __m128 y ) { return _mm_sub_ps(x,y); }
37 RETf MUL( const __m128 x, const __m128 y ) { return _mm_mul_ps(x,y); }
38 RETf MUL( const __m128 x, const float y ) { return MUL(x,SET(y)); }
39 RETf MUL( const float x, const __m128 y ) { return MUL(SET(x),y); }
40 RETf INC( __m128 &x, const __m128 y ) { return x = ADD(x,y); }
41 RETf INC( float &x, const __m128 y ) { __m128 t=ADD(LD(x),y); return STR(x,t); }
42 RETf DEC( __m128 &x, const __m128 y ) { return x = SUB(x,y); }
43 RETf DEC( float &x, const __m128 y ) { __m128 t=SUB(LD(x),y); return STR(x,t); }
44 RETf MIN( const __m128 x, const __m128 y ) { return _mm_min_ps(x,y); }
45 RETf RCP( const __m128 x ) { return _mm_rcp_ps(x); }
46 RETf RCPSQRT( const __m128 x ) { return _mm_rsqrt_ps(x); }
47
48 // logical operators
49 RETf AND( const __m128 x, const __m128 y ) { return _mm_and_ps(x,y); }
50 RETi AND( const __m128i x, const __m128i y ) { return _mm_and_si128(x,y); }
51 RETf ANDNOT( const __m128 x, const __m128 y ) { return _mm_andnot_ps(x,y); }
52 RETf OR( const __m128 x, const __m128 y ) { return _mm_or_ps(x,y); }
53 RETf XOR( const __m128 x, const __m128 y ) { return _mm_xor_ps(x,y); }
54
55 // comparison operators
56 RETf CMPGT( const __m128 x, const __m128 y ) { return _mm_cmpgt_ps(x,y); }
57 RETf CMPLT( const __m128 x, const __m128 y ) { return _mm_cmplt_ps(x,y); }
58 RETi CMPGT( const __m128i x, const __m128i y ) { return _mm_cmpgt_epi32(x,y); }
59 RETi CMPLT( const __m128i x, const __m128i y ) { return _mm_cmplt_epi32(x,y); }
60
61 // conversion operators
62 RETf CVT( const __m128i x ) { return _mm_cvtepi32_ps(x); }
63 RETi CVT( const __m128 x ) { return _mm_cvttps_epi32(x); }
64
65 #undef RETf
66 #undef RETi
67 #endif