1 /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Transactional Memory Library (libitm).
6 Libitm is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #ifndef LIBITM_CACHELINE_H
26 #define LIBITM_CACHELINE_H 1
28 // Minimum cacheline size is 32, due to both complex long double and __m256.
29 // There's no requirement that 64-bit use a 64-byte cacheline size, but do
30 // so for now to make sure everything is parameterized properly.
32 # define CACHELINE_SIZE 64
34 # define CACHELINE_SIZE 32
37 namespace GTM HIDDEN
{
39 // A gtm_cacheline_mask stores a modified bit for every modified byte
40 // in the cacheline with which it is associated.
41 typedef sized_integral
<CACHELINE_SIZE
/ 8>::type gtm_cacheline_mask
;
45 // Byte access to the cacheline.
46 unsigned char b
[CACHELINE_SIZE
] __attribute__((aligned(CACHELINE_SIZE
)));
48 // Larger sized access to the cacheline.
49 uint16_t u16
[CACHELINE_SIZE
/ sizeof(uint16_t)];
50 uint32_t u32
[CACHELINE_SIZE
/ sizeof(uint32_t)];
51 uint64_t u64
[CACHELINE_SIZE
/ sizeof(uint64_t)];
52 gtm_word w
[CACHELINE_SIZE
/ sizeof(gtm_word
)];
55 __m64 m64
[CACHELINE_SIZE
/ sizeof(__m64
)];
58 __m128 m128
[CACHELINE_SIZE
/ sizeof(__m128
)];
61 __m128i m128i
[CACHELINE_SIZE
/ sizeof(__m128i
)];
64 __m256 m256
[CACHELINE_SIZE
/ sizeof(__m256
)];
65 __m256i m256i
[CACHELINE_SIZE
/ sizeof(__m256i
)];
68 #if defined(__SSE__) || defined(__AVX__)
69 // Copy S to D; only bother defining if we can do this more efficiently
70 // than the compiler-generated default implementation.
71 gtm_cacheline
& operator= (const gtm_cacheline
&s
);
75 #if defined(__SSE__) || defined(__AVX__)
76 inline gtm_cacheline
& ALWAYS_INLINE
77 gtm_cacheline::operator= (const gtm_cacheline
& __restrict s
)
89 // ??? Wouldn't it be nice to have a pragma to tell the compiler
90 // to completely unroll a given loop?
91 switch (CACHELINE_SIZE
/ sizeof(TYPE
))
94 this->CP
[0] = s
.CP
[0];
125 #endif // LIBITM_CACHELINE_H