-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.py
More file actions
582 lines (522 loc) · 25 KB
/
generate.py
File metadata and controls
582 lines (522 loc) · 25 KB
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
import sys, os, subprocess, argparse, logging, json, tempfile, multiprocessing, shutil, re
# Try to more extensively check the cost model figures coming out of the cost model, for every operation x type combo.
# Currently it looks at costsize costs, as those are easier to measure.
# Measures codesize from llc with some filtering.
# Can add other costs in the future, they are more difficult to measure correctly.
# Run this to generate data.json
# python llvm/utils/costmodeltest.py
# and this to serve is to pert 8081, inside a venv with pandas
# python llvm/utils/costmodeltest.py --servellvm/utils/costmodeltest.py
logging.basicConfig(stream=sys.stdout, level=logging.WARNING, format='')
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
def run(cmd):
logging.debug('> ' + cmd)
cmd = cmd.split()
return subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode('utf-8')
def parseCostLine(line):
costpre = 'Cost Model: Found costs of '
if not line.startswith(costpre):
return [0,0,0,0]
line = line[len(costpre):line.find(' for: ')]
def parseint(cost):
if cost.strip() == "Invalid":
return -1
return int(cost)
if "RThru" in line:
costs=line.replace(':', ' ').split(' ')
return [parseint(costs[1]), parseint(costs[3]), parseint(costs[5]), parseint(costs[7])]
cost = parseint(line)
return [cost, cost, cost, cost]
def getcost(path):
try:
text = run(f"opt {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.attr if args.mattr else ''} {os.path.join(path, 'costtest.ll')} -passes=print<cost-model> -cost-kind=all -disable-output")
except subprocess.CalledProcessError as e:
shutil.copyfile(os.path.join(path, 'costtest.ll'), 'costtest.ll')
return (-1, -1, -1, -1, str(e))
if print:
logging.debug(text.strip())
costs = [x for x in text.split('\n') if 'for: ret ' not in x]
costs = [parseCostLine(x) for x in costs]
def sumcost(costs, idx):
if len([c for c in costs if c[idx]<0]) > 0:
return -1
return sum([c[idx] for c in costs])
return (sumcost(costs, 0), sumcost(costs, 1), sumcost(costs, 2), sumcost(costs, 3), text.strip())
def getasm(path, extraflags):
try:
run(f"llc {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.attr if args.mattr else ''} {extraflags} {os.path.join(path, 'costtest.ll')} -o {os.path.join(path, 'costtest.s')}")
except subprocess.CalledProcessError as e:
lines = [e.output.decode('utf-8').split('\n')[0]]
lines = [re.sub(r'llc: /.*/llvm', 'llc: llvm', l) for l in lines]
if "unable to legalize" in lines[0] or "cannot select" in lines[0] or "unable to translate" in lines[0]:
return (lines, -2)
return (lines, -1)
with open(os.path.join(path, "costtest.s")) as f:
lines = [l.strip() for l in f]
# This tries to remove .declarations, comments etc
lines = [l for l in lines if l[0] != '.' and l[0] != '/' and not l.startswith('test:')]
#logging.debug(lines)
# TODOD: Improve the filtering to what is invariant, somehow. Or include it in the costs.
#filteredlines = [l for l in lines if not l.startswith('movi') and not l.startswith('mov\tw') and l != 'ret' and not l.startswith('adrp') and not l.startswith('ldr') and not l.startswith('dup') and not l.startswith('fmov')]
filteredlines = [l for l in lines if l != 'ret' and not l.startswith('ptrue') and not re.match(r'fmov\sd[0-9], d[0-9]+',l) and not re.match(r'mov\sv[0-9].16b, v[0-9]+.16b', l)]
logging.debug(filteredlines)
size = len(filteredlines)
logging.debug(f"size = {size}")
return (lines, size)
def checkcosts(llasm):
logging.debug(llasm)
with tempfile.TemporaryDirectory() as tmp:
with open(os.path.join(tmp, "costtest.ll"), "w") as f:
f.write(llasm)
lines, size = getasm(tmp, '')
gilines, gisize = getasm(tmp, '-global-isel -aarch64-enable-gisel-sve')
sizes = getcost(tmp)
logging.debug(f"cost = throughput:{sizes[0]} codesize:{sizes[1]} lat:{sizes[2]} sizelat:{sizes[3]}")
return (size, gisize, sizes, llasm, ('\n'.join(lines)).replace('\t', ' '), ('\n'.join(gilines)).replace('\t', ' '))
# TODOD:
#if args.checkopted:
# run(f"opt {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.attr if args.mattr else ''} costtest.ll -O1 -S -o -")
def generate_const(ty, sameval):
consts = ['7', '6'] if not ty.isFloat() else ['7.0', '6.0']
if ty.elts == 1:
return consts[0]
if sameval:
return f"splat ({ty.scalar} {consts[0]})"
return "<" + ", ".join([f"{ty.scalar} {consts[0]}, {ty.scalar} {consts[1]}" for x in range(ty.elts // 2)]) + '>'
def generate_const0(ty):
if ty.elts == 1:
return '0' if not ty.isFloat() else ('0.0' if ty.scalar != 'fp128' else '0xL00000000000000000000000000000000')
return "zeroinitializer"
def generate_constm1(ty):
if ty.elts == 1:
return '-1'
return f"splat ({ty.scalar} -1)"
def zipf(it1, it2):
for i in zip(it1, it2):
yield i[0]
yield i[1]
def generateShuffleMask(elts, srcelts, variant):
mask = []
variant = variant[:variant.find(' ')]
n = elts // 2
if variant == 'identity':
# 0,1,2,3,..
mask = range(elts)
elif variant == 'reverse':
# 3,2,1,0
mask = reversed(range(elts))
elif variant == 'splat0':
# 0,0,0,0,...
mask = [0] * elts
elif variant == 'splat3':
# 3,3,3,3,...
mask = [min(3,srcelts-1)] * elts
elif variant == 'zip1':
# 0,n,1,n+1,2,...
mask = zipf(range(n), [srcelts//2 + i for i in range(n)])
elif variant == 'zip2':
# n/2,3n/2,n/2+1,3n/2+1,...
mask = zipf([srcelts//4 + i for i in range(n)], [3*srcelts//4 + i for i in range(n)])
elif variant == 'uzp1':
# 0,2,4,6,...
mask = [2*i for i in range(elts)]
elif variant == 'uzp2':
# 1,3,5,7,...
mask = [2*i + 1 for i in range(elts)]
elif variant == 'trn1':
# 0,n,2,n+2,...
mask = zipf([2*i for i in range(n)], [srcelts//2 + 2*i for i in range(n)])
elif variant == 'trn2':
# 1,n+1,3,n+3,...
mask = zipf([2*i + 1 for i in range(n)], [srcelts//2 + 2*i + 1 for i in range(n)])
elif variant == 'splice2':
# 2,3,..,0,1
mask = list(range(2,elts))+[0,1]
else:
assert(False)
mask = [str(x) for x in mask]
return f"<{elts} x i32> <i32 {', i32 '.join(mask)}>"
def generate(variant, instr, ty, ty2):
tystr = ty.str()
eltstr = ty.scalar
rettystr = eltstr if instr == 'extractelement' else (tystr if variant=='binopi' else ty2.str())
preamble = f"define {rettystr} @test({tystr} %a"
if variant == 'binop' or variant == 'cmp' or variant == 'triopconstsplat' or instr == 'shuffleb':
preamble += f", {tystr} %b"
elif variant == 'binopsplat' or instr == 'insertelement':
preamble += f", {eltstr} %bs"
elif variant == 'triop' and instr == 'select':
preamble += f", {tystr} %b, {Ty('i1', ty.elts, ty.scalable)} %c"
elif variant == 'triop':
preamble += f", {tystr} %b, {tystr} %c"
elif variant.startswith('reduce') and (instr == 'reduce.fadd' or instr == 'reduce.fmul'):
preamble += f", {rettystr} %b"
elif variant == 'binopi':
preamble += f", {ty2.str()} %b"
if variant == 'vecopvar':
preamble += f", i32 %c"
if (variant == 'cmp' or variant == 'cmp0') and instr.startswith('select'):
preamble += f", {tystr} %d, {tystr} %e"
preamble += ") "
if args.vscale:
preamble += f"vscale_range({args.vscale}, {args.vscale})"
preamble += "{\n"
setup = ""
if variant == "binopsplat":
setup += f" %i = insertelement {tystr} poison, {eltstr} %bs, i64 0\n"
setup += f" %b = shufflevector {tystr} %i, {tystr} poison, <{ty.vecpart()} x i32> zeroinitializer\n"
instrstr = ""
b = "%b"
c = "%c"
if "const" in variant and "triop" in variant:
c = generate_const(ty, variant == 'triopconstsplat')
elif "const" in variant:
b = generate_const(ty, variant == 'binopconstsplat')
elif variant == 'mvn':
b = generate_constm1(ty)
elif variant == 'cmp0':
b = generate_const0(ty)
if instr in ['add', 'sub', 'mul', 'sdiv', 'srem', 'udiv', 'urem', 'and', 'or', 'xor', 'shl', 'ashr', 'lshr', 'fadd', 'fsub', 'fmul', 'fdiv', 'frem']:
instrstr += f" %r = {instr} {tystr} %a, {b}\n"
elif instr in ['rotr', 'rotl']:
instrstr += f" %r = call {tystr} @llvm.fsh{instr[3]}({tystr} %a, {tystr} %a, {tystr} {b})\n"
elif instr in ['fneg']:
instrstr += f" %r = {instr} {tystr} %a\n"
elif instr == 'abs' or instr == 'ctlz' or instr == 'cttz':
instrstr += f" %r = call {tystr} @llvm.{instr}({tystr} %a, i1 0)\n"
elif instr == 'fptosi.sat' or instr == 'fptoui.sat':
instrstr += f" %r = call {rettystr} @llvm.{instr}({tystr} %a)\n"
elif variant == 'unop':
instrstr += f" %r = call {tystr} @llvm.{instr}({tystr} %a)\n"
elif variant == 'binopi':
instrstr += f" %r = call {tystr} @llvm.{instr}({tystr} %a, {ty2.str()} %b)\n"
elif instr in ['select']:
instrstr += f" %r = {instr} {Ty('i1', ty.elts, ty.scalable)} %c, {tystr} %a, {tystr} %b\n"
elif (variant == 'cmp' or variant == 'cmp0') and instr.startswith('select'):
instrstr += f" %c = {instr[6:10]} {instr[10:]} {tystr} %a, {b}\n %r = select {Ty('i1', ty.elts, ty.scalable)} %c, {tystr} %d, {tystr} %e\n"
elif variant == 'cmp' or variant == 'cmp0':
instrstr += f" %r = {instr[:4]} {instr[4:]} {tystr} %a, {b}\n"
elif variant.startswith('triop'):
instrstr += f" %r = call {tystr} @llvm.{instr}({tystr} %a, {tystr} %b, {tystr} {c})\n"
elif variant.startswith('reduce') and (instr == 'reduce.fadd' or instr == 'reduce.fmul'):
instrstr += f" %r = call {'fast ' if variant == 'reducefast' else ''}{rettystr} @llvm.vector.{instr}({rettystr} %b, {tystr} %a)\n"
elif variant.startswith('reduce'):
instrstr += f" %r = call {'fast ' if variant == 'reducefast' else ''}{rettystr} @llvm.vector.{instr}({tystr} %a)\n"
elif instr == 'extractelement':
idx = '%c' if variant == 'vecopvar' else ('1' if variant == 'vecop1' else '0')
instrstr += f" %r = extractelement {tystr} %a, i32 {idx}\n"
elif instr == 'insertelement':
idx = '%c' if variant == 'vecopvar' else ('1' if variant == 'vecop1' else '0')
instrstr += f" %r = insertelement {tystr} %a, {eltstr} %bs, i32 {idx}\n"
elif instr in ['llrint', 'lrint', 'llround', 'lround']:
instrstr += f" %r = call {rettystr} @llvm.{instr}({tystr} %a)\n"
elif variant.startswith('cast'):
instrstr += f" %r = {instr} {tystr} %a to {rettystr}\n"
elif instr == "shuffleu":
instrstr += f" %r = shufflevector {tystr} %a, {tystr} poison, {generateShuffleMask(ty2.elts, ty.elts, variant)}\n"
elif instr == "shuffleb":
instrstr += f" %r = shufflevector {tystr} %a, {tystr} %b, {generateShuffleMask(ty2.elts, ty.elts*2, variant)}\n"
else:
instrstr += f" %r = call {tystr} @llvm.{instr}({tystr} %a, {tystr} {b})\n"
return preamble + setup + instrstr + f" ret {rettystr} %r\n}}"
class Ty:
def __init__(self, scalar, elts=1, scalable=0):
self.scalar = scalar
self.elts = elts
self.scalable = scalable
def isFloat(self):
return self.scalar[0] != 'i'
def scalarsize(self):
return int(self.scalar[1:]) if self.scalar[0] == 'i' else fptymap[self.scalar]
def str(self):
if self.elts == 1 and not self.scalable:
return self.scalar
return f"<{self.vecpart()} x {self.scalar}>"
def vecpart(self):
if self.scalable:
return f"vscale x {self.elts}"
return f"{self.elts}"
def __repr__(self):
return self.str()
fptymap = { 'half':16, 'bfloat':16, 'float':32, 'double':64, "fp128":128 }
def inttypes(lowsizes = False, highsizes = False):
# TODO: i128, other type sizes?
# TODO: More sizes for more operations
for bits in [8, 16, 32, 64]:
yield Ty('i'+str(bits))
for scalable in [0,1]:
if scalable == 1 and (not args.mattr or 'sve' not in args.attr):
continue
for bits in [8, 16, 32, 64]:
for s in [2, 4, 8, 16, 32]:
if not highsizes and s * bits > 256:
continue
if not lowsizes and s * bits < 64:
continue
yield Ty('i'+str(bits), s, scalable)
def fptypes(lowsizes = False, highsizes = False):
# TODO: f128? They are just libcalls
# TODO: More sizes for more operations
for bits in ['half', 'bfloat', 'float', 'double']:
yield Ty(bits)
for scalable in [0,1]:
if scalable == 1 and (not args.mattr or 'sve' not in args.attr):
continue
for bits in ['half', 'bfloat', 'float', 'double']:
for s in [2, 4, 8, 16, 32]:
if not highsizes and s * fptymap[bits] > 256:
continue
if not lowsizes and s * fptymap[bits] < 64:
continue
yield Ty(bits, s, scalable)
parser = argparse.ArgumentParser()
parser.add_argument('--type', choices=['all', 'int', 'fp', 'castint', 'castfp', 'vec'], default='all')
parser.add_argument('-mtriple', default='aarch64')
parser.add_argument('-mattr', default=None)
parser.add_argument('-vscale', default=None)
#parser.add_argument('--checkopted', action='store_true')
args = parser.parse_args()
args.attr = args.mattr
if args.attr == 'all':
args.attr = '+aes,+altnzcv,+am,+amvs,+bf16,+brbe,+bti,+btie,+ccdp,+ccidx,+ccpp,+chk,+clrbhb,+cmpbr,+complxnum,+cpa,+crc,+crypto,+cssc,+d128,+dit,+dotprod,+ecv,+ete,+f16f32dot,+f16f32mm,+f16mm,+f32mm,+f64mm,+f8f16mm,+f8f32mm,+faminmax,+fgt,+flagm,+fp-armv8,+fp16fml,+fp8,+fp8dot2,+fp8dot4,+fp8fma,+fpac,+fprcvt,+fptoint,+fullfp16,+gcie,+gcs,+hbc,+hcx,+i8mm,+ite,+jsconv,+lor,+ls64,+lscp,+lse,+lse128,+lse2,+lsfe,+lsui,+lut,+mec,+mops,+mops-go,+mpam,+mpamv2,+mte,+mtetc,+neon,+nmi,+nv,+occmo,+pan,+pan-rwv,+pauth,+pauth-lr,+perfmon,+poe2,+pops,+predres,+prfm-slc-target,+rand,+ras,+rasv2,+rcpc,+rcpc-immo,+rcpc3,+rdm,+rme,+sb,+sel2,+sha2,+sha3,+sm4,+sme,+sme-b16b16,+sme-f16f16,+sme-f64f64,+sme-f8f16,+sme-f8f32,+sme-fa64,+sme-i16i64,+sme-lutv2,+sme-mop4,+sme-tmop,+sme2,+sme2p1,+sme2p2,+sme2p3,+spe,+spe-eef,+specres2,+specrestrict,+ssbs,+ssve-aes,+ssve-bitperm,+ssve-fexpa,+ssve-fp8dot2,+ssve-fp8dot4,+ssve-fp8fma,+sve,+sve-aes,+sve-aes2,+sve-b16b16,+sve-b16mm,+sve-bfscale,+sve-bitperm,+sve-f16f32mm,+sve-sha3,+sve-sm4,+sve2,+sve2-aes,+sve2-bitperm,+sve2-sha3,+sve2-sm4,+sve2p1,+sve2p2,+sve2p3,+tagged-globals,+tev,+the,+tlb-rmi,+tlbid,+tlbiw,+tpidr-el1,+tpidr-el2,+tpidr-el3,+tpidrro-el0,+tracev8.4,+trbe,+uaops,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8.7a,+v8.8a,+v8.9a,+v9.1a,+v9.2a,+v9.3a,+v9.4a,+v9.5a,+v9.6a,+v9.7a,+v9a,+vh,+wfxt,+xs'
def getFileName(mid):
return f"data-{mid}{'-'+args.mattr if args.mattr else ''}{'-'+str(128*int(args.vscale)) if args.vscale else ''}.json"
def do(instr, variant, ty, ty2, tyoverride):
try:
logging.info(f"{variant} {instr} with {ty.str()}")
(size, gisize, costs, ll, asm, giasm) = checkcosts(generate(variant, instr, ty, ty2))
tystr = str(ty) if not tyoverride else tyoverride
if costs[0] != size:
logging.warning(f">>> {variant} {instr} with {tystr} size = {size} vs cost = {costs[0]}")
return {"instr":instr, "ty":tystr, "variant":variant, "codesize":costs[1], "thru":costs[0], "lat":costs[2], "sizelat":costs[3], "size":size, "gisize":gisize, "asm":asm, "giasm":giasm, "ll":ll, "costoutput":costs[4]}
except:
logging.error(f"error in: {variant} {instr} with {ty.str()} {ty2.str()}")
raise
# Operations are the ones in https://github.com/llvm/llvm-project/issues/115133
# TODO: load/store, bitcast, getelementptr, phi
if args.type == 'all' or args.type == 'int':
def enumint():
# Int Binops
for instr in ['add', 'sub', 'mul', 'and', 'or', 'xor', 'shl', 'ashr', 'lshr', 'sdiv', 'srem', 'udiv', 'urem', 'smin', 'smax', 'umin', 'umax', 'uadd.sat', 'usub.sat', 'sadd.sat', 'ssub.sat', 'rotr', 'rotl', 'clmul', 'scmp', 'ucmp']:
for ty in inttypes():
yield (instr, 'binop', ty, ty, None)
if instr in ['sdiv', 'srem', 'udiv', 'urem', 'shl', 'ashr', 'lshr', 'rotr', 'rotl']:
if not ty.scalable:
yield (instr, 'binopconst', ty, ty, None)
if ty.elts > 1:
yield (instr, 'binopsplat', ty, ty, None)
yield (instr, 'binopconstsplat', ty, ty, None)
# Int unops
for instr in ['abs', 'bitreverse', 'bswap', 'ctlz', 'cttz', 'ctpop']:
for ty in inttypes():
if instr == 'bswap' and ty.scalarsize() % 16 != 0:
continue
yield (instr, 'unop', ty, ty, None)
for instr in ['xor']:
for ty in inttypes():
yield (instr, 'mvn', ty, ty, None)
# Int triops
for instr in ['fshl', 'fshr', 'select']:
for ty in inttypes():
yield (instr, 'triop', ty, ty, None)
if instr != 'select':
yield (instr, 'triopconstsplat', ty, ty, None)
# icmp + icmp+select
for op in ['eq', 'ne', 'slt', 'sle', 'sgt', 'sge', 'ult', 'ule', 'ugt', 'uge']:
for ty in inttypes():
yield ('icmp'+op, 'cmp', ty, Ty('i1', ty.elts, ty.scalable), None)
yield ('icmp'+op, 'cmp0', ty, Ty('i1', ty.elts, ty.scalable), None)
yield ('selecticmp'+op, 'cmp', ty, ty, None)
yield ('selecticmp'+op, 'cmp0', ty, ty, None)
# TODO: mla?
# TODO: uaddo, usubo, uadde, usube?
# TODO: umulo, smulo?
# TODO: umulh, smulh
# TODO: ushlsat, sshlsat
# TODO: smulfix, umulfix
# TODO: smulfixsat, umulfixsat
# TODO: sdivfix, udivfix
# TODO: sdivfixsat, udivfixsat
# Reductions
for instr in ['add', 'mul', 'and', 'or', 'xor', 'smin', 'smax', 'umin', 'umax']:
for ty in inttypes():
if ty.elts == 1:
continue
yield ("reduce."+instr, 'reduce', ty, Ty(ty.scalar), None)
pool = multiprocessing.Pool(16)
data = pool.starmap(do, enumint())
with open(getFileName('int'), "w") as f:
json.dump(data, f, indent=1)
if args.type == 'all' or args.type == 'fp':
def enumfp():
# Floating point Binops
for instr in ['fadd', 'fsub', 'fmul', 'fdiv', 'frem', 'minnum', 'maxnum', 'minimum', 'maximum', 'copysign', 'pow']:
for ty in fptypes():
yield (instr, 'binop', ty, ty, None)
for instr in ['ldexp']:
for ty in fptypes():
yield (instr, 'binopi', ty, Ty('i32', ty.elts, ty.scalable), None)
for instr in ['powi']:
for ty in fptypes():
yield (instr, 'binopi', ty, Ty('i32'), None)
# FP unops
for instr in ['fneg', 'fabs', 'sqrt', 'ceil', 'floor', 'trunc', 'rint', 'nearbyint', 'round', 'roundeven', 'exp']:
for ty in fptypes():
yield (instr, 'unop', ty, ty, None)
# FP triops
for instr in ['fma', 'fmuladd', 'select']:
for ty in fptypes():
yield (instr, 'triop', ty, ty, None)
# fcmps
for op in ['oeq', 'ogt', 'oge', 'olt', 'ole', 'one', 'ord', 'ueq', 'ugt', 'uge', 'ult', 'ule', 'une', 'uno']:
for ty in fptypes():
yield ('fcmp'+op, 'cmp', ty, Ty('i1', ty.elts, ty.scalable), None)
yield ('fcmp'+op, 'cmp0', ty, Ty('i1', ty.elts, ty.scalable), None)
yield ('selectfcmp'+op, 'cmp', ty, ty, None)
yield ('selectfcmp'+op, 'cmp0', ty, ty, None)
# TODO: fmul+fadd?
# TODO: fminimumnum, fmaximumnum
# TODO: fpowi
# TODO: sin, cos, etc
# TODO: fexp2, flog, flog2, flog10
# TODO: fldexp, frexmp
for instr in ['fadd', 'fmul', 'fmin', 'fmax', 'fminimum', 'fmaximum']:
for ty in fptypes():
if ty.elts == 1:
continue
yield ("reduce."+instr, 'reduce', ty, Ty(ty.scalar), None)
yield ("reduce."+instr, 'reducefast', ty, Ty(ty.scalar), None)
pool = multiprocessing.Pool(16)
data = pool.starmap(do, enumfp())
with open(getFileName('fp'), "w") as f:
json.dump(data, f, indent=1)
if args.type == 'all' or args.type == 'castint':
def enumcast():
for ty1 in inttypes(True, True):
for ty2 in inttypes(True, True):
if ty1.elts != ty2.elts or ty1.scalable != ty2.scalable:
continue
if ty1.elts * min(ty1.scalarsize(), ty2.scalarsize()) > 256:
continue
if ty1.scalarsize() < ty2.scalarsize():
yield ('zext', 'cast '+ty2.scalar, ty1, ty2, None)
yield ('sext', 'cast '+ty2.scalar, ty1, ty2, None)
if ty1.scalarsize() > ty2.scalarsize():
yield ('trunc', 'cast '+ty2.scalar, ty1, ty2, None)
pool = multiprocessing.Pool(16)
data = pool.starmap(do, enumcast())
with open(getFileName('castint'), "w") as f:
json.dump(data, f, indent=1)
if args.type == 'all' or args.type == 'castfp':
def enumcast():
for instr in ['fptosi', 'fptoui', 'fptosi.sat', 'fptoui.sat']:
for ty1 in fptypes(True, False):
for ty2 in inttypes(True, True):
if ty1.elts != ty2.elts or ty1.scalable != ty2.scalable:
continue
yield (instr, 'cast '+ty2.scalar, ty1, ty2, None)
for instr in ['sitofp', 'uitofp']:
for ty1 in fptypes(True, False):
for ty2 in inttypes(True, True):
if ty1.elts != ty2.elts or ty1.scalable != ty2.scalable:
continue
yield (instr, 'cast '+ty2.scalar, ty2, ty1, str(ty1))
for instr in ['fpext']:
for ty1 in fptypes(True, False):
for ty2 in fptypes(True, False):
if ty1.elts != ty2.elts or ty1.scalable != ty2.scalable or ty1.scalarsize() >= ty2.scalarsize():
continue
if fptymap[ty1.scalar] < 32 and fptymap[ty2.scalar] < 32:
continue
yield (instr, 'cast '+ty2.scalar, ty1, ty2, None)
for instr in ['fptrunc']:
for ty1 in fptypes(True, False):
for ty2 in fptypes(True, False):
if ty1.elts != ty2.elts or ty1.scalable != ty2.scalable or ty1.scalarsize() <= ty2.scalarsize():
continue
if fptymap[ty1.scalar] < 32 and fptymap[ty2.scalar] < 32:
continue
yield (instr, 'cast '+ty2.scalar, ty1, ty2, None)
for instr in ['lrint', 'llrint', 'lround', 'llround']:
for ty1 in fptypes(True, False):
yield (instr, 'cast i64', ty1, Ty('i64', ty1.elts, ty1.scalable), None)
if not instr.startswith('ll'):
yield (instr, 'cast i32', ty1, Ty('i32', ty1.elts, ty1.scalable), None)
pool = multiprocessing.Pool(16)
data = pool.starmap(do, enumcast())
with open(getFileName('castfp'), "w") as f:
json.dump(data, f, indent=1)
if args.type == 'all' or args.type == 'vec':
def enumvec():
# Shuffles, 1src
for variant in ['identity', 'splat0', 'splat3', 'zip1', 'zip2', 'uzp1', 'uzp2', 'trn1', 'trn2', 'reverse', 'splice2']:
for dst in inttypes(True, True):
for src in inttypes(True, True):
if src.elts == 1 or dst.elts == 1 or src.scalar != dst.scalar or src.scalable or dst.scalable:
continue
if variant in ['identity', 'reverse'] and src.elts < dst.elts:
continue
if variant in ['zip1', 'zip2', 'uzp1', 'uzp2', 'trn1', 'trn2'] and src.elts < dst.elts*2:
continue
if variant in ['splice2'] and src.elts != dst.elts:
continue
yield ('shuffleu', variant+' v'+str(dst.elts), src, dst, None)
for dst in fptypes(True, True):
for src in fptypes(True, True):
if src.elts == 1 or dst.elts == 1 or src.scalar != dst.scalar or src.scalable or dst.scalable:
continue
if variant in ['identity', 'reverse'] and src.elts < dst.elts:
continue
if variant in ['zip1', 'zip2', 'uzp1', 'uzp2', 'trn1', 'trn2'] and src.elts < dst.elts*2:
continue
if variant in ['splice2'] and src.elts != dst.elts:
continue
yield ('shuffleu', variant+' v'+str(dst.elts), src, dst, None)
# TODO: subvector_insert
# TODO: subvector_extract
# TODO: Others? random, replicate,
# Shuffles, 2srcs
for variant in ['identity', 'zip1', 'zip2', 'uzp1', 'uzp2', 'trn1', 'trn2', 'reverse', 'splice2']:
for dst in inttypes(True, True):
for src in inttypes(True, True):
if src.elts == 1 or dst.elts == 1 or src.scalar != dst.scalar or src.scalable or dst.scalable:
continue
if variant in ['identity', 'reverse'] and src.elts * 2 < dst.elts:
continue
if variant in ['zip1', 'zip2', 'uzp1', 'uzp2', 'trn1', 'trn2'] and src.elts < dst.elts:
continue
if variant in ['splice2'] and src.elts != dst.elts:
continue
yield ('shuffleb', variant+' v'+str(dst.elts), src, dst, None)
for dst in fptypes(True, True):
for src in fptypes(True, True):
if src.elts == 1 or dst.elts == 1 or src.scalar != dst.scalar or src.scalable or dst.scalable:
continue
if variant in ['identity', 'reverse'] and src.elts * 2 < dst.elts:
continue
if variant in ['zip1', 'zip2', 'uzp1', 'uzp2', 'trn1', 'trn2'] and src.elts < dst.elts:
continue
if variant in ['splice2'] and src.elts != dst.elts:
continue
yield ('shuffleb', variant+' v'+str(dst.elts), src, dst, None)
# 2src:
# TODO: select?
# TODO: subvector_insert
# TODO: subvector_extract
# TODO: Others? random,
for instr in ['insertelement', 'extractelement']:
for ty in inttypes():
if ty.elts == 1:
continue
for variant in ['vecop0', 'vecop1', 'vecopvar']:
yield (instr, variant, ty, ty, None)
for ty in fptypes():
if ty.elts == 1:
continue
for variant in ['vecop0', 'vecop1', 'vecopvar']:
yield (instr, variant, ty, ty, None)
pool = multiprocessing.Pool(16)
data = pool.starmap(do, enumvec())
with open(getFileName('vec'), "w") as f:
json.dump(data, f, indent=1)