v2 / thirdparty / libatomic_ops / atomic_ops / sysdeps / standard_ao_double_t.h
91 lines · 84 sloc · 4.19 KB · f53b5d737fd636890520101e736ad29e20d3c322
Raw
1/*
2 * Copyright (c) 2004-2011 Hewlett-Packard Development Company, L.P.
3 * Copyright (c) 2012-2021 Ivan Maidanski
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24/* For 64-bit systems, we expect the double type to hold two int64's. */
25
26#if (((defined(__x86_64__) && defined(AO_GCC_ATOMIC_TEST_AND_SET)) \
27 || defined(__aarch64__)) && !defined(__ILP32__)) \
28 || (defined(__e2k__) && __SIZEOF_SIZE_T__ == 8) \
29 || (defined(__riscv) && __riscv_xlen == 64)
30 /* x86-64: __m128 is not applicable to atomic intrinsics. */
31# if AO_GNUC_PREREQ(4, 7) || AO_CLANG_PREREQ(3, 6)
32# pragma GCC diagnostic push
33 /* Suppress warning about __int128 type. */
34# if defined(__clang__) || AO_GNUC_PREREQ(6, 0)
35# pragma GCC diagnostic ignored "-Wpedantic"
36# else
37 /* GCC before ~4.8 does not accept "-Wpedantic" quietly. */
38# pragma GCC diagnostic ignored "-pedantic"
39# endif
40 typedef unsigned __int128 double_ptr_storage;
41# pragma GCC diagnostic pop
42# else /* pragma diagnostic is not supported */
43 typedef unsigned __int128 double_ptr_storage;
44# endif
45#elif defined(_M_ARM64) && defined(_MSC_VER)
46 /* __int128 does not seem to be available. */
47 typedef __declspec(align(16)) unsigned __int64 double_ptr_storage[2];
48#elif ((defined(__x86_64__) && AO_GNUC_PREREQ(4, 0)) || defined(_WIN64)) \
49 && !defined(__ILP32__)
50 /* x86-64 (except for x32): __m128 serves as a placeholder which also */
51 /* requires the compiler to align it on 16-byte boundary (as required */
52 /* by cmpxchg16b). */
53 /* Similar things could be done for PPC 64-bit using a VMX data type. */
54# include <xmmintrin.h>
55 typedef __m128 double_ptr_storage;
56#elif defined(_WIN32) && !defined(__GNUC__)
57 typedef unsigned __int64 double_ptr_storage;
58#elif defined(__i386__) && defined(__GNUC__)
59 typedef unsigned long long double_ptr_storage
60 __attribute__((__aligned__(8)));
61#else
62 typedef unsigned long long double_ptr_storage;
63#endif
64# define AO_HAVE_DOUBLE_PTR_STORAGE
65
66typedef union {
67 struct { AO_t AO_v1; AO_t AO_v2; } AO_parts;
68 /* Note that AO_v1 corresponds to the low or the high part of */
69 /* AO_whole depending on the machine endianness. */
70 double_ptr_storage AO_whole;
71 /* AO_whole is now (starting from v7.3alpha3) the 2nd element */
72 /* of this union to make AO_DOUBLE_T_INITIALIZER portable */
73 /* (because __m128 definition could vary from a primitive type */
74 /* to a structure or array/vector). */
75} AO_double_t;
76#define AO_HAVE_double_t
77
78/* Note: AO_double_t volatile variables are not intended to be local */
79/* ones (at least those which are passed to AO double-wide primitives */
80/* as the first argument), otherwise it is the client responsibility to */
81/* ensure they have double-word alignment. */
82
83/* Dummy declaration as a compile-time assertion for AO_double_t size. */
84struct AO_double_t_size_static_assert {
85 char dummy[sizeof(AO_double_t) == 2 * sizeof(AO_t) ? 1 : -1];
86};
87
88#define AO_DOUBLE_T_INITIALIZER { { (AO_t)0, (AO_t)0 } }
89
90#define AO_val1 AO_parts.AO_v1
91#define AO_val2 AO_parts.AO_v2
92