-
Notifications
You must be signed in to change notification settings - Fork 27
/
funcs_c.h
193 lines (160 loc) · 6.05 KB
/
funcs_c.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/******************************************************************************
* funcs_c.h
*
* All Test Functions in C code: they are codenamed as
* Scan/Perm Read/Write 32/64/128/256 Ptr/Index Simple/Unroll Loop.
*
* Scan = consecutive scanning, Perm = walk permutation cycle.
* Read/Write = obvious
* 32/64/128/256 = size of access
* Ptr = with pointer, Index = access as array[i]
* Simple/Unroll = 1 or 16 operations per loop
*
******************************************************************************
* Copyright (C) 2013 Timo Bingmann <[email protected]>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#warning "The C implementations of these loops are subject to compiler optimizations of all kinds."
#warning "For getting reliable results it is recommended to replace them with inline assembly."
// ****************************************************************************
// ----------------------------------------------------------------------------
// 64-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 64-bit writer in a simple loop (C version)
void cScanWrite64PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
uint64_t* begin = (uint64_t*)memarea;
uint64_t* end = begin + size / sizeof(uint64_t);
uint64_t value = 0xC0FFEEEEBABE0000;
do {
uint64_t* p = begin;
do {
*p++ = value;
}
while (p < end);
}
while (--repeats != 0);
}
REGISTER(cScanWrite64PtrSimpleLoop, 8, 8, 1);
// -----------------------------------------------------------------------------
// 64-bit writer in an indexed loop (C version)
void cScanWrite64IndexSimpleLoop(char* _memarea, size_t _size, size_t repeats)
{
uint64_t* memarea = (uint64_t*)_memarea;
uint64_t size = _size / sizeof(uint64_t);
uint64_t value = 0xC0FFEEEEBABE0000;
do {
for (size_t i = 0; i < size; ++i)
memarea[i] = value;
}
while (--repeats != 0);
}
REGISTER(cScanWrite64IndexSimpleLoop, 8, 8, 1);
// ****************************************************************************
// ----------------------------------------------------------------------------
// 128-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 128-bit writer in a simple loop (C version)
void cScanWrite128PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
typedef std::pair<uint64_t,uint64_t> uint128;
uint128* begin = (uint128*)memarea;
uint128* end = begin + size / sizeof(uint128);
uint64_t val64 = 0xC0FFEEEEBABE0000;
uint128 value = uint128(val64,val64);
do {
uint128* p = begin;
do {
*p++ = value;
}
while(p < end);
}
while (--repeats != 0);
}
REGISTER(cScanWrite128PtrSimpleLoop, 16, 16, 1);
// ****************************************************************************
// ----------------------------------------------------------------------------
// 32-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 32-bit writer in a simple loop (C version)
void cScanWrite32PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t* begin = (uint32_t*)memarea;
uint32_t* end = begin + size / sizeof(uint32_t);
uint32_t value = 0xC0FFEEEE;
do {
uint32_t* p = begin;
do {
*p++ = value;
}
while (p < end);
}
while (--repeats != 0);
}
REGISTER(cScanWrite32PtrSimpleLoop, 4, 4, 1);
// -----------------------------------------------------------------------------
// 32-bit writer in an indexed loop (C version)
void cScanWrite32IndexSimpleLoop(char* _memarea, size_t _size, size_t repeats)
{
uint32_t* memarea = (uint32_t*)_memarea;
size_t size = _size / sizeof(uint32_t);
uint32_t value = 0xC0FFEEEE;
do {
for (size_t i = 0; i < size; ++i)
memarea[i] = value;
}
while (--repeats != 0);
}
REGISTER(cScanWrite32IndexSimpleLoop, 4, 4, 1);
// ****************************************************************************
// ----------------------------------------------------------------------------
// Permutation Walking
// ----------------------------------------------------------------------------
// ****************************************************************************
#ifndef __LP64__
// follow 32-bit permutation in a simple loop (C version)
void cPermRead32SimpleLoop(char* memarea, size_t, size_t repeats)
{
uint32_t* begin = (uint32_t*)memarea;
do {
uint32_t* p = begin;
do {
p = (uint32_t*)*p;
}
while (p != begin);
}
while (--repeats != 0);
}
REGISTER_PERM(cPermRead32SimpleLoop, 4);
#else
// follow 64-bit permutation in a simple loop (C version)
void cPermRead64SimpleLoop(char* memarea, size_t, size_t repeats)
{
uint64_t* begin = (uint64_t*)memarea;
do {
uint64_t* p = begin;
do {
p = (uint64_t*)*p;
}
while (p != begin);
}
while (--repeats != 0);
}
REGISTER_PERM(cPermRead64SimpleLoop, 8);
#endif
// -----------------------------------------------------------------------------