CNDP  22.08.0
cne_vect.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation
3  */
4 
5 #ifndef _CNE_VECT_X86_H_
6 #define _CNE_VECT_X86_H_
7 
14 #include <stdint.h>
15 #include <cne_vect_generic.h>
16 
17 #if (defined(__ICC) || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
18 
19 #include <smmintrin.h> /* SSE4 */
20 
21 #if defined(__AVX__)
22 #include <immintrin.h>
23 #endif
24 
25 #else
26 
27 #include <x86intrin.h>
28 
29 #endif
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define CNE_VECT_DEFAULT_SIMD_BITWIDTH CNE_VECT_SIMD_256
36 
37 typedef __m128i xmm_t;
38 
39 /*
40  * Some people use Klocwork for static code analysis. Klocwork is unable to
41  * determine the proper size of the intrinsic types, and produces hundreds of
42  * ABV.GENERAL false-positives when code using the cne_[xyz]mm_t types assign
43  * to the embedded arrays. To avoid false-positives, we hardcode the expected
44  * sizes and verify they are the same as the actual sizes using a compile time
45  * check.
46  */
47 #define XMM_SIZE 16
48 #define XMM_MASK (XMM_SIZE - 1)
49 
50 typedef union cne_xmm {
51  xmm_t x;
52  uint8_t u8[XMM_SIZE / sizeof(uint8_t)];
53  uint16_t u16[XMM_SIZE / sizeof(uint16_t)];
54  uint32_t u32[XMM_SIZE / sizeof(uint32_t)];
55  uint64_t u64[XMM_SIZE / sizeof(uint64_t)];
56  double pd[XMM_SIZE / sizeof(double)];
57 } cne_xmm_t;
58 
62 static inline void
63 __cne_vec_xmm_size_check(void)
64 {
65  CNE_BUILD_BUG_ON(XMM_SIZE != sizeof(xmm_t));
66 }
67 
68 #ifdef __AVX__
69 
70 typedef __m256i ymm_t;
71 
72 #define YMM_SIZE 32
73 #define YMM_MASK (YMM_SIZE - 1)
74 
75 typedef union cne_ymm {
76  ymm_t y;
77  xmm_t x[YMM_SIZE / sizeof(xmm_t)];
78  uint8_t u8[YMM_SIZE / sizeof(uint8_t)];
79  uint16_t u16[YMM_SIZE / sizeof(uint16_t)];
80  uint32_t u32[YMM_SIZE / sizeof(uint32_t)];
81  uint64_t u64[YMM_SIZE / sizeof(uint64_t)];
82  double pd[YMM_SIZE / sizeof(double)];
83 } cne_ymm_t;
84 
88 static inline void
89 __cne_vec_ymm_size_check(void)
90 {
91  CNE_BUILD_BUG_ON(YMM_SIZE != sizeof(ymm_t));
92 }
93 
94 #endif /* __AVX__ */
95 
96 #ifdef __AVX512F__
97 
98 #define CNE_X86_ZMM_SIZE 64
99 #define CNE_X86_ZMM_MASK (CNE_X86_ZMM_SIZE - 1)
100 
101 typedef union __cne_x86_zmm {
102  __m512i z;
103  ymm_t y[CNE_X86_ZMM_SIZE / sizeof(ymm_t)];
104  xmm_t x[CNE_X86_ZMM_SIZE / sizeof(xmm_t)];
105  uint8_t u8[CNE_X86_ZMM_SIZE / sizeof(uint8_t)];
106  uint16_t u16[CNE_X86_ZMM_SIZE / sizeof(uint16_t)];
107  uint32_t u32[CNE_X86_ZMM_SIZE / sizeof(uint32_t)];
108  uint64_t u64[CNE_X86_ZMM_SIZE / sizeof(uint64_t)];
109  double pd[CNE_X86_ZMM_SIZE / sizeof(double)];
110 } __cne_aligned(CNE_X86_ZMM_SIZE) __cne_x86_zmm_t;
111 
115 static inline void
116 __cne_vec_cne_x86_zmm_size_check(void)
117 {
118  CNE_BUILD_BUG_ON(CNE_X86_ZMM_SIZE != sizeof(__m512i));
119 }
120 
121 #endif /* __AVX512F__ */
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* _CNE_VECT_X86_H_ */
#define __cne_aligned(a)
Definition: cne_common.h:124
#define CNE_BUILD_BUG_ON(condition)
Definition: cne_common.h:357