-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
1502 lines (1300 loc) · 45.5 KB
/
main.js
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
let argIndexing = 1;
let perPageMin = 10;
let perPageMax = 50;
/*
intrinsic entry:
{
raw: whatever original form of the object,
cpu: ["CPU"],
id: idCounter++,
ref: "unique string within this CPU",
ret: {type:"return type",name:"return name"},
args: [... {type:"type",name:"name"}],
name: "intrinsic_function_name",
desc: "description",
header: "header_name.h",
implDesc: "operation section",
implInstr: "if immediate is 2: vadd a,b,b<br>else:<br> vmul a,b,imm",
implInstrSearch: "vadd a,b,b\nvmul a,b,imm", // implInstr for searching; will be lowercased automatically
implTimes: {...someArch: {l:"latency",t:"reciprocal throughput"}},
short: "var0", // defaults to "base"
variations: [...{
short: "var",
args, name, ret, // same structure as outside
desc, implInstr, implInstrSearch, implDesc, implTimes, // optional, same structure as outside
}],
toVar: {...}, // a reference to an entry in variations to go to on click; if present, self is excluded from variationsIncl (for entries is just a "wrapper" around variations)
archs: [..."arch|paths"],
categories: [..."category|paths"],
}
*/
let cpuLoaderX86_64 = {msg: 'x86-64', load: loadIntel};
let cpuLoaderARM = {msg: 'ARM', load: loadArm};
let cpuLoaderRISCV = {msg: 'RISC-V', load: loadRVV};
let knownCPUs = [
['x86-64', cpuLoaderX86_64],
['Arm MVE', cpuLoaderARM],
['armv7', cpuLoaderARM],
['aarch32', cpuLoaderARM],
['aarch64', cpuLoaderARM],
['risc-v', cpuLoaderRISCV],
];
let searchFieldEl = document.getElementById("search-field");
let cpuListEl = document.getElementById("cpu-list");
let archListEl = document.getElementById("arch-list");
let categoryListEl = document.getElementById("category-list");
let resultListEl = document.getElementById("result-list");
let descPlaceEl = document.getElementById("desc-place");
let resultCountEl = document.getElementById("result-count");
let pages1El = document.getElementById("pages-1");
let pages2El = document.getElementById("pages-2");
let pages3El = document.getElementById("pages-3");
let centerInfoEl = document.getElementById("center-info");
let idCounter = 1;
let entries_all = [];
let entries_ccpu = undefined;
let curr_archObj, curr_categoryObj, curr_cpu, curr_entry;
let query_archs = [];
let query_categories = [];
let query_found = [];
let query_selVar = undefined;
let query_currPage = 0;
let perPage = 37;
let extra_test = false;
async function loadFile(path) {
let f = await fetch(path);
let b = await f.arrayBuffer();
return new TextDecoder().decode(b);
}
function overloadedName(name) {
return `Overloaded name: <span class="mono h-name">${mkcopy(name,name)}</span>`
}
let excludeSVML = true; // remove SVML entries, which are provided by an Intel library and not the CPU
async function loadIntel() {
let src, perfSrc;
try {
src = await loadFile("data/intel_intrinsics-1.xml");
perfSrc = await loadFile("data/intel_perf2-1.js");
} catch(e) {
return null;
}
let perf = JSON.parse(perfSrc.substring(perfSrc.indexOf('{')).replace(/,\s*}/g,'}').replace(/,\s*]/g,']').replace(/\{l:"/g, '{"l":"').replace(/",t:"/g, '","t":"'));
let type = (c) => {
let name = c.getAttribute("varname");
let type = c.getAttribute("type")
.replace("unsigned ", "u")
.replace(/__int32\b/g, "int32_t")
.replace(/__int64\b/g, "int64_t")
.replace(/long long\b/g, "int64_t")
.replace(/char\b/g, "int8_t")
.replace(/short\b/g, "int16_t")
.replace(/int\b/g, "int32_t")
;
if (type==="unsigned") type = "uint32_t";
let info = '';
let mw = c.getAttribute("memwidth");
if (mw) info+= "Used memory bytes: " + mw/8;
let iw = c.getAttribute("immwidth");
if (iw) info+= (info?"; ":"")+"Used bits: " + iw;
return {
name: name,
type: type,
info: info,
};
};
let archPre = {
MMX: "SSE",
AVX: "AVX+AVX2",
AVX2: "AVX+AVX2",
PCLMULQDQ: "SSE|SSE+",
AES: "SSE|SSE+",
SHA: "SSE|SSE+",
FMA: "AVX2+",
AVX_VNNI: "AVX2+",
FP16C: "AVX2+",
VPCLMULQDQ: "AVX512",
VAES: "AVX512",
GFNI: "AVX512",
KNCNI: "other",
BMI1: "bitmanip",
BMI2: "bitmanip",
POPCNT: "bitmanip",
LZCNT: "bitmanip",
ADX: "other",
CET_SS: "other",
CLDEMOTE: "other",
CLFLUSHOPT: "other",
CLWB: "other",
CRC32: "other",
ENQCMD: "other",
FSGSBASE: "other",
FXSR: "other",
HRESET: "other",
INVPCID: "other",
KEYLOCKER: "SSE|SSE+",
KEYLOCKER_WIDE: "SSE|SSE+",
MONITOR: "other",
MOVBE: "other",
MOVDIR64B: "other",
MOVDIRI: "other",
MPX: "other",
PCONFIG: "other",
PREFETCHWT1: "other",
RDPID: "other",
RDRAND: "other",
RDSEED: "other",
RDTSCP: "other",
RTM: "other",
SERIALIZE: "other",
TSC: "other",
TSXLDTRK: "other",
UINTR: "other",
WAITPKG: "other",
WBNOINVD: "other",
XSAVE: "other",
XSAVEC: "other",
XSAVEOPT: "other",
XSS: "other",
};
let xml = new DOMParser().parseFromString(src, "text/xml");
let res0 = [...xml.children[0].children].map(e=>{
let ch = [...e.children];
let assert = cond => {
if (!cond) throw new Error("bad element: "+e.outerHTML);
}
let filter = (n) => ch.filter(c => c.tagName==n);
let take = (n) => {
let r = filter(n);
assert(r.length==1);
return r[0];
}
let takeOpt = (n, f) => {
let r = filter(n);
assert(r.length<=1);
if (r.length==1) return f(r[0]);
return undefined;
}
let instrs = filter("instruction");
let implInstrList = instrs.map(c => {
let res = c.getAttribute("name").toLowerCase();
if (c.hasAttribute("form")) res+= " "+c.getAttribute("form");
return esc(res);
});
if (e.getAttribute("sequence")==="TRUE") {
if (implInstrList.length==0) implInstrList = ["(sequence)"];
else implInstrList = implInstrList.map(c => c+" (sequence)");
}
let implTimes = instrs.map(c=>perf[c.getAttribute("xed")]).filter(c=>c);
// if (implTimes.length>1) console.log(instrs.map(c=>c.getAttribute("xed"))); // TODO do something about this
implTimes = implTimes.length? implTimes[0] : undefined;
let archs = filter("CPUID").map(c=>c.textContent).map(c=>{
if (e.getAttribute("tech")==='SVML') return "SVML|"+c;
let pre = archPre[c];
if (pre) return pre+"|"+c;
if (c.startsWith("AVX512")) return "AVX512|"+c;
if (c.startsWith("AMX")) return "other|AMX|"+c;
if (c.startsWith("SSE") || c.startsWith("SSSE")) return "SSE|"+c;
return c;
});
if (archs.length==0) archs = ['other|all'];
if (archs.length > 1 && archs.every(c=>c.includes('512'))) archs = archs.filter(c=>c!='AVX512|AVX512F'); // remove reduntant AVX512F arch requirements for things that imply that otherwise
let implDesc = takeOpt("operation", c=>c.textContent);
if(implDesc) while(" \n\t".includes(implDesc[implDesc.length-1])) implDesc = implDesc.substring(0, implDesc.length-1);
let parameters = filter("parameter").map(type);
if (parameters.length==1 && parameters[0].type=='void') parameters = [];
return {
raw: e,
cpu: ["x86-64"],
id: idCounter++,
ret: type(take("return")),
args: parameters,
name: e.getAttribute("name"),
desc: take("description").textContent,
header: takeOpt("header", c=>c.textContent),
implDesc: implDesc,
implInstr: implInstrList.join("<br>"),
implInstrSearch: implInstrList.join("\n"),
implTimes: implTimes,
archs: archs,
categories: filter("category").map(c=>c.textContent),
};
});
if (excludeSVML) res0 = res0.filter(c=>!c.archs.some(c=>c.includes('SVML')));
let res1 = [];
{
let mapB = new Map();
let mapX = new Map();
let add = (map, key, val, ...pre) => { // returns whether this is a new entry
let l = map.get(key);
if (!l) {
map.set(key, l = []);
l.push(...pre, val);
return true;
}
l.push(val);
return false;
}
res0.forEach(n => {
let key1 = n.name.replace(/^(_mm\d*)_mask[z23]?_/, "$1_");
if (!n.archs.length || !(n.archs[0].includes("AVX512") || n.archs[0].includes("KNCNI"))) {
add(mapX, key1, n);
n.short = "base";
res1.push(n);
return;
}
let key = n.archs[0]+';'+key1;
if (add(mapB, key, n, res1.length)) res1.push("??");
});
mapB.forEach((v,k) => {
let pos = v[0];
if (v.length==2) {
res1[pos] = v[1];
} else {
let v1 = v.slice(1);
v1.sort((a,b) => a.name.length-b.name.length);
if (v1.length>1 && v1[0].name.length==v1[1].name.length) throw new Error("equal first lengths");
v1.map((c,i) => {
let f = c.name.match(/_(mask[z23]?)_/);
c.short = f? f[1] : "base";
if (c.short=="base" && i!=0) throw new Error("base not first");
});
let v2 = [...(mapX.get(k.split(';')[1]) || []), ...v1];
let opts = v2.map((c) => c.name.match(/_mask([z23]?)_/));
let optsF = opts.filter(c=>c);
let dec = optsF.map(c=>c[1]).join('');
let exName = optsF[0].input.replace(/_mask([z23]?)_/, opts.includes(null)? '[_mask]_' : `_mask[${dec}]_`);
let exArch = v1[0];
res1[pos] = {
id: idCounter++,
name: exName,
ret: v2[0].ret,
args: v2[0].args,
archs: exArch.archs, cpu: exArch.cpu, categories: exArch.categories,
variations: v2,
toVar: exArch,
};
}
});
}
res1.sort((a,b) => [a,b].map(c => {
let a0 = c.archs[0];
let a0i = (e) => a0.includes(e);
return (c.name.startsWith('_mm')?'0':'1') + (a0i('MMX')||a0i('AES')||a0i('KEYLOCKER')||a0i('SHA')? '~' : a0i('SSE')?'1':'0') + a0 + '__' + c.name.replace(/\[z]|\[?_maskz?]?/g, '') + (c.name.includes('[')?'1':'0');
}).reduce((a,b)=>(a>b)-(a<b)));
return res1;
}
async function loadArm() {
let intrinsics, operations;
try {
intrinsics = await loadFile("data/arm_intrinsics-1.json");
operations = await loadFile("data/arm_operations-1.json");
} catch (e) {
return null;
}
intrinsics = JSON.parse(intrinsics);
operations = JSON.parse(operations);
let operationMap = {};
operations.forEach(c => {
operationMap[c.item.id] = c.item.content;
});
let categoryMap = {
'Logical|NAND': 'Logical|NAND',
'Logical|NOR': 'Logical|NOR',
'Logical|Bitwise NOT': 'Logical|NOT',
'Logical|Logical NOT': 'Logical|NOT',
'Logical|Exclusive OR': 'Logical|XOR',
'Logical|Exclusive OR and rotate': 'Logical|XOR+rotate',
'Logical|Rotate and exclusive OR': 'Logical|XOR+rotate',
'Logical|Bit clear and exclusive OR': 'Logical|ANDN+XOR',
'Logical|AND-NOT': 'Logical|ANDN',
'Logical|OR-NOT': 'Logical|ORN',
'Logical|Saturating Negate': 'Arithmetic|Negate|Saturating negation',
'Logical|Negate': 'Arithmetic|Negate|Negation',
'Vector manipulation|Set all lanes to the same value': 'Vector manipulation|Broadcast',
'Move|Vector move': 'Vector manipulation|Broadcast',
'Table lookups|Extended table lookup': 'Table lookup|Extended table lookup',
'Table lookups|Table lookup': 'Table lookup|Table lookup',
'Bit manipulation|Bitwise clear': 'Logical|ANDN',
'Compare|Bitwise not equal to zero': 'Compare|Bitwise Test',
'Compare|Bitwise equal': 'Compare|==',
'Compare|Equal to': 'Compare|==',
'Compare|Bitwise equal to zero': 'Compare|==',
'Compare|Not equal to': 'Compare|!=',
};
let optMap = (c, f) => c===undefined? c : f(c);
let res0 = intrinsics.map(c=>{
let implInstr = optMap(c.instructions, c=>c.map(c => {
return esc(c.preamble+"\n "+c.list.map(c => c.base_instruction.toLowerCase()+" "+c.operands).join("\n "));
}).join("<br>"));
let implInstrSearch = optMap(c.instructions, c=>c.map(c => {
return c.list.map(c => c.base_instruction.toLowerCase()+" "+c.operands).join("\n");
}).join("\n"));
let args = c.arguments.map(c=>{
let i = Math.max(c.lastIndexOf(' '), c.lastIndexOf('*'));
return ({type: c.substring(0, i+1), name: c.substring(i+1)});
});
if (args.length==1 && args[0].type=='void') args = [];
if (c.Arguments_Preparation) {
let argMap = Object.fromEntries(args.map(c=>[c.name, c]));
Object.entries(c.Arguments_Preparation).forEach(([k,v]) => {
if (!argMap[k]) return;
if (v.hasOwnProperty("minimum") && v.hasOwnProperty("maximum")) argMap[k].info = "range: ["+v.minimum+";"+v.maximum+"]";
});
}
let category = c.instruction_group
.replace(/^Vector arithmetic\|/, "Arithmetic\|")
.replace(/^Scalar arithmetic\|/, "With scalar\|")
.replace(/^Arithmetic\|Across vector arithmetic\|/, "Arithmetic\|Fold\|")
.replace(/^Arithmetic\|Pairwise arithmetic\|/, "Arithmetic\|Pairwise\|")
.replace(/^Shift\|/, "Logical|Shift|")
.replace(/^(Compare multiple|Fault suppression|Predication|Prefetch|Vector length|Vector tuple manipulation)\|/, c => "SVE|"+c)
;
if (category.startsWith("Compare|")) {
category = category
.replace(/Compare\|Absolute /, "Compare|Absolute|")
.replace(/greater than or equal to( zero)?/i, c=>">=")
.replace(/less than or equal to( zero)?/i, c=>"<=")
.replace(/less than( zero)?/i, c=>"<")
.replace(/greater than( zero)?/i, c=>">")
;
}
if (categoryMap[category]) category = categoryMap[category];
if (c.name.startsWith('vmaxnmq_') || c.name.startsWith('vmaxnm_')) category = "Arithmetic|Maximum";
let categories = [category];
let nativeOpNEON = (c.Operation || "").startsWith("Neon");
let nativeOperation = c.Operation? operationMap[c.Operation].replace(/^<h4>Operation<\/h4>/, "<br>").replace(/<h4>/g,'<span class="arm-header">').replace(/<\/h4>/g, '</span>') : "";
return {
raw: c,
cpu: c.Architectures.map(c => c=="v7"? "armv7" : c=="A32"? "aarch32" : c=="A64"? "aarch64" : c=="MVE"? "Arm MVE" : "arm??"),
id: idCounter++,
ret: {type: c.return_type.value},
args: args,
name: c.name.replace(/\[|]/g,""),
desc: (c.name.includes("[")? overloadedName(c.name.replace(/\[[^\]]+]/g,"")) + "<br>" : "") + c.description + (nativeOpNEON? "" : "<br>"+nativeOperation),
header: undefined,
implDesc: nativeOpNEON? nativeOperation : undefined,
implInstr: implInstr,
implInstrSearch: implInstrSearch,
archs: [c.SIMD_ISA],
categories: categories,
};
});
let res1 = [];
{
let map = new Map();
res0.forEach(n => {
if (!n.archs.length || !n.archs[0].includes("sve")) { res1.push(n); return; }
let key = n.archs[0] + ';' + n.name.replace(/_[mxz]$/, "");
let l = map.get(key);
if (!l) {
map.set(key, l = []);
l.push(res1.length);
res1.push("??");
}
l.push(n);
});
map.forEach((v,k) => {
let pos = v[0];
if (v.length==2) {
res1[pos] = v[1];
} else {
let v1 = v.slice(1);
v1.sort((a,b) => {
let d = a.name.length-b.name.length;
if (d) return d;
return a<b;
});
res1[pos] = v1[0];
let v2 = v1[0].variations = v1.slice(1);
v1.map((c,i) => {
let f = c.name.match(/(_[mxz])$/);
c.short = f? f[1] : "base";
if (c.short=="base" && i!=0) throw new Error("base not first");
});
}
});
}
return res1;
}
let rvv_helper = undefined;
async function loadRVV() {
let specFilePath = "data/v-spec.html";
let baseFile, rvvOps;
try {
baseFile = await loadFile("data/rvv_base-5.json");
rvvOps = new Function(await loadFile("extra/rvv_ops.js"))();
} catch (e) {
console.error(e);
return null;
}
rvv_helper = (name, ...args) => {
let prev_entry = curr_entry;
descPlaceEl.innerHTML = `<a class="rvv-helper-back">back</a><pre>${rvvOps.helper(name, ...args)}</pre>`;
descPlaceEl.getElementsByClassName('rvv-helper-back')[0].onclick = () => displayEnt(...prev_entry, false);
};
let res = JSON.parse(baseFile);
// process entries
res.forEach(ins => {
let c = ins;
let fxarg = arg => {
if (arg.name == 'vm') arg.name = 'mask';
return arg;
}
c.args.forEach(fxarg);
c.id = idCounter++;
c.implInstr = c.implInstrRaw? c.implInstrRaw.replace(/\n/g, '<br>') : undefined;
// process variations
if (ins.policies) {
ins.variations = ins.policies.map(s => {
let obj = {
name: ins.name + s.s,
short: s.s,
ret: ins.ret,
args: s.a.map(a => {
if (typeof a === 'number') return ins.args[a];
if (typeof a === 'object') return fxarg(a);
return {name: a.startsWith('vbool')? 'mask' : 'vd', type: a};
}),
};
obj.implDesc = () => rvvOps.oper(c, obj)?.oper;
obj.implInstr = () => rvvOps.oper(c, obj)?.instrHTML;
if (extra_test) rvvOps.oper(c, obj); // make sure oper generation works for all variations
return obj;
});
}
[ins, ...(ins.variations || [])].forEach(v => {
v.args.forEach(a => {
if (a.info==='__RISCV_FRM' || a.info=='__RISCV_VXRM') a.info = `<a onclick="rvv_helper('${a.info}')">${a.info}</a>`
});
});
let newOp = rvvOps.oper(c);
if (!newOp) throw new Error("No rvvOps for "+c.name);
c.desc = newOp.desc || '';
c.specRef = newOp.specRef;
c.implDesc = newOp.oper;
if (newOp.instrHTML !== undefined) {
c.implInstrSearch = newOp.instrSearch;
c.implInstr = () => rvvOps.oper(c).instrHTML;
}
c.categories = newOp.categories;
if (c.overloaded) c.desc = `${overloadedName(c.overloaded)}<br>${c.desc}`;
if (c.specRef) c.desc = `<a target="_blank" href="${specFilePath}#${newOp.specRef}">Specification</a><br>${c.desc}`;
});
rvvOps.initialized();
function addSimpleOp(ret, name, args, desc, oper) {
res.push({
id: idCounter++,
ret: {type: ret}, args, name,
desc, implDesc: oper,
archs: ['rvv'], categories: ["Initialize|General"],
});
}
addSimpleOp("unsigned long", "__riscv_vlenb", [], "Get VLEN in bytes", "return VLEN/8;");
res.forEach(c => {
c.cpu = ['risc-v'];
});
return res;
}
function unique(l) {
return [...new Set(l)];
}
function group(list, name, order) {
let leaf = list.filter(c=>c.length==1).map(c=>c[0]);
let chel = list.filter(c=>c.length>1);
let uniq = unique(chel.map(c=>c[0]));
let cmp = (a,b) => {
let sa = order[name+'|'+a]; if (sa===undefined) sa = 99;
let sb = order[name+'|'+b]; if (sb===undefined) sb = 99;
if (sa!=sb) return sa-sb;
return a.localeCompare(b);
};
leaf.sort(cmp);
uniq.sort(cmp);
return {
ch: uniq.map(c=>group(chel.filter(e=>e[0]==c).map(e=>e.slice(1)), c, order)),
leaf: leaf,
name: name,
};
}
function mkch(n, ch, {cl, id, attrs, onclick, href, innerHTML}={}) {
let r = document.createElement(n);
if (ch) r.append(...ch);
if (id) r.id = id;
if (onclick) r.onclick = e => { onclick(r); }
if (href) r.href = href;
if (attrs) Object.entries(attrs).map(([k,v]) => r.setAttribute(k,v));
if (cl) cl instanceof Array? r.classList.add(...cl) : r.classList.add(cl);
if (innerHTML) r.innerHTML = innerHTML
return r;
};
const mk = (n, named={}) => mkch(n, undefined, named);
function docopy(text) {
navigator.clipboard.writeText(text);
}
function mkcopy(content, text) {
let hoverMessage = 'Click to copy';
if (typeof content === 'string') return `<span class="click-copy hover-base" onclick="docopy('${text}')"><span class="hover-text">${hoverMessage}</span>${content}</span>`;
return mkch('span', [mkch('span', [hoverMessage], {cl:'hover-text'}), content], {cl:['click-copy', 'hover-base'], onclick: ()=>docopy(text)});
}
function makeCheckbox(display, key, updated, group) {
let check = mk('input', {attrs:{type: "checkbox"}, onclick: c => {
if (group) {
let on = c.checked;
[...group.getElementsByTagName('input')].forEach(e => {
e.checked = on;
});
}
updated();
}});
check.checked = true;
let count = mkch('span', ['?']);
let label = mkch('label', [check, display+' (', count, ')'], {cl: ['flex-grow', 'cht-off']});
let row = mkch('div', [
mkch('span', [group? (group.hidden? ">" : "∨") : ""], {cl:['gr',group?'gr-yes':'gr-no'], onclick: t => {
group.hidden^= 1;
t.textContent = group.hidden? ">" : "∨";
}}),
label,
], {cl: 'flex-horiz'});
return {check: check, obj: row, key: key, setCount: (n) => {
if (n) label.classList.remove('cht-off');
else label.classList.add('cht-off');
count.textContent = n;
}};
}
function jp(a, b) {
return a? a+"|"+b : b;
}
function makeTree(tree, ob, update) {
let res;
function updateFn(link=true) {
let rec = (c) => { // 1:off 2:on 3:indeterminate
let chRes = c.ch.map(c => rec(c));
let status = [
...c.leaf.map(c=>c.check.checked?2:1),
...chRes.map(c=>c[0]),
].reduce((a,b)=>a|b, 0);
let cc = c.check;
if (status==3) cc.indeterminate = true;
else {
cc.indeterminate = false;
cc.checked = status==2;
}
return [status, [...chRes.flatMap(c=>c[1]), ...c.leaf.filter(c=>c.check.checked).map(c=>c.key)]];
}
update(rec(res)[1].map(c=>c.substring(4)), link);
}
function step(tree, prefix) {
let key = jp(prefix, tree.name);
let chRes = tree.ch.map(c=>step(c, key));
let leafRes = tree.leaf.map(c => makeCheckbox(c, jp(key,c), updateFn, undefined));
let contents = mkch('div', [...chRes, ...leafRes].map(c=>c.obj));
let indent = mkch('div', [contents], {cl:'indent'});
if (!ob.has(tree.name)) indent.hidden = true;
let check = makeCheckbox(tree.name, key, updateFn, indent);
return {check: check.check, obj: mkch('div', [check.obj, indent]), ch:chRes, leaf:leafRes, setCount: check.setCount, key:key};
}
res = step(tree, '');
res.updateFn = updateFn;
return res;
}
async function newCPU() {
let cpu = cpuListEl.selectedOptions[0].value;
entries_ccpu = undefined;
if (!await setCPU(cpu)) return false;
entries_ccpu = entries_all.filter(c=>c.cpu.includes(cpu));
let archs = unique(entries_ccpu.map(c=>c.archs).flat());
let orderArch = {
'all|SSE': 0,
'all|AVX+AVX2': 1,
'all|AVX2+': 2,
'all|AVX512': 3,
'SSE|MMX':0,
'SSE|SSE':1,
'SSE|SSE2':2,
'SSE|SSE3':3,
'SSE|SSSE3':4,
'AVX512|AVX512F': 0,
'AVX512|AVX512CD': 1,
'AVX512|AVX512ER': 2,
'AVX512|AVX512PF': 3,
'AVX512|AVX512VL': 4,
'AVX512|AVX512DQ': 5,
'AVX512|AVX512BW': 6,
'AVX512|AVX512IFMA52': 7,
'AVX512|AVX512_VBMI': 8,
'AVX512|AVX512_4VNNIW': 9,
'AVX512|AVX512_4FMAPS': 10,
'AVX512|AVX512VPOPCNTDQ': 11,
'AVX512|AVX512_VNNI': 12,
'AVX512|AVX512_BF16': 13,
'AVX512|AVX512_VBMI2': 14,
'AVX512|AVX512_BITALG': 15,
'AVX512|AVX512_VP2INTERSECT': 16,
};
let orderCategory = {
// x86-64
'other|all':0,
'other|AMX':1,
'other|KNCNI':2,
// ARM
'Logical|AND': 0,
'Logical|OR': 1,
'Logical|XOR': 2,
'Logical|NOT': 3,
'Logical|ANDN': 4,
'Logical|ORN': 5,
'all|Arithmetic':0,
'all|Logical':1,
'all|Vector manipulation':2,
// rvv
'Arithmetic|Add':0,
'Arithmetic|Subtract':1,
'Arithmetic|Multiply':2,
'all|Integer':0,
'all|Float':1,
'all|Fold':2,
'all|Mask':3,
'all|Bitwise':4,
'all|Memory':5,
'all|Permutation':6,
'all|Initialize':7,
'all|Conversion':8,
'Integer|Add': 0,
'Integer|Subtract': 1,
'Integer|Multiply': 2,
'Integer|Min': 3,
'Integer|Max': 4,
'Integer|Negate': 5,
'Integer|Compare': 6,
'Integer|Carry / borrow': 7,
'Integer|Multiply-add': 8,
'Integer|Divide': 9,
'Multiply|Same-width': 0,
'Float|Add': 0,
'Float|Subtract': 1,
'Float|Multiply': 2,
'Float|Divide': 3,
'Float|Min': 4,
'Float|Max': 5,
'Float|Negate': 6,
'Float|Absolute': 7,
'Float|Compare': 8,
'Compare|==': 0,
'Fold|Sum': 0,
'Fold|Sequential sum': 1,
'Fold|Tree sum': 2,
'Fold|Widening float sum': 3,
'Fold|Widening integer sum': 4,
'Mask|Logical': 0,
'Mask|Find first set': 1,
'Mask|Population count': 2,
'Mask|Set before first': 3,
'Mask|Set including first': 4,
'Mask|Set only first': 5,
'Permutation|Shuffle': 0,
'Permutation|Slide': 1,
'Memory|Load': 0,
'Memory|Store': 1,
'Memory|Indexed': 2,
'Memory|Fault-only-first load': 3,
'Conversion|Integer widen': 0,
'Conversion|Integer narrow': 1,
'Conversion|Float widen': 2,
'Conversion|Float narrow': 3,
'Conversion|Integer to float': 4,
'Conversion|Float to integer': 5,
'Integer to float|Same-width result': 0,
'Float to integer|Same-width result': 0,
'Bitwise|Shift left': 0,
'Bitwise|AND': 1,
'Bitwise|OR': 2,
'Bitwise|XOR': 3,
'Bitwise|NOT': 4,
'Fixed-point|Saturating add': 0,
'Fixed-point|Saturating subtract': 1,
};
let openByDefault = new Set([
'all',
'SSE', 'AVX+AVX2',
]);
archListEl.textContent = '';
let archGroups = group(archs.map(c => c.split("|")), 'all', orderArch);
query_archs = [...archs];
curr_archObj = makeTree(archGroups, openByDefault, (a, link) => {
query_archs = a;
updateSearch(link);
});
if (archs.length > 1) archListEl.append(curr_archObj.obj);
let categories = unique(entries_ccpu.map(c=>c.categories).flat());
categoryListEl.textContent = '';
let categoryGroups = group(categories.map(c => c.split("|")), 'all', orderCategory);
query_categories = categories;
curr_categoryObj = makeTree(categoryGroups, openByDefault, (c, link) => {
query_categories = c;
updateSearch(link);
});
categoryListEl.append(curr_categoryObj.obj);
updateSearch(false);
return true;
}
function esc(s) {
return new Option(s).innerHTML;
}
function calcPages() {
return Math.max(1, Math.floor((query_found.length+perPage-1)/perPage));
}
function deltaPage(n) {
let p = query_currPage+n;
if (p<0 || p>=calcPages()) return;
toPage(p);
}
const hl = (h, text) => mkch('span', [text], {cl:'h-'+h});
let mkRetLine = (fn) => hl('type',fn.ret.type);
let mkFnLine = (fn, wrapname=(c=>c)) => mkch('span', [wrapname(hl('name',fn.name)), '(', ...fn.args.flatMap(c=>[hl('type', c.type), ' '+c.name, ', ']).slice(0,-1), ')']);
function displayNoEnt(link = true) {
descPlaceEl.innerText = "";
curr_entry = undefined;
if (link) updateLink();
}
function displayEnt(ins, fn, link = true) {
if (fn.toVar) fn = fn.toVar;
curr_entry = [ins, fn];
let a0 = fn.archs || ins.archs;
let a1 = a0;
if (a0.length>1) a1 = a1.filter(c=>!c.endsWith("|KNCNI"));
let a2 = a1.map(c=>esc(c.split(/\|/g).slice(-1)[0])).join(' + ');
if (a0.length != a1.length) a2+= " / KNCNI";
let text = ``;
text+= `<br>Architecture: <span class="mono">${a2}</span>`;
text+= `<br>Categor${ins.categories.length>1?"ies":"y"}: <span class="mono">${ins.categories.map(c=>esc(c.replace(/\|/g,'→'))).join(', ')}</span>`;
text+= `<br><br>Description:<div class="desc">${fn.desc||ins.desc}</div>`;
let implInstr = fn.implInstr;
if (typeof implInstr === 'function') implInstr = implInstr();
let implDesc = fn.implDesc || ins.implDesc;
if (typeof implDesc === 'function') implDesc = implDesc();
let implTimes = fn.implTimes || ins.implTimes;
if (implInstr) text+= `<br>Instruction:<pre>${implInstr}</pre>`;
if (implDesc) text+= `<br>Operation:<pre class="operation">${implDesc}</pre>`;
if (implTimes) text+= `<br>Performance:<table class="perf-table"></table>`;
descPlaceEl.innerHTML = text;
if (implTimes) descPlaceEl.getElementsByClassName("perf-table")[0].append(mkch('tbody', [
mkch('tr', ['Architecture', 'Latency', 'Throughput (CPI)'].map(c=>mkch('th',[c]))),
...implTimes.map(c => {
let [[k,v]] = Object.entries(c);
return mkch('tr', [k, v.l, v.t].map(e => mkch('td', [e])));
})
]));
let desc;
let copyWrap = (c) => mkcopy(c, fn.name);
if (fn.args.length>7 || fn.args==0) {
desc = [mkRetLine(fn), ' ', mkFnLine(fn, copyWrap)];
} else {
desc = [mkRetLine(fn), ' ', copyWrap(hl('name',fn.name)), '(\n', ...fn.args.map((a,i)=>{
return mkch('span', [' ', hl('type',a.type), ' '+a.name, ','.repeat(i!=fn.args.length-1), a.info? hl('comm',mkch('span', [], {innerHTML: ' // '+a.info})) : '', '\n']);
}), ')'];
}
if (ins.variations && ins.variations.length) {
let mkvar = (fn, short) => mkch('span', short, {cl: ['mono', 'var-link'], onclick: () => displayEnt(ins, fn)});
descPlaceEl.insertAdjacentElement('afterBegin', mkch('span', [
'Variations: ',
...ins.variationsIncl.flatMap((fn, i) => [i?', ':'', mkvar(fn, fn.short || "base")])
]));
descPlaceEl.insertAdjacentElement('afterBegin', mk('br'));
}
descPlaceEl.insertAdjacentElement('afterBegin', mk('br'));
descPlaceEl.insertAdjacentElement('afterBegin', mkch('span', desc, {cl: ['mono', 'code-ws']}));
if (link) updateLink();
}
function toPage(page) {
query_currPage = page;
let pages = calcPages();
let makeBtn = (n) => {
let r = mkch('span', [n+1], {cl: ['page-btn'], onclick: () => toPage(n)});
if (page===n) r.classList.add('page-curr');
return r;
}
pages1El.textContent = '';
pages2El.textContent = '';
pages3El.textContent = '';
function range(s, e) {
return Array(e-s).fill().map((c,i)=>i+s);
}
if (pages < 14) {
pages2El.append(...range(0, pages).map(makeBtn));
} else {
let nL = page<3;
let nR = page>=pages-3;
let n = nL||nR;
pages1El.append(...range(0, n? 5 : 3).map(makeBtn));
if (!n) pages2El.append(...range(page-2, page+3).map(makeBtn));
pages3El.append(...range(pages-(n? 5 : 3), pages).map(makeBtn));
}
resultListEl.textContent = '';
resultListEl.append(...query_found.slice(page*perPage, (page+1)*perPage).map(ins=>{
let cvar = ins;
if (ins.variations && query_selVar) {
cvar = ins.variations.find(c=>c.short==query_selVar) || cvar;
}
let r = mkch('tr', [
mkch('td', [mkRetLine(cvar)]),
mkch('td', [mkFnLine(cvar)]),
// mkch('td', [c.archs.map(c=>c.split(/\|/g).slice(-1)[0]).join("+")]),
]);
r.onclick = () => {
if (curr_entry && curr_entry[0]===ins && curr_entry[1]===cvar) {
displayNoEnt();
} else {
displayEnt(ins, cvar);
}
}