]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/piotr_fhog/sse.hpp
1c7c0ee1d1ef063d2b842c7538d6d672862c0437
[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 #ifndef __ARM_NEON
10 #define __ARM_NEON
11 #endif
12
13 #ifdef __ARM_NEON
14 #include "SSE2NEON.h"
15 #else
16 #include <emmintrin.h> // SSE2:<e*.h>, SSE3:<p*.h>, SSE4:<s*.h>
17 #endif
18
19 #define RETf inline __m128
20 #define RETi inline __m128i
21
22 // set, load and store values
23 RETf SET( const float &x ) { return _mm_set1_ps(x); }
24 RETf SET( float x, float y, float z, float w ) { return _mm_set_ps(x,y,z,w); }
25 RETi SET( const int &x ) { return _mm_set1_epi32(x); }
26 RETf LD( const float &x ) { return _mm_load_ps(&x); }
27 RETf LDu( const float &x ) { return _mm_loadu_ps(&x); }
28 RETf STR( float &x, const __m128 y ) { _mm_store_ps(&x,y); return y; }
29 RETf STR1( float &x, const __m128 y ) { _mm_store_ss(&x,y); return y; }
30 RETf STRu( float &x, const __m128 y ) { _mm_storeu_ps(&x,y); return y; }
31 RETf STR( float &x, const float y ) { return STR(x,SET(y)); }
32
33 // arithmetic operators
34 RETi ADD( const __m128i x, const __m128i y ) { return _mm_add_epi32(x,y); }
35 RETf ADD( const __m128 x, const __m128 y ) { return _mm_add_ps(x,y); }
36 RETf ADD( const __m128 x, const __m128 y, const __m128 z ) {
37   return ADD(ADD(x,y),z); }
38 RETf ADD( const __m128 a, const __m128 b, const __m128 c, const __m128 &d ) {
39   return ADD(ADD(ADD(a,b),c),d); }
40 RETf SUB( const __m128 x, const __m128 y ) { return _mm_sub_ps(x,y); }
41 RETf MUL( const __m128 x, const __m128 y ) { return _mm_mul_ps(x,y); }
42 RETf MUL( const __m128 x, const float y ) { return MUL(x,SET(y)); }
43 RETf MUL( const float x, const __m128 y ) { return MUL(SET(x),y); }
44 RETf INC( __m128 &x, const __m128 y ) { return x = ADD(x,y); }
45 RETf INC( float &x, const __m128 y ) { __m128 t=ADD(LD(x),y); return STR(x,t); }
46 RETf DEC( __m128 &x, const __m128 y ) { return x = SUB(x,y); }
47 RETf DEC( float &x, const __m128 y ) { __m128 t=SUB(LD(x),y); return STR(x,t); }
48 RETf MIN( const __m128 x, const __m128 y ) { return _mm_min_ps(x,y); }
49 RETf RCP( const __m128 x ) { return _mm_rcp_ps(x); }
50 RETf RCPSQRT( const __m128 x ) { return _mm_rsqrt_ps(x); }
51
52 // logical operators
53 RETf AND( const __m128 x, const __m128 y ) { return _mm_and_ps(x,y); }
54 RETi AND( const __m128i x, const __m128i y ) { return _mm_and_si128(x,y); }
55 RETf ANDNOT( const __m128 x, const __m128 y ) { return _mm_andnot_ps(x,y); }
56 RETf OR( const __m128 x, const __m128 y ) { return _mm_or_ps(x,y); }
57 RETf XOR( const __m128 x, const __m128 y ) { return _mm_xor_ps(x,y); }
58
59 // comparison operators
60 RETf CMPGT( const __m128 x, const __m128 y ) { return _mm_cmpgt_ps(x,y); }
61 RETf CMPLT( const __m128 x, const __m128 y ) { return _mm_cmplt_ps(x,y); }
62 RETi CMPGT( const __m128i x, const __m128i y ) { return _mm_cmpgt_epi32(x,y); }
63 RETi CMPLT( const __m128i x, const __m128i y ) { return _mm_cmplt_epi32(x,y); }
64
65 // conversion operators
66 RETf CVT( const __m128i x ) { return _mm_cvtepi32_ps(x); }
67 RETi CVT( const __m128 x ) { return _mm_cvttps_epi32(x); }
68
69 #undef RETf
70 #undef RETi
71 #endif