]> git.proxmox.com Git - mirror_qemu.git/blob - include/qemu/atomic128.h
Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging
[mirror_qemu.git] / include / qemu / atomic128.h
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 *
9 * See docs/devel/atomics.rst for discussion about the guarantees each
10 * atomic primitive is meant to provide.
11 */
12
13 #ifndef QEMU_ATOMIC128_H
14 #define QEMU_ATOMIC128_H
15
16 #include "qemu/int128.h"
17
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
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.
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
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
61 #include "host/atomic128-cas.h"
62 #include "host/atomic128-ldst.h"
63
64 #endif /* QEMU_ATOMIC128_H */