New upstream version 17.11.1
[deb_dpdk.git] / lib / librte_eal / common / include / arch / x86 / rte_vect.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_VECT_X86_H_
35 #define _RTE_VECT_X86_H_
36
37 /**
38  * @file
39  *
40  * RTE SSE/AVX related header.
41  */
42
43 #include <stdint.h>
44 #include <rte_config.h>
45 #include "generic/rte_vect.h"
46
47 #if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
48
49 #include <smmintrin.h> /* SSE4 */
50
51 #if defined(__AVX__)
52 #include <immintrin.h>
53 #endif
54
55 #else
56
57 #include <x86intrin.h>
58
59 #endif
60
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64
65 typedef __m128i xmm_t;
66
67 #define XMM_SIZE        (sizeof(xmm_t))
68 #define XMM_MASK        (XMM_SIZE - 1)
69
70 typedef union rte_xmm {
71         xmm_t    x;
72         uint8_t  u8[XMM_SIZE / sizeof(uint8_t)];
73         uint16_t u16[XMM_SIZE / sizeof(uint16_t)];
74         uint32_t u32[XMM_SIZE / sizeof(uint32_t)];
75         uint64_t u64[XMM_SIZE / sizeof(uint64_t)];
76         double   pd[XMM_SIZE / sizeof(double)];
77 } rte_xmm_t;
78
79 #ifdef __AVX__
80
81 typedef __m256i ymm_t;
82
83 #define YMM_SIZE        (sizeof(ymm_t))
84 #define YMM_MASK        (YMM_SIZE - 1)
85
86 typedef union rte_ymm {
87         ymm_t    y;
88         xmm_t    x[YMM_SIZE / sizeof(xmm_t)];
89         uint8_t  u8[YMM_SIZE / sizeof(uint8_t)];
90         uint16_t u16[YMM_SIZE / sizeof(uint16_t)];
91         uint32_t u32[YMM_SIZE / sizeof(uint32_t)];
92         uint64_t u64[YMM_SIZE / sizeof(uint64_t)];
93         double   pd[YMM_SIZE / sizeof(double)];
94 } rte_ymm_t;
95
96 #endif /* __AVX__ */
97
98 #ifdef RTE_ARCH_I686
99 #define _mm_cvtsi128_si64(a)    \
100 __extension__ ({                \
101         rte_xmm_t m;            \
102         m.x = (a);              \
103         (m.u64[0]);             \
104 })
105 #endif
106
107 /*
108  * Prior to version 12.1 icc doesn't support _mm_set_epi64x.
109  */
110 #if (defined(__ICC) && __ICC < 1210)
111 #define _mm_set_epi64x(a, b)     \
112 __extension__ ({                 \
113         rte_xmm_t m;             \
114         m.u64[0] = b;            \
115         m.u64[1] = a;            \
116         (m.x);                   \
117 })
118 #endif /* (defined(__ICC) && __ICC < 1210) */
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif /* _RTE_VECT_X86_H_ */