2 * Copyright 2010-2016 Intel Corporation.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation, version 2.1.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * Disclaimer: The codes contained in these modules may be specific
19 * to the Intel Software Development Platform codenamed Knights Ferry,
20 * and the Intel product codenamed Knights Corner, and are not backward
21 * compatible with other Intel products. Additionally, Intel will NOT
22 * support the codes or instruction set in future products.
24 * Intel offers no warranty of any kind regarding the code. This code is
25 * licensed on an "AS IS" basis and Intel is not obligated to provide
26 * any support, assistance, installation, training, or other services
27 * of any kind. Intel is also not obligated to provide any updates,
28 * enhancements or extensions. Intel specifically disclaims any warranty
29 * of merchantability, non-infringement, fitness for any particular
30 * purpose, and any other warranty.
32 * Further, Intel disclaims all liability of any kind, including but
33 * not limited to liability for infringement of any proprietary rights,
34 * relating to the use of the code, even if Intel is notified of the
35 * possibility of such liability. Except as expressly stated in an Intel
36 * license agreement provided with this code and agreed upon with Intel,
37 * no license, express or implied, by estoppel or otherwise, to any
38 * intellectual property rights is granted herein.
41 #ifndef _COIMACROS_COMMON_H
42 #define _COIMACROS_COMMON_H
45 #include "../source/COIPipeline_source.h"
46 #include "../common/COITypes_common.h"
48 /// @file common/COIMacros_common.h
49 /// Commonly used macros
51 // Note that UNUSUED_ATTR means that it is "possibly" unused, not "definitely".
52 // This should compile out in release mode if indeed it is unused.
53 #define UNUSED_ATTR __attribute__((unused))
55 #ifndef UNREFERENCED_CONST_PARAM
56 #define UNREFERENCED_CONST_PARAM(P) { void* x UNUSED_ATTR = \
61 // This seems to work on everything.
62 #ifndef UNREFERENCED_PARAM
63 #define UNREFERENCED_PARAM(P) (P = P)
66 #ifndef SYMBOL_VERSION
70 #define SYMBOL_VERSION( SYMBOL , VERSION ) SYMBOL ## VERSION
74 /* The following are static inline definitions of functions used for manipulating
75 COI_CPU_MASK info (The COI_CPU_MASK type is declared as an array of 16 uint64_t's
76 in COITypes_common.h "typedef uint64_t COI_CPU_MASK[16]").
78 These static inlined functions are intended on being roughly the same as the Linux
79 CPU_* macros defined in sched.h - with the important difference being a different
80 fundamental type difference: cpu_set_t versus COI_CPU_MASK.
82 The motivation for writing this code was to ease portability on the host side of COI
83 applications to both Windows and Linux.
86 /* Roughly equivalent to CPU_ISSET(). */
87 static inline uint64_t COI_CPU_MASK_ISSET(int bitNumber
, const COI_CPU_MASK cpu_mask
)
89 if ((size_t)bitNumber
< sizeof(COI_CPU_MASK
) * 8)
90 return ((cpu_mask
)[bitNumber
/ 64] & (((uint64_t)1) << (bitNumber
% 64)));
94 /* Roughly equivalent to CPU_SET(). */
95 static inline void COI_CPU_MASK_SET(int bitNumber
, COI_CPU_MASK cpu_mask
)
97 if ((size_t)bitNumber
< sizeof(COI_CPU_MASK
) * 8)
98 ((cpu_mask
)[bitNumber
/ 64] |= (((uint64_t)1) << (bitNumber
% 64)));
101 /* Roughly equivalent to CPU_ZERO(). */
102 static inline void COI_CPU_MASK_ZERO(COI_CPU_MASK cpu_mask
)
104 memset(cpu_mask
, 0, sizeof(COI_CPU_MASK
));
107 /* Roughly equivalent to CPU_AND(). */
108 static inline void COI_CPU_MASK_AND(COI_CPU_MASK dst
, const COI_CPU_MASK src1
, const COI_CPU_MASK src2
)
110 const unsigned int loopIterations
= sizeof(COI_CPU_MASK
) / sizeof(dst
[0]);
113 for (; i
< loopIterations
; ++i
)
114 dst
[i
] = src1
[i
] & src2
[i
];
117 /* Roughly equivalent to CPU_XOR(). */
118 static inline void COI_CPU_MASK_XOR(COI_CPU_MASK dst
, const COI_CPU_MASK src1
, const COI_CPU_MASK src2
)
120 const unsigned int loopIterations
= sizeof(COI_CPU_MASK
) / sizeof(dst
[0]);
123 for (; i
< loopIterations
; ++i
)
124 dst
[i
] = src1
[i
] ^ src2
[i
];
127 /* Roughly equivalent to CPU_OR(). */
128 static inline void COI_CPU_MASK_OR(COI_CPU_MASK dst
, const COI_CPU_MASK src1
, const COI_CPU_MASK src2
)
130 const unsigned int loopIterations
= sizeof(COI_CPU_MASK
) / sizeof(dst
[0]);
133 for (; i
< loopIterations
; ++i
)
134 dst
[i
] = src1
[i
] | src2
[i
];
137 /* Utility function for COI_CPU_MASK_COUNT() below. */
138 static inline int __COI_CountBits(uint64_t n
)
147 /* Roughly equivalent to CPU_COUNT(). */
148 static inline int COI_CPU_MASK_COUNT(const COI_CPU_MASK cpu_mask
)
151 const unsigned int loopIterations
= sizeof(COI_CPU_MASK
) / sizeof(cpu_mask
[0]);
154 for (; i
< loopIterations
; ++i
)
156 cnt
+= __COI_CountBits(cpu_mask
[i
]);
161 /* Roughly equivalent to CPU_EQUAL(). */
162 static inline int COI_CPU_MASK_EQUAL(const COI_CPU_MASK cpu_mask1
, const COI_CPU_MASK cpu_mask2
)
164 const unsigned int loopIterations
= sizeof(COI_CPU_MASK
) / sizeof(cpu_mask1
[0]);
167 for (; i
< loopIterations
; ++i
)
169 if (cpu_mask1
[i
] != cpu_mask2
[i
])
176 /* Utility function to translate from cpu_set * to COI_CPU_MASK. */
177 static inline void COI_CPU_MASK_XLATE(COI_CPU_MASK dest
, const cpu_set_t
*src
)
181 COI_CPU_MASK_ZERO(dest
);
183 /* Slightly slower version than the following #else/#endif block. Left here only to
184 document the intent of the code. */
185 for (i
= 0; i
< sizeof(cpu_set_t
) * 8; ++i
)
186 if (CPU_ISSET(i
, src
))
187 COI_CPU_MASK_SET(i
, dest
);
189 for (i
= 0; i
< sizeof(COI_CPU_MASK
) / sizeof(dest
[0]); ++i
)
191 for (j
= 0; j
< 64; ++j
)
193 if (CPU_ISSET(i
* 64 + j
, src
))
194 dest
[i
] |= ((uint64_t)1) << j
;
200 /* Utility function to translate from COI_CPU_MASK to cpu_set *. */
201 static inline void COI_CPU_MASK_XLATE_EX(cpu_set_t
*dest
, const COI_CPU_MASK src
)
207 /* Slightly slower version than the following #else/#endif block. Left here only to
208 document the intent of the code. */
209 for (i
= 0; i
< sizeof(COI_CPU_MASK
) * 8; ++i
)
210 if (COI_CPU_MASK_ISSET(i
, src
))
213 for (i
= 0; i
< sizeof(COI_CPU_MASK
) / sizeof(src
[0]); ++i
)
215 const uint64_t cpu_mask
= src
[i
];
217 for (j
= 0; j
< 64; ++j
)
219 const uint64_t bit
= ((uint64_t)1) << j
;
222 CPU_SET(i
* 64 + j
, dest
);
229 #endif /* _COIMACROS_COMMON_H */