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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
/*
* Copyright 2011 Christoph Bumiller
* 2014 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "codegen/nv50_ir_target_gm107.h"
#include "codegen/nv50_ir_lowering_gm107.h"
namespace nv50_ir {
Target *getTargetGM107(unsigned int chipset)
{
return new TargetGM107(chipset);
}
// BULTINS / LIBRARY FUNCTIONS:
// lazyness -> will just hardcode everything for the time being
#include "lib/gm107.asm.h"
void
TargetGM107::getBuiltinCode(const uint32_t **code, uint32_t *size) const
{
*code = (const uint32_t *)&gm107_builtin_code[0];
*size = sizeof(gm107_builtin_code);
}
uint32_t
TargetGM107::getBuiltinOffset(int builtin) const
{
assert(builtin < NVC0_BUILTIN_COUNT);
return gm107_builtin_offsets[builtin];
}
bool
TargetGM107::isOpSupported(operation op, DataType ty) const
{
switch (op) {
case OP_SAD:
case OP_POW:
case OP_DIV:
case OP_MOD:
return false;
case OP_SQRT:
if (ty == TYPE_F64)
return false;
return chipset >= NVISA_GM200_CHIPSET;
case OP_XMAD:
if (isFloatType(ty))
return false;
break;
default:
break;
}
return true;
}
// Return true when an instruction supports the reuse flag. When supported, the
// hardware will use the operand reuse cache introduced since Maxwell, which
// should try to reduce bank conflicts by caching values for the subsequent
// instructions. Note that the next instructions have to use the same GPR id in
// the same operand slot.
bool
TargetGM107::isReuseSupported(const Instruction *insn) const
{
const OpClass cl = getOpClass(insn->op);
// TODO: double-check!
switch (cl) {
case OPCLASS_ARITH:
case OPCLASS_COMPARE:
case OPCLASS_LOGIC:
case OPCLASS_MOVE:
case OPCLASS_SHIFT:
return true;
case OPCLASS_BITFIELD:
if (insn->op == OP_INSBF || insn->op == OP_EXTBF)
return true;
break;
default:
break;
}
return false;
}
// Return true when an instruction requires to set up a barrier because it
// doesn't operate at a fixed latency. Variable latency instructions are memory
// operations, double precision operations, special function unit operations
// and other low throughput instructions.
bool
TargetGM107::isBarrierRequired(const Instruction *insn) const
{
const OpClass cl = getOpClass(insn->op);
if (insn->dType == TYPE_F64 || insn->sType == TYPE_F64)
return true;
switch (cl) {
case OPCLASS_ATOMIC:
case OPCLASS_LOAD:
case OPCLASS_STORE:
case OPCLASS_SURFACE:
case OPCLASS_TEXTURE:
return true;
case OPCLASS_SFU:
switch (insn->op) {
case OP_COS:
case OP_EX2:
case OP_LG2:
case OP_LINTERP:
case OP_PINTERP:
case OP_RCP:
case OP_RSQ:
case OP_SIN:
case OP_SQRT:
return true;
default:
break;
}
break;
case OPCLASS_BITFIELD:
switch (insn->op) {
case OP_BFIND:
case OP_POPCNT:
return true;
default:
break;
}
break;
case OPCLASS_CONTROL:
switch (insn->op) {
case OP_EMIT:
case OP_RESTART:
return true;
default:
break;
}
break;
case OPCLASS_OTHER:
switch (insn->op) {
case OP_AFETCH:
case OP_PFETCH:
case OP_PIXLD:
case OP_SHFL:
return true;
case OP_RDSV:
return !isCS2RSV(insn->getSrc(0)->reg.data.sv.sv);
default:
break;
}
break;
case OPCLASS_ARITH:
if ((insn->op == OP_MUL || insn->op == OP_MAD) &&
!isFloatType(insn->dType))
return true;
break;
case OPCLASS_CONVERT:
if (insn->def(0).getFile() != FILE_PREDICATE &&
insn->src(0).getFile() != FILE_PREDICATE)
return true;
break;
default:
break;
}
return false;
}
bool
TargetGM107::canDualIssue(const Instruction *a, const Instruction *b) const
{
// TODO
return false;
}
// Return the number of stall counts needed to complete a single instruction.
// On Maxwell GPUs, the pipeline depth is 6, but some instructions require
// different number of stall counts like memory operations.
int
TargetGM107::getLatency(const Instruction *insn) const
{
// TODO: better values! This should be good enough for now though.
switch (insn->op) {
case OP_EMIT:
case OP_EXPORT:
case OP_PIXLD:
case OP_RESTART:
case OP_STORE:
case OP_SUSTB:
case OP_SUSTP:
return 1;
case OP_SHFL:
return 2;
case OP_ADD:
case OP_AND:
case OP_EXTBF:
case OP_FMA:
case OP_INSBF:
case OP_MAD:
case OP_MAX:
case OP_MIN:
case OP_MOV:
case OP_MUL:
case OP_NOT:
case OP_OR:
case OP_PREEX2:
case OP_PRESIN:
case OP_QUADOP:
case OP_SELP:
case OP_SET:
case OP_SET_AND:
case OP_SET_OR:
case OP_SET_XOR:
case OP_SHL:
case OP_SHLADD:
case OP_SHR:
case OP_SLCT:
case OP_SUB:
case OP_VOTE:
case OP_XOR:
case OP_XMAD:
if (insn->dType != TYPE_F64)
return 6;
break;
case OP_RDSV:
return isCS2RSV(insn->getSrc(0)->reg.data.sv.sv) ? 6 : 15;
case OP_ABS:
case OP_CEIL:
case OP_CVT:
case OP_FLOOR:
case OP_NEG:
case OP_SAT:
case OP_TRUNC:
if (insn->op == OP_CVT && (insn->def(0).getFile() == FILE_PREDICATE ||
insn->src(0).getFile() == FILE_PREDICATE))
return 6;
break;
case OP_BFIND:
case OP_COS:
case OP_EX2:
case OP_LG2:
case OP_POPCNT:
case OP_QUADON:
case OP_QUADPOP:
case OP_RCP:
case OP_RSQ:
case OP_SIN:
case OP_SQRT:
return 13;
default:
break;
}
// Use the maximum number of stall counts for other instructions.
return 15;
}
// Return the operand read latency which is the number of stall counts before
// an instruction can read its sources. For memory operations like ATOM, LOAD
// and STORE, the memory access has to be indirect.
int
TargetGM107::getReadLatency(const Instruction *insn) const
{
switch (insn->op) {
case OP_ABS:
case OP_BFIND:
case OP_CEIL:
case OP_COS:
case OP_EX2:
case OP_FLOOR:
case OP_LG2:
case OP_NEG:
case OP_POPCNT:
case OP_RCP:
case OP_RSQ:
case OP_SAT:
case OP_SIN:
case OP_SQRT:
case OP_SULDB:
case OP_SULDP:
case OP_SUREDB:
case OP_SUREDP:
case OP_SUSTB:
case OP_SUSTP:
case OP_TRUNC:
return 4;
case OP_CVT:
if (insn->def(0).getFile() != FILE_PREDICATE &&
insn->src(0).getFile() != FILE_PREDICATE)
return 4;
break;
case OP_ATOM:
case OP_LOAD:
case OP_STORE:
if (insn->src(0).isIndirect(0)) {
switch (insn->src(0).getFile()) {
case FILE_MEMORY_SHARED:
case FILE_MEMORY_CONST:
return 2;
case FILE_MEMORY_GLOBAL:
case FILE_MEMORY_LOCAL:
return 4;
default:
break;
}
}
break;
case OP_EXPORT:
case OP_PFETCH:
case OP_SHFL:
case OP_VFETCH:
return 2;
default:
break;
}
return 0;
}
bool
TargetGM107::isCS2RSV(SVSemantic sv) const
{
return sv == SV_CLOCK;
}
bool
TargetGM107::runLegalizePass(Program *prog, CGStage stage) const
{
if (stage == CG_STAGE_PRE_SSA) {
GM107LoweringPass pass(prog);
return pass.run(prog, false, true);
} else
if (stage == CG_STAGE_POST_RA) {
NVC0LegalizePostRA pass(prog);
return pass.run(prog, false, true);
} else
if (stage == CG_STAGE_SSA) {
GM107LegalizeSSA pass;
return pass.run(prog, false, true);
}
return false;
}
CodeEmitter *
TargetGM107::getCodeEmitter(Program::Type type)
{
return createCodeEmitterGM107(type);
}
} // namespace nv50_ir
|