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