95bf4b1a34809e19f4d53736bbd03e7e23be737f
[dpdk.git] / lib / librte_eal / common / include / rte_common_vect.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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_COMMON_VECT_H_
35 #define _RTE_COMMON_VECT_H_
36
37 /**
38  * @file
39  *
40  * RTE SSE/AVX related header.
41  */
42
43 #if (defined(__ICC) || (__GNUC__ == 4 &&  __GNUC_MINOR__ < 4))
44
45 #ifdef __SSE__
46 #include <xmmintrin.h>
47 #endif
48
49 #ifdef __SSE2__
50 #include <emmintrin.h>
51 #endif
52
53 #if defined(__SSE4_2__) || defined(__SSE4_1__)
54 #include <smmintrin.h>
55 #endif
56
57 #else
58
59 #include <x86intrin.h>
60
61 #endif
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 typedef __m128i xmm_t;
68
69 #define XMM_SIZE        (sizeof(xmm_t))
70 #define XMM_MASK        (XMM_SIZE - 1)
71
72 typedef union rte_xmm {
73         xmm_t    m;
74         uint8_t  u8[XMM_SIZE / sizeof(uint8_t)];
75         uint16_t u16[XMM_SIZE / sizeof(uint16_t)];
76         uint32_t u32[XMM_SIZE / sizeof(uint32_t)];
77         uint64_t u64[XMM_SIZE / sizeof(uint64_t)];
78         double   pd[XMM_SIZE / sizeof(double)];
79 } rte_xmm_t;
80
81 #ifdef RTE_ARCH_I686
82 #define _mm_cvtsi128_si64(a) ({ \
83         rte_xmm_t m;            \
84         m.m = (a);              \
85         (m.u64[0]);             \
86 })
87 #endif
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* _RTE_COMMON__VECT_H_ */