forked from ColinIanKing/stress-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core-nt-store.h
171 lines (161 loc) · 5.19 KB
/
core-nt-store.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright (C) 2022-2023 Colin Ian King
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef CORE_NT_STORE_H
#define CORE_NT_STORE_H
#include "core-arch.h"
#if defined(HAVE_IMMINTRIN_H)
#include <immintrin.h>
#endif
#if defined(HAVE_XMMINTRIN_H) && \
defined(__SSE__)
#include <xmmintrin.h>
#endif
/* Non-temporal store writes */
/*
* 128 bit non-temporal stores
*/
#if defined(HAVE_INT128_T) && \
defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_NONTEMPORAL_STORE)
/* Clang non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store128(__uint128_t *addr, register __uint128_t value)
{
__builtin_nontemporal_store(value, addr);
}
#define HAVE_NT_STORE128
#elif defined(HAVE_XMMINTRIN_H) && \
defined(__SSE__) && \
defined(HAVE_INT128_T) && \
defined(HAVE_V2DI) && \
defined(STRESS_ARCH_X86_64) && \
defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_IA32_MOVNTDQ)
/* gcc x86 non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store128(__uint128_t *addr, register __uint128_t value)
{
__builtin_ia32_movntdq((__v2di *)addr, (__v2di)value);
}
#define HAVE_NT_STORE128
#elif defined(HAVE_IMMINTRIN_H) && \
defined(HAVE_INT128_T) && \
defined(STRESS_ARCH_X86_64) && \
defined(HAVE_MM_STREAM_SI128)
/* icc x86 non-temportal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store128(__uint128_t *addr, register __uint128_t value)
{
_mm_stream_si128((__m128i *)addr, (__m128i)value);
}
#define HAVE_NT_STORE128
#endif
/*
* 64 bit non-temporal stores
*/
#if defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_NONTEMPORAL_STORE)
/* Clang non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store64(uint64_t *addr, register uint64_t value)
{
__builtin_nontemporal_store(value, addr);
}
#define HAVE_NT_STORE64
#elif defined(HAVE_XMMINTRIN_H) && \
defined(__SSE__) && \
defined(STRESS_ARCH_X86_64) && \
defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_IA32_MOVNTI64)
/* gcc x86 non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store64(uint64_t *addr, register uint64_t value)
{
__builtin_ia32_movnti64((long long int *)addr, (long long int)value);
}
#define HAVE_NT_STORE64
#elif defined(HAVE_IMMINTRIN_H) && \
defined(STRESS_ARCH_X86_64) && \
defined(HAVE_MM_STREAM_SI64)
/* icc x86 non-temportal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store64(uint64_t *addr, register uint64_t value)
{
_mm_stream_si64((__int64 *)addr, (__int64)value);
}
#define HAVE_NT_STORE64
#endif
/*
* 32 bit non-temporal stores
*/
#if defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_NONTEMPORAL_STORE)
/* Clang non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store32(uint32_t *addr, register uint32_t value)
{
__builtin_nontemporal_store(value, addr);
}
#define HAVE_NT_STORE32
#elif defined(HAVE_XMMINTRIN_H) && \
defined(__SSE__) && \
defined(STRESS_ARCH_X86_64) && \
defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_IA32_MOVNTI)
/* gcc x86 non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store32(uint32_t *addr, register uint32_t value)
{
__builtin_ia32_movnti((int *)addr, value);
}
#define HAVE_NT_STORE32
#elif defined(HAVE_IMMINTRIN_H) && \
defined(STRESS_ARCH_X86_64) && \
defined(HAVE_MM_STREAM_SI64)
/* icc x86 non-temportal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store32(uint32_t *addr, register uint32_t value)
{
_mm_stream_si32((int *)addr, (int)value);
}
#define HAVE_NT_STORE32
#endif
/*
* double precision float non-temporal stores
*/
#if defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_NONTEMPORAL_STORE)
/* Clang non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store_double(double *addr, register double value)
{
__builtin_nontemporal_store(value, addr);
}
#define HAVE_NT_STORE_DOUBLE
#elif defined(HAVE_XMMINTRIN_H) && \
defined(__SSE__) && \
defined(STRESS_ARCH_X86_64) && \
defined(HAVE_BUILTIN_SUPPORTS) && \
defined(HAVE_BUILTIN_IA32_MOVNTI64)
/* gcc x86 non-temporal stores */
static inline void ALWAYS_INLINE OPTIMIZE3 stress_nt_store_double(double *addr, double value)
{
if (sizeof(double) == sizeof(uint64_t)) {
union alias {
uint64_t u;
double d;
};
__builtin_ia32_movnti64((long long int *)addr, ((union alias)value).u);
} else {
*addr = value;
}
}
#define HAVE_NT_STORE_DOUBLE
#endif
#endif