Commit | Line | Data |
---|---|---|
af02d47e MD |
1 | #ifndef _COMPILER_H |
2 | #define _COMPILER_H | |
3 | ||
4 | /* | |
5 | * compiler.h | |
6 | * | |
7 | * Compiler definitions. | |
8 | * | |
9 | * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
10 | * | |
11 | * This library is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License as published by the Free Software Foundation; either | |
14 | * version 2.1 of the License, or (at your option) any later version. | |
15 | * | |
16 | * This library is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * Lesser General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU Lesser General Public | |
22 | * License along with this library; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
24 | * | |
25 | * IBM's contributions to this file may be relicensed under LGPLv2 or later. | |
26 | */ | |
27 | ||
28 | /* The "volatile" is due to gcc bugs */ | |
29 | #define barrier() __asm__ __volatile__("": : :"memory") | |
30 | ||
31 | #define likely(x) __builtin_expect(!!(x), 1) | |
32 | #define unlikely(x) __builtin_expect(!!(x), 0) | |
33 | ||
34 | /* | |
35 | * Instruct the compiler to perform only a single access to a variable | |
36 | * (prohibits merging and refetching). The compiler is also forbidden to reorder | |
37 | * successive instances of ACCESS_ONCE(), but only when the compiler is aware of | |
38 | * particular ordering. Compiler ordering can be ensured, for example, by | |
39 | * putting two ACCESS_ONCE() in separate C statements. | |
40 | * | |
41 | * This macro does absolutely -nothing- to prevent the CPU from reordering, | |
42 | * merging, or refetching absolutely anything at any time. Its main intended | |
43 | * use is to mediate communication between process-level code and irq/NMI | |
44 | * handlers, all running on the same CPU. | |
45 | */ | |
46 | #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) | |
47 | ||
48 | #endif /* _COMPILER_H */ |