File: likely_unlikely.h

package info (click to toggle)
libjodycode 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,676 kB
  • sloc: ansic: 2,820; makefile: 372; sh: 160; xml: 37
file content (33 lines) | stat: -rw-r--r-- 635 bytes parent folder | download | duplicates (9)
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
32
33
/* likely()/unlikely() macros for branch optimization
 * By Jody Bruchon <jody@jodybruchon.com>
 * Released to the public domain */

#ifndef LIKELY_UNLIKELY_H
#define LIKELY_UNLIKELY_H

#ifdef __cplusplus
extern "C" {
#endif

/* Un-define if already defined */
#if !defined NO_LIKELY_UNLIKELY && (defined __GNUC__ || defined __clang__)
#ifdef likely
#undef likely
#endif
#ifdef unlikely
#undef unlikely
#endif

#define likely(a) __builtin_expect((a), 1)
#define unlikely(a) __builtin_expect((a), 0)

#else /* no GCC/Clang */
#define likely(a) a
#define unlikely(a) a
#endif

#ifdef __cplusplus
}
#endif

#endif /* LIKELY_UNLIKELY_H */