]>
Commit | Line | Data |
---|---|---|
e6cd4bb5 RH |
1 | /* |
2 | * Simple interface for 128-bit atomic operations. | |
3 | * | |
4 | * Copyright (C) 2018 Linaro, Ltd. | |
5 | * | |
6 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
7 | * See the COPYING file in the top-level directory. | |
8 | * | |
29f23167 | 9 | * See docs/devel/atomics.rst for discussion about the guarantees each |
e6cd4bb5 RH |
10 | * atomic primitive is meant to provide. |
11 | */ | |
12 | ||
13 | #ifndef QEMU_ATOMIC128_H | |
14 | #define QEMU_ATOMIC128_H | |
15 | ||
ec150c7e MA |
16 | #include "qemu/int128.h" |
17 | ||
333c813b RH |
18 | /* |
19 | * If __alignof(unsigned __int128) < 16, GCC may refuse to inline atomics | |
20 | * that are supported by the host, e.g. s390x. We can force the pointer to | |
21 | * have our known alignment with __builtin_assume_aligned, however prior to | |
22 | * GCC 13 that was only reliable with optimization enabled. See | |
23 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107389 | |
24 | */ | |
25 | #if defined(CONFIG_ATOMIC128_OPT) | |
26 | # if !defined(__OPTIMIZE__) | |
27 | # define ATTRIBUTE_ATOMIC128_OPT __attribute__((optimize("O1"))) | |
28 | # endif | |
29 | # define CONFIG_ATOMIC128 | |
30 | #endif | |
31 | #ifndef ATTRIBUTE_ATOMIC128_OPT | |
32 | # define ATTRIBUTE_ATOMIC128_OPT | |
33 | #endif | |
34 | ||
e6cd4bb5 RH |
35 | /* |
36 | * GCC is a house divided about supporting large atomic operations. | |
37 | * | |
38 | * For hosts that only have large compare-and-swap, a legalistic reading | |
39 | * of the C++ standard means that one cannot implement __atomic_read on | |
40 | * read-only memory, and thus all atomic operations must synchronize | |
41 | * through libatomic. | |
42 | * | |
43 | * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80878 | |
44 | * | |
45 | * This interpretation is not especially helpful for QEMU. | |
7893e42d PMD |
46 | * For system-mode, all RAM is always read/write from the hypervisor. |
47 | * For user-mode, if the guest doesn't implement such an __atomic_read | |
e6cd4bb5 RH |
48 | * then the host need not worry about it either. |
49 | * | |
50 | * Moreover, using libatomic is not an option, because its interface is | |
51 | * built for std::atomic<T>, and requires that *all* accesses to such an | |
52 | * object go through the library. In our case we do not have an object | |
53 | * in the C/C++ sense, but a view of memory as seen by the guest. | |
54 | * The guest may issue a large atomic operation and then access those | |
55 | * pieces using word-sized accesses. From the hypervisor, we have no | |
56 | * way to connect those two actions. | |
57 | * | |
58 | * Therefore, special case each platform. | |
59 | */ | |
60 | ||
412db3d5 | 61 | #include "host/atomic128-cas.h" |
15469133 | 62 | #include "host/atomic128-ldst.h" |
e6cd4bb5 RH |
63 | |
64 | #endif /* QEMU_ATOMIC128_H */ |