vector.h 2.84 KB
Newer Older
Pedro Gonnet's avatar
Pedro Gonnet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*******************************************************************************
 * This file is part of SWIFT.
 * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 ******************************************************************************/

/* Have I already read this file? */
#ifndef VEC_MACRO

    /* Include the header file with the intrinsics. */
    #include <immintrin.h>
    
    /* Define the vector macro. */
    #define VEC_MACRO(elcount, type)  __attribute__((vector_size((elcount)*sizeof(type)))) type

    /* So what will the vector size be? */
30
31
    #ifdef NO__AVX__
        #define VECTORIZE
Pedro Gonnet's avatar
Pedro Gonnet committed
32
        #define VEC_SIZE 8
33
34
        #define VEC_FLOAT __m256
        #define VEC_INT __m256i
Pedro Gonnet's avatar
Pedro Gonnet committed
35
36
37
38
39
40
41
        #define vec_load(a) _mm256_load_ps(a)
        #define vec_set1(a) _mm256_set1_ps(a)
        #define vec_sqrt(a) _mm256_sqrt_ps(a)
        #define vec_rcp(a) _mm256_rcp_ps(a)
        #define vec_rsqrt(a) _mm256_rsqrt_ps(a)
        #define vec_ftoi(a) _mm256_cvttps_epi32(a)
        #define vec_fmin(a,b) _mm256_min_ps(a,b)
42
43
    #elif defined( NO__SSE2__ )
        #define VECTORIZE
Pedro Gonnet's avatar
Pedro Gonnet committed
44
        #define VEC_SIZE 4
45
46
        #define VEC_FLOAT __m128
        #define VEC_INT __m128i
Pedro Gonnet's avatar
Pedro Gonnet committed
47
48
49
50
51
52
53
        #define vec_load(a) _mm_load_ps(a)
        #define vec_set1(a) _mm_set1_ps(a)
        #define vec_sqrt(a) _mm_sqrt_ps(a)
        #define vec_rcp(a) _mm_rcp_ps(a)
        #define vec_rsqrt(a) _mm_rsqrt_ps(a)
        #define vec_ftoi(a) _mm_cvttps_epi32(a)
        #define vec_fmin(a,b) _mm_min_ps(a,b)
54
55
    #else
        #define VEC_SIZE 4
Pedro Gonnet's avatar
Pedro Gonnet committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    #endif
    // #ifdef __AVX__
    //     #define VEC_SIZE 8
    //     #define VEC_FLOAT VEC_MACRO(8,float)
    //     #define VEC_DOUBLE VEC_MACRO(4,double)
    //     #define VECTORIZE
    // #elif defined(__SSE2__)
    //     #define VEC_SIZE 4
    //     #define VEC_FLOAT VEC_MACRO(4,float)
    //     #define VEC_DOUBLE VEC_MACRO(2,double)
    //     #define VECTORIZE
    // #endif

    /* Define the composite types for element access. */
    #ifdef VECTORIZE
    typedef union {
72
73
74
75
        // VEC_MACRO(VEC_SIZE,float) v;
        // VEC_MACRO(VEC_SIZE,int) m;
        VEC_FLOAT v;
        VEC_INT m;
Pedro Gonnet's avatar
Pedro Gonnet committed
76
77
78
79
80
81
        float f[VEC_SIZE];
        int i[VEC_SIZE];
        } vector;
    #endif

#endif