File: compiler.h

package info (click to toggle)
vdo 8.3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,536 kB
  • sloc: ansic: 21,023; sh: 349; makefile: 314; perl: 242
file content (31 lines) | stat: -rw-r--r-- 984 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright 2023 Red Hat
 */

#ifndef LINUX_COMPILER_H
#define LINUX_COMPILER_H

#include <linux/compiler_attributes.h>

/*
 * CPU Branch-prediction hints, courtesy of GCC. Defining these as inline functions instead of
 * macros spoils their magic, sadly.
 */
#define likely(expr) __builtin_expect(!!(expr), 1)
#define unlikely(expr) __builtin_expect(!!(expr), 0)

/*
 * Count the elements in a static array while attempting to catch some type errors. (See
 * http://stackoverflow.com/a/1598827 for an explanation.)
 */
#define ARRAY_SIZE(x) ((sizeof(x) / sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))

/* Defined in linux/container_of.h */
#define container_of(ptr, type, member)                              \
	__extension__({                                              \
		__typeof__(((type *) 0)->member) * __mptr = (ptr);   \
		(type *) ((char *) __mptr - offsetof(type, member)); \
	})

#endif /* LINUX_COMPILER_H */