/src/openvswitch/include/openvswitch/util.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017 Nicira, Inc. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at: |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #ifndef OPENVSWITCH_UTIL_H |
18 | | #define OPENVSWITCH_UTIL_H 1 |
19 | | |
20 | | #include <openvswitch/compiler.h> |
21 | | #include <openvswitch/version.h> |
22 | | #include <openvswitch/types.h> |
23 | | |
24 | | #ifdef __cplusplus |
25 | | extern "C" { |
26 | | #endif |
27 | | |
28 | | void ovs_set_program_name(const char *name, const char *version); |
29 | | |
30 | | const char *ovs_get_program_name(void); |
31 | | const char *ovs_get_program_version(void); |
32 | | |
33 | | /* Expands to a string that looks like "<file>:<line>", e.g. "tmp.c:10". |
34 | | * |
35 | | * See http://c-faq.com/ansi/stringize.html for an explanation of OVS_STRINGIZE |
36 | | * and OVS_STRINGIZE2. */ |
37 | 2.74k | #define OVS_SOURCE_LOCATOR __FILE__ ":" OVS_STRINGIZE(__LINE__) |
38 | 2.74k | #define OVS_STRINGIZE(ARG) OVS_STRINGIZE2(ARG) |
39 | 2.74k | #define OVS_STRINGIZE2(ARG) #ARG |
40 | | |
41 | | /* Saturating multiplication of "unsigned int"s: overflow yields UINT_MAX. */ |
42 | | #define OVS_SAT_MUL(X, Y) \ |
43 | 0 | ((Y) == 0 ? 0 \ |
44 | 0 | : (X) <= UINT_MAX / (Y) ? (unsigned int) (X) * (unsigned int) (Y) \ |
45 | 0 | : UINT_MAX) |
46 | | |
47 | | /* A special function that is intended to explicitly ignore results of |
48 | | * functions marked with __attribute__((warn_unused_result)), if necessary. */ |
49 | | void ovs_ignore(bool); |
50 | | |
51 | | /* Like the standard assert macro, except: |
52 | | * |
53 | | * - Writes the failure message to the log. |
54 | | * |
55 | | * - Always evaluates the condition, even with NDEBUG. */ |
56 | | #ifndef NDEBUG |
57 | | #define ovs_assert(CONDITION) \ |
58 | | (OVS_LIKELY(CONDITION) \ |
59 | | ? (void) 0 \ |
60 | | : ovs_assert_failure(OVS_SOURCE_LOCATOR, __func__, #CONDITION)) |
61 | | #else |
62 | 11.2M | #define ovs_assert ovs_ignore |
63 | | #endif |
64 | | OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *); |
65 | | |
66 | | /* This is a void expression that issues a compiler error if POINTER cannot be |
67 | | * compared for equality with the given pointer TYPE. This generally means |
68 | | * that POINTER is a qualified or unqualified TYPE. However, |
69 | | * BUILD_ASSERT_TYPE(POINTER, void *) will accept any pointer to object type, |
70 | | * because any pointer to object can be compared for equality with "void *". |
71 | | * |
72 | | * POINTER can be any expression. The use of "sizeof" ensures that the |
73 | | * expression is not actually evaluated, so that any side effects of the |
74 | | * expression do not occur. |
75 | | * |
76 | | * The cast to int is present only to suppress an "expression using sizeof |
77 | | * bool" warning from "sparse" (see |
78 | | * http://permalink.gmane.org/gmane.comp.parsers.sparse/2967). */ |
79 | | #define BUILD_ASSERT_TYPE(POINTER, TYPE) \ |
80 | 3.46M | ((void) sizeof ((int) ((POINTER) == (TYPE) (POINTER)))) |
81 | | |
82 | | /* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes |
83 | | * anything other than an outermost "const" or "volatile" qualifier. */ |
84 | | #define CONST_CAST(TYPE, POINTER) \ |
85 | 3.46M | (BUILD_ASSERT_TYPE(POINTER, TYPE), \ |
86 | 3.46M | (TYPE) (POINTER)) |
87 | | |
88 | | /* Given a pointer-typed lvalue OBJECT, expands to a pointer type that may be |
89 | | * assigned to OBJECT. */ |
90 | | #ifdef __GNUC__ |
91 | | #define OVS_TYPEOF(OBJECT) typeof(OBJECT) |
92 | | #elif defined (__cplusplus) |
93 | | #define OVS_TYPEOF(OBJECT) decltype(OBJECT) |
94 | | #else |
95 | | #define OVS_TYPEOF(OBJECT) void * |
96 | | #endif |
97 | | |
98 | | /* Given OBJECT of type pointer-to-structure, expands to the offset of MEMBER |
99 | | * within an instance of the structure. |
100 | | * |
101 | | * The GCC-specific version avoids the technicality of undefined behavior if |
102 | | * OBJECT is null, invalid, or not yet initialized. This makes some static |
103 | | * checkers (like Coverity) happier. But the non-GCC version does not actually |
104 | | * dereference any pointer, so it would be surprising for it to cause any |
105 | | * problems in practice. |
106 | | */ |
107 | | #ifdef __GNUC__ |
108 | 770k | #define OBJECT_OFFSETOF(OBJECT, MEMBER) offsetof(typeof(*(OBJECT)), MEMBER) |
109 | | #else |
110 | | #define OBJECT_OFFSETOF(OBJECT, MEMBER) \ |
111 | | ((char *) &(OBJECT)->MEMBER - (char *) (OBJECT)) |
112 | | #endif |
113 | | |
114 | | /* Yields the size of MEMBER within STRUCT. */ |
115 | 195 | #define MEMBER_SIZEOF(STRUCT, MEMBER) (sizeof(((STRUCT *) NULL)->MEMBER)) |
116 | | |
117 | | /* Yields the offset of the end of MEMBER within STRUCT. */ |
118 | | #define OFFSETOFEND(STRUCT, MEMBER) \ |
119 | 0 | (offsetof(STRUCT, MEMBER) + MEMBER_SIZEOF(STRUCT, MEMBER)) |
120 | | |
121 | | /* Given POINTER, the address of the given MEMBER in a STRUCT object, returns |
122 | | the STRUCT object. */ |
123 | | #define CONTAINER_OF(POINTER, STRUCT, MEMBER) \ |
124 | 28.2k | ((STRUCT *) (void *) ((char *) (POINTER) - offsetof (STRUCT, MEMBER))) |
125 | | |
126 | | /* Given POINTER, the address of the given MEMBER within an object of the type |
127 | | * that that OBJECT points to, returns OBJECT as an assignment-compatible |
128 | | * pointer type (either the correct pointer type or "void *"). OBJECT must be |
129 | | * an lvalue. |
130 | | * |
131 | | * This is the same as CONTAINER_OF except that it infers the structure type |
132 | | * from the type of '*OBJECT'. */ |
133 | | #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER) \ |
134 | 767k | ((OVS_TYPEOF(OBJECT)) (void *) \ |
135 | 767k | ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER))) |
136 | | |
137 | | /* Given POINTER, the address of the given MEMBER within an object of the type |
138 | | * that that OBJECT points to, assigns the address of the outer object to |
139 | | * OBJECT, which must be an lvalue. |
140 | | * |
141 | | * Evaluates to (void) 0 as the result is not to be used. */ |
142 | | #define ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER) \ |
143 | 0 | ((OBJECT) = OBJECT_CONTAINING(POINTER, OBJECT, MEMBER), (void) 0) |
144 | | |
145 | | /* As explained in the comment above OBJECT_OFFSETOF(), non-GNUC compilers |
146 | | * like MSVC will complain about un-initialized variables if OBJECT |
147 | | * hasn't already been initialized. To prevent such warnings, INIT_CONTAINER() |
148 | | * can be used as a wrapper around ASSIGN_CONTAINER. */ |
149 | | #define INIT_CONTAINER(OBJECT, POINTER, MEMBER) \ |
150 | 0 | ((OBJECT) = NULL, ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER)) |
151 | | |
152 | | /* Multi-variable container iterators. |
153 | | * |
154 | | * The following macros facilitate safe iteration over data structures |
155 | | * contained in objects. It does so by using an internal iterator variable of |
156 | | * the type of the member object pointer (i.e: pointer to the data structure). |
157 | | */ |
158 | | |
159 | | /* Multi-variable iterator variable name. |
160 | | * Returns the name of the internal iterator variable. |
161 | | */ |
162 | 238k | #define ITER_VAR(NAME) NAME ## __iterator__ |
163 | | |
164 | | /* Multi-variable initialization. Creates an internal iterator variable that |
165 | | * points to the provided pointer. The type of the iterator variable is |
166 | | * ITER_TYPE*. It must be the same type as &VAR->MEMBER. |
167 | | * |
168 | | * The _EXP version evaluates the extra expressions once. |
169 | | */ |
170 | | #define INIT_MULTIVAR(VAR, MEMBER, POINTER, ITER_TYPE) \ |
171 | 1.04M | INIT_MULTIVAR_EXP(VAR, MEMBER, POINTER, ITER_TYPE, (void) 0) |
172 | | |
173 | | #define INIT_MULTIVAR_EXP(VAR, MEMBER, POINTER, ITER_TYPE, ...) \ |
174 | 1.04M | ITER_TYPE *ITER_VAR(VAR) = ( __VA_ARGS__ , (ITER_TYPE *) POINTER) |
175 | | |
176 | | /* Multi-variable condition. |
177 | | * Evaluates the condition expression (that must be based on the internal |
178 | | * iterator variable). Only if the result of expression is true, the OBJECT is |
179 | | * set to the object containing the current value of the iterator variable. |
180 | | * |
181 | | * It is up to the caller to make sure it is safe to run OBJECT_CONTAINING on |
182 | | * the pointers that verify the condition. |
183 | | */ |
184 | | #define CONDITION_MULTIVAR(VAR, MEMBER, EXPR) \ |
185 | 1.28M | ((EXPR) ? \ |
186 | 1.28M | (((VAR) = OBJECT_CONTAINING(ITER_VAR(VAR), VAR, MEMBER)), 1) : \ |
187 | 1.28M | (((VAR) = NULL), 0)) |
188 | | |
189 | | /* Multi-variable update. |
190 | | * Sets the iterator value to NEXT_ITER. |
191 | | */ |
192 | | #define UPDATE_MULTIVAR(VAR, NEXT_ITER) \ |
193 | 238k | (ITER_VAR(VAR) = NEXT_ITER) |
194 | | |
195 | | /* In the safe version of the multi-variable container iteration, the next |
196 | | * value of the iterator is precalculated on the condition expression. |
197 | | * This allows for the iterator to be freed inside the loop. |
198 | | * |
199 | | * Two versions of the macros are provided: |
200 | | * |
201 | | * * In the _SHORT version, the user does not have to provide a variable to |
202 | | * store the next value of the iterator. Instead, a second iterator variable |
203 | | * is declared in the INIT_ macro and its name is determined by |
204 | | * ITER_NEXT_VAR(OBJECT). |
205 | | * |
206 | | * * In the _LONG version, the user provides another variable of the same type |
207 | | * as the iterator object variable to store the next containing object. |
208 | | * We still declare an iterator variable inside the loop but in this case it's |
209 | | * name is derived from the name of the next containing variable. |
210 | | * The value of the next containing object will only be set |
211 | | * (via OBJECT_CONTAINING) if an additional condition is statisfied. This |
212 | | * second condition must ensure it is safe to call OBJECT_CONTAINING on the |
213 | | * next iterator variable. |
214 | | * With respect to the value of the next containing object: |
215 | | * - Inside of the loop: the variable is either NULL or safe to use. |
216 | | * - Outside of the loop: the variable is NULL if the loop ends normally. |
217 | | * If the loop ends with a "break;" statement, rules of Inside the loop |
218 | | * apply. |
219 | | */ |
220 | | #define ITER_NEXT_VAR(NAME) NAME ## __iterator__next__ |
221 | | |
222 | | /* Safe initialization declares both iterators. */ |
223 | | #define INIT_MULTIVAR_SAFE_SHORT(VAR, MEMBER, POINTER, ITER_TYPE) \ |
224 | 0 | INIT_MULTIVAR_SAFE_SHORT_EXP(VAR, MEMBER, POINTER, ITER_TYPE, (void) 0) |
225 | | |
226 | | #define INIT_MULTIVAR_SAFE_SHORT_EXP(VAR, MEMBER, POINTER, ITER_TYPE, ...) \ |
227 | 0 | ITER_TYPE *ITER_VAR(VAR) = ( __VA_ARGS__ , (ITER_TYPE *) POINTER), \ |
228 | 0 | *ITER_NEXT_VAR(VAR) = NULL |
229 | | |
230 | | /* Evaluate the condition expression and, if satisfied, update the _next_ |
231 | | * iterator with the NEXT_EXPR. |
232 | | * Both EXPR and NEXT_EXPR should only use ITER_VAR(VAR) and |
233 | | * ITER_NEXT_VAR(VAR). |
234 | | */ |
235 | | #define CONDITION_MULTIVAR_SAFE_SHORT(VAR, MEMBER, EXPR, NEXT_EXPR) \ |
236 | 0 | ((EXPR) ? \ |
237 | 0 | (((VAR) = OBJECT_CONTAINING(ITER_VAR(VAR), VAR, MEMBER)), \ |
238 | 0 | (NEXT_EXPR), 1) : \ |
239 | 0 | (((VAR) = NULL), 0)) |
240 | | |
241 | | #define UPDATE_MULTIVAR_SAFE_SHORT(VAR) \ |
242 | | UPDATE_MULTIVAR(VAR, ITER_NEXT_VAR(VAR)) |
243 | | |
244 | | /* _LONG versions of the macros. */ |
245 | | |
246 | | #define INIT_MULTIVAR_SAFE_LONG(VAR, NEXT_VAR, MEMBER, POINTER, ITER_TYPE) \ |
247 | | INIT_MULTIVAR_SAFE_LONG_EXP(VAR, NEXT_VAR, MEMBER, POINTER, ITER_TYPE, \ |
248 | | (void) 0) \ |
249 | | |
250 | | #define INIT_MULTIVAR_SAFE_LONG_EXP(VAR, NEXT_VAR, MEMBER, POINTER, \ |
251 | | ITER_TYPE, ...) \ |
252 | | ITER_TYPE *ITER_VAR(VAR) = ( __VA_ARGS__ , (ITER_TYPE *) POINTER), \ |
253 | | *ITER_VAR(NEXT_VAR) = NULL |
254 | | |
255 | | /* Evaluate the condition expression and, if satisfied, update the _next_ |
256 | | * iterator with the NEXT_EXPR. After, evaluate the NEXT_COND and, if |
257 | | * satisfied, set the value to NEXT_VAR. NEXT_COND must use ITER_VAR(NEXT_VAR). |
258 | | * |
259 | | * Both EXPR and NEXT_EXPR should only use ITER_VAR(VAR) and |
260 | | * ITER_VAR(NEXT_VAR). |
261 | | */ |
262 | | #define CONDITION_MULTIVAR_SAFE_LONG(VAR, NEXT_VAR, MEMBER, EXPR, NEXT_EXPR, \ |
263 | | NEXT_COND) \ |
264 | | ((EXPR) ? \ |
265 | | (((VAR) = OBJECT_CONTAINING(ITER_VAR(VAR), VAR, MEMBER)), \ |
266 | | (NEXT_EXPR), ((NEXT_COND) ? \ |
267 | | ((NEXT_VAR) = \ |
268 | | OBJECT_CONTAINING(ITER_VAR(NEXT_VAR), NEXT_VAR, MEMBER)) : \ |
269 | | ((NEXT_VAR) = NULL)), 1) : \ |
270 | | (((VAR) = NULL), ((NEXT_VAR) = NULL), 0)) |
271 | | |
272 | | #define UPDATE_MULTIVAR_SAFE_LONG(VAR, NEXT_VAR) \ |
273 | | UPDATE_MULTIVAR(VAR, ITER_VAR(NEXT_VAR)) |
274 | | |
275 | | /* Helpers to allow overloading the *_SAFE iterator macros and select either |
276 | | * the LONG or the SHORT version depending on the number of arguments. |
277 | | */ |
278 | | #define GET_SAFE_MACRO2(_1, _2, NAME, ...) NAME |
279 | 0 | #define GET_SAFE_MACRO3(_1, _2, _3, NAME, ...) NAME |
280 | 0 | #define GET_SAFE_MACRO4(_1, _2, _3, _4, NAME, ...) NAME |
281 | 0 | #define GET_SAFE_MACRO5(_1, _2, _3, _4, _5, NAME, ...) NAME |
282 | | #define GET_SAFE_MACRO6(_1, _2, _3, _4, _5, _6, NAME, ...) NAME |
283 | | #define GET_SAFE_MACRO(MAX_ARGS) GET_SAFE_MACRO ## MAX_ARGS |
284 | | |
285 | | /* MSVC treats __VA_ARGS__ as a simple token in argument lists. Introduce |
286 | | * a level of indirection to work around that. */ |
287 | 0 | #define EXPAND_MACRO(name, args) name args |
288 | | |
289 | | /* Overload the LONG and the SHORT version of the macros. MAX_ARGS is the |
290 | | * maximum number of arguments (i.e: the number of arguments of the LONG |
291 | | * version). */ |
292 | | #define OVERLOAD_SAFE_MACRO(LONG, SHORT, MAX_ARGS, ...) \ |
293 | 0 | EXPAND_MACRO(GET_SAFE_MACRO(MAX_ARGS), \ |
294 | 0 | (__VA_ARGS__, LONG, SHORT))(__VA_ARGS__) |
295 | | |
296 | | /* Returns the number of elements in ARRAY. */ |
297 | 3.10M | #define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY) |
298 | | |
299 | | /* Returns X / Y, rounding up. X must be nonnegative to round correctly. */ |
300 | 987k | #define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y)) |
301 | | |
302 | | /* Returns X rounded up to the nearest multiple of Y. */ |
303 | 397k | #define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y)) |
304 | | |
305 | | /* Returns the least number that, when added to X, yields a multiple of Y. */ |
306 | 69.7k | #define PAD_SIZE(X, Y) (ROUND_UP(X, Y) - (X)) |
307 | | |
308 | | /* Returns X rounded down to the nearest multiple of Y. */ |
309 | 0 | #define ROUND_DOWN(X, Y) ((X) / (Y) * (Y)) |
310 | | |
311 | | /* Returns true if X is a power of 2, otherwise false. */ |
312 | 9.43k | #define IS_POW2(X) ((X) && !((X) & ((X) - 1))) |
313 | | |
314 | | /* Expands to an anonymous union that contains: |
315 | | * |
316 | | * - MEMBERS in a nested anonymous struct. |
317 | | * |
318 | | * - An array as large as MEMBERS plus padding to a multiple of UNIT bytes. |
319 | | * |
320 | | * The effect is to pad MEMBERS to a multiple of UNIT bytes. |
321 | | * |
322 | | * For example, the struct below is 8 bytes long, with 6 bytes of padding: |
323 | | * |
324 | | * struct padded_struct { |
325 | | * PADDED_MEMBERS(8, uint8_t x; uint8_t y;); |
326 | | * }; |
327 | | */ |
328 | | #define PAD_PASTE2(x, y) x##y |
329 | | #define PAD_PASTE(x, y) PAD_PASTE2(x, y) |
330 | | #define PAD_ID PAD_PASTE(pad, __COUNTER__) |
331 | | #ifndef __cplusplus |
332 | | #define PADDED_MEMBERS(UNIT, MEMBERS) \ |
333 | | union { \ |
334 | | struct { MEMBERS }; \ |
335 | | uint8_t PAD_ID[ROUND_UP(sizeof(struct { MEMBERS }), UNIT)]; \ |
336 | | } |
337 | | #else |
338 | | /* C++ doesn't allow a type declaration within "sizeof", but it does support |
339 | | * scoping for member names, so we can just declare a second member, with a |
340 | | * name and the same type, and then use its size. */ |
341 | | #define PADDED_MEMBERS(UNIT, MEMBERS) \ |
342 | | struct named_member__ { MEMBERS }; \ |
343 | | union { \ |
344 | | struct { MEMBERS }; \ |
345 | | uint8_t PAD_ID[ROUND_UP(sizeof(struct named_member__), UNIT)]; \ |
346 | | } |
347 | | #endif |
348 | | |
349 | | /* Similar to PADDED_MEMBERS with additional cacheline marker: |
350 | | * |
351 | | * - OVS_CACHE_LINE_MARKER is a cacheline marker |
352 | | * - MEMBERS in a nested anonymous struct. |
353 | | * - An array as large as MEMBERS plus padding to a multiple of UNIT bytes. |
354 | | * |
355 | | * The effect is to add cacheline marker and pad MEMBERS to a multiple of |
356 | | * UNIT bytes. |
357 | | * |
358 | | * Example: |
359 | | * struct padded_struct { |
360 | | * PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline0, |
361 | | * uint8_t x; |
362 | | * uint8_t y; |
363 | | * ); |
364 | | * }; |
365 | | * |
366 | | * The PADDED_MEMBERS_CACHELINE_MARKER macro in above structure expands as: |
367 | | * |
368 | | * struct padded_struct { |
369 | | * union { |
370 | | * OVS_CACHE_LINE_MARKER cacheline0; |
371 | | * struct { |
372 | | * uint8_t x; |
373 | | * uint8_t y; |
374 | | * }; |
375 | | * uint8_t pad0[64]; |
376 | | * }; |
377 | | * *--- cacheline 1 boundary (64 bytes) ---* |
378 | | * }; |
379 | | */ |
380 | | #ifndef __cplusplus |
381 | | #define PADDED_MEMBERS_CACHELINE_MARKER(UNIT, CACHELINE, MEMBERS) \ |
382 | | union { \ |
383 | | OVS_CACHE_LINE_MARKER CACHELINE; \ |
384 | | struct { MEMBERS }; \ |
385 | | uint8_t PAD_ID[ROUND_UP(sizeof(struct { MEMBERS }), UNIT)]; \ |
386 | | } |
387 | | #else |
388 | | #define PADDED_MEMBERS_CACHELINE_MARKER(UNIT, CACHELINE, MEMBERS) \ |
389 | | struct struct_##CACHELINE { MEMBERS }; \ |
390 | | union { \ |
391 | | OVS_CACHE_LINE_MARKER CACHELINE; \ |
392 | | struct { MEMBERS }; \ |
393 | | uint8_t PAD_ID[ROUND_UP(sizeof(struct struct_##CACHELINE), UNIT)]; \ |
394 | | } |
395 | | #endif |
396 | | |
397 | | static inline bool |
398 | | is_pow2(uintmax_t x) |
399 | 9.43k | { |
400 | 9.43k | return IS_POW2(x); |
401 | 9.43k | } ofctl_parse_target.c:is_pow2 Line | Count | Source | 399 | 9.40k | { | 400 | 9.40k | return IS_POW2(x); | 401 | 9.40k | } |
Unexecuted instantiation: match.c:is_pow2 Unexecuted instantiation: ofp-flow.c:is_pow2 Unexecuted instantiation: ofp-group.c:is_pow2 Unexecuted instantiation: ofp-match.c:is_pow2 Unexecuted instantiation: ofp-msgs.c:is_pow2 Unexecuted instantiation: ofp-parse.c:is_pow2 Unexecuted instantiation: ofp-port.c:is_pow2 Unexecuted instantiation: ofp-print.c:is_pow2 Unexecuted instantiation: ofp-prop.c:is_pow2 Unexecuted instantiation: ofp-protocol.c:is_pow2 Unexecuted instantiation: ofp-queue.c:is_pow2 Unexecuted instantiation: ofp-switch.c:is_pow2 Unexecuted instantiation: ofp-table.c:is_pow2 Unexecuted instantiation: ofp-util.c:is_pow2 Unexecuted instantiation: ofpbuf.c:is_pow2 Unexecuted instantiation: ovs-thread.c:is_pow2 Unexecuted instantiation: ox-stat.c:is_pow2 Unexecuted instantiation: packets.c:is_pow2 Unexecuted instantiation: poll-loop.c:is_pow2 Unexecuted instantiation: seq.c:is_pow2 Unexecuted instantiation: socket-util.c:is_pow2 Unexecuted instantiation: timeval.c:is_pow2 Unexecuted instantiation: tun-metadata.c:is_pow2 Unexecuted instantiation: unixctl.c:is_pow2 Unexecuted instantiation: util.c:is_pow2 Unexecuted instantiation: vlog.c:is_pow2 Unexecuted instantiation: latch-unix.c:is_pow2 Unexecuted instantiation: socket-util-unix.c:is_pow2 Unexecuted instantiation: async-append-aio.c:is_pow2 Unexecuted instantiation: dirs.c:is_pow2 Unexecuted instantiation: backtrace.c:is_pow2 Unexecuted instantiation: byteq.c:is_pow2 Unexecuted instantiation: colors.c:is_pow2 Unexecuted instantiation: command-line.c:is_pow2 Unexecuted instantiation: coverage.c:is_pow2 Unexecuted instantiation: csum.c:is_pow2 Unexecuted instantiation: dp-packet.c:is_pow2 Unexecuted instantiation: dp-packet-gso.c:is_pow2 Unexecuted instantiation: dynamic-string.c:is_pow2 Unexecuted instantiation: fatal-signal.c:is_pow2 Unexecuted instantiation: flow.c:is_pow2 Unexecuted instantiation: hash.c:is_pow2 Line | Count | Source | 399 | 34 | { | 400 | 34 | return IS_POW2(x); | 401 | 34 | } |
Unexecuted instantiation: id-pool.c:is_pow2 Unexecuted instantiation: jhash.c:is_pow2 Unexecuted instantiation: json.c:is_pow2 Unexecuted instantiation: jsonrpc.c:is_pow2 Unexecuted instantiation: meta-flow.c:is_pow2 Unexecuted instantiation: namemap.c:is_pow2 Unexecuted instantiation: netdev.c:is_pow2 Unexecuted instantiation: netlink.c:is_pow2 Unexecuted instantiation: nx-match.c:is_pow2 Unexecuted instantiation: ofp-actions.c:is_pow2 Unexecuted instantiation: ofp-bundle.c:is_pow2 Unexecuted instantiation: ofp-connection.c:is_pow2 Unexecuted instantiation: ofp-ct.c:is_pow2 Unexecuted instantiation: ofp-ed-props.c:is_pow2 Unexecuted instantiation: ofp-errors.c:is_pow2 Unexecuted instantiation: ofp-ipfix.c:is_pow2 Unexecuted instantiation: ofp-meter.c:is_pow2 Unexecuted instantiation: ofp-monitor.c:is_pow2 Unexecuted instantiation: ofp-packet.c:is_pow2 Unexecuted instantiation: ovs-rcu.c:is_pow2 Unexecuted instantiation: ovs-replay.c:is_pow2 Unexecuted instantiation: ovs-router.c:is_pow2 Unexecuted instantiation: pvector.c:is_pow2 Unexecuted instantiation: random.c:is_pow2 Unexecuted instantiation: reconnect.c:is_pow2 Unexecuted instantiation: shash.c:is_pow2 Unexecuted instantiation: smap.c:is_pow2 Unexecuted instantiation: sset.c:is_pow2 Unexecuted instantiation: stream.c:is_pow2 Unexecuted instantiation: svec.c:is_pow2 Unexecuted instantiation: syslog-direct.c:is_pow2 Unexecuted instantiation: syslog-libc.c:is_pow2 Unexecuted instantiation: syslog-null.c:is_pow2 Unexecuted instantiation: tnl-ports.c:is_pow2 Unexecuted instantiation: token-bucket.c:is_pow2 Unexecuted instantiation: unicode.c:is_pow2 Unexecuted instantiation: userspace-tso.c:is_pow2 Unexecuted instantiation: uuid.c:is_pow2 Unexecuted instantiation: daemon-unix.c:is_pow2 Unexecuted instantiation: signals.c:is_pow2 Unexecuted instantiation: stream-unix.c:is_pow2 Unexecuted instantiation: netdev-linux.c:is_pow2 Unexecuted instantiation: netlink-socket.c:is_pow2 Unexecuted instantiation: rtnetlink.c:is_pow2 Unexecuted instantiation: route-table.c:is_pow2 Unexecuted instantiation: tc.c:is_pow2 Unexecuted instantiation: stream-ssl.c:is_pow2 Unexecuted instantiation: dhparams.c:is_pow2 Unexecuted instantiation: aes128.c:is_pow2 Unexecuted instantiation: bundle.c:is_pow2 Unexecuted instantiation: classifier.c:is_pow2 Unexecuted instantiation: ccmap.c:is_pow2 Unexecuted instantiation: cmap.c:is_pow2 Unexecuted instantiation: connectivity.c:is_pow2 Unexecuted instantiation: cooperative-multitasking.c:is_pow2 Unexecuted instantiation: daemon.c:is_pow2 Unexecuted instantiation: dpif-offload.c:is_pow2 Unexecuted instantiation: dpif-offload-dummy.c:is_pow2 Unexecuted instantiation: dpif.c:is_pow2 Unexecuted instantiation: entropy.c:is_pow2 Unexecuted instantiation: guarded-list.c:is_pow2 Unexecuted instantiation: hmapx.c:is_pow2 Unexecuted instantiation: id-fpool.c:is_pow2 Unexecuted instantiation: learn.c:is_pow2 Unexecuted instantiation: lockfile.c:is_pow2 Unexecuted instantiation: multipath.c:is_pow2 Unexecuted instantiation: netdev-dummy.c:is_pow2 Unexecuted instantiation: netdev-vport.c:is_pow2 Unexecuted instantiation: odp-execute.c:is_pow2 Unexecuted instantiation: odp-util.c:is_pow2 Unexecuted instantiation: pcap-file.c:is_pow2 Unexecuted instantiation: process.c:is_pow2 Unexecuted instantiation: sha1.c:is_pow2 Unexecuted instantiation: simap.c:is_pow2 Unexecuted instantiation: stream-fd.c:is_pow2 Unexecuted instantiation: stream-replay.c:is_pow2 Unexecuted instantiation: stream-tcp.c:is_pow2 Unexecuted instantiation: timer.c:is_pow2 Unexecuted instantiation: tnl-neigh-cache.c:is_pow2 Unexecuted instantiation: netdev-native-tnl.c:is_pow2 Unexecuted instantiation: dpif-netlink.c:is_pow2 Unexecuted instantiation: dpif-netlink-rtnl.c:is_pow2 Unexecuted instantiation: dpif-offload-tc.c:is_pow2 Unexecuted instantiation: dpif-offload-tc-netdev.c:is_pow2 Unexecuted instantiation: netlink-conntrack.c:is_pow2 Unexecuted instantiation: netlink-notifier.c:is_pow2 Unexecuted instantiation: conntrack.c:is_pow2 Unexecuted instantiation: ct-dpif.c:is_pow2 Unexecuted instantiation: dpctl.c:is_pow2 Unexecuted instantiation: dpif-netdev.c:is_pow2 Unexecuted instantiation: fat-rwlock.c:is_pow2 Unexecuted instantiation: hindex.c:is_pow2 Unexecuted instantiation: ipf.c:is_pow2 Unexecuted instantiation: ovs-numa.c:is_pow2 Unexecuted instantiation: dpdk-stub.c:is_pow2 Unexecuted instantiation: vswitch-idl.c:is_pow2 Unexecuted instantiation: conntrack-icmp.c:is_pow2 Unexecuted instantiation: conntrack-tcp.c:is_pow2 Unexecuted instantiation: conntrack-tp.c:is_pow2 Unexecuted instantiation: conntrack-other.c:is_pow2 Unexecuted instantiation: dpif-netdev-dfc.c:is_pow2 Unexecuted instantiation: dpif-netdev-dpcls.c:is_pow2 Unexecuted instantiation: dpif-netdev-perf.c:is_pow2 Unexecuted instantiation: ovsdb-data.c:is_pow2 Unexecuted instantiation: ovsdb-error.c:is_pow2 Unexecuted instantiation: ovsdb-idl.c:is_pow2 Unexecuted instantiation: ovsdb-map-op.c:is_pow2 Unexecuted instantiation: ovsdb-set-op.c:is_pow2 Unexecuted instantiation: ovsdb-parser.c:is_pow2 Unexecuted instantiation: ovsdb-types.c:is_pow2 Unexecuted instantiation: skiplist.c:is_pow2 Unexecuted instantiation: ovsdb-cs.c:is_pow2 Unexecuted instantiation: ovsdb-session.c:is_pow2 |
402 | | |
403 | | /* Returns X rounded up to a power of 2. X must be a constant expression. */ |
404 | 0 | #define ROUND_UP_POW2(X) RUP2__(X) |
405 | 0 | #define RUP2__(X) (RUP2_1(X) + 1) |
406 | 0 | #define RUP2_1(X) (RUP2_2(X) | (RUP2_2(X) >> 16)) |
407 | 0 | #define RUP2_2(X) (RUP2_3(X) | (RUP2_3(X) >> 8)) |
408 | 0 | #define RUP2_3(X) (RUP2_4(X) | (RUP2_4(X) >> 4)) |
409 | 0 | #define RUP2_4(X) (RUP2_5(X) | (RUP2_5(X) >> 2)) |
410 | 0 | #define RUP2_5(X) (RUP2_6(X) | (RUP2_6(X) >> 1)) |
411 | 0 | #define RUP2_6(X) ((X) - 1) |
412 | | |
413 | | /* Returns X rounded down to a power of 2. X must be a constant expression. */ |
414 | | #define ROUND_DOWN_POW2(X) RDP2__(X) |
415 | | #define RDP2__(X) (RDP2_1(X) - (RDP2_1(X) >> 1)) |
416 | | #define RDP2_1(X) (RDP2_2(X) | (RDP2_2(X) >> 16)) |
417 | | #define RDP2_2(X) (RDP2_3(X) | (RDP2_3(X) >> 8)) |
418 | | #define RDP2_3(X) (RDP2_4(X) | (RDP2_4(X) >> 4)) |
419 | | #define RDP2_4(X) (RDP2_5(X) | (RDP2_5(X) >> 2)) |
420 | | #define RDP2_5(X) ( (X) | ( (X) >> 1)) |
421 | | |
422 | | /* Macros for sizing bitmaps */ |
423 | 2.56M | #define BITMAP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT) |
424 | 0 | #define BITMAP_N_LONGS(N_BITS) DIV_ROUND_UP(N_BITS, BITMAP_ULONG_BITS) |
425 | | |
426 | | /* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to (void |
427 | | * *). This suppresses the alignment warning issued by Clang and newer |
428 | | * versions of GCC when a pointer is cast to a type with a stricter alignment. |
429 | | * |
430 | | * Add ALIGNED_CAST only if you are sure that the cast is actually correct, |
431 | | * that is, that the pointer is actually properly aligned for the stricter |
432 | | * type. On RISC architectures, dereferencing a misaligned pointer can cause a |
433 | | * segfault, so it is important to be aware of correct alignment. */ |
434 | 3.92M | #define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR)) |
435 | | |
436 | | #define IS_PTR_ALIGNED(OBJ) \ |
437 | 0 | (!(OBJ) || (uintptr_t) (OBJ) % __alignof__(OVS_TYPEOF(OBJ)) == 0) |
438 | | |
439 | | #ifdef __cplusplus |
440 | | } |
441 | | #endif |
442 | | |
443 | | #endif |