|
| 1 | +import { InstructionInfo, ExtensionInfo } from "./sharedTypes.js"; |
| 2 | +import { extensionDescriptions } from "./hardcodedData.js"; |
1 | 3 | import loadInstructions from "./loadInstructions.js"; |
2 | 4 |
|
3 | | -export default () => { |
4 | | - const instructions = loadInstructions(); |
5 | | - const descriptions = { |
6 | | - I: "Base Integer", |
7 | | - E: "Embedded Base", |
8 | | - M: "Integer Multiply/Divide", |
9 | | - A: "Atomic Instructions", |
10 | | - F: "Single-Precision Floating Point", |
11 | | - D: "Double-Precision Floating Point", |
12 | | - Q: "Quad-Precision Floating Point", |
13 | | - C: "Compressed Instructions", |
14 | | - B: "Bit Manipulation", |
15 | | - H: "Hypervisor", |
16 | | - S: "Supervisor", |
17 | | - V: "Vector", |
18 | | - Sdext: "Supervisor Debug", |
19 | | - Smdbltrp: "Supervisor Multiple Double Trap", |
20 | | - Smrnmi: "Supervisor Recursive NMI", |
21 | | - Svinval: "Supervisor Virtual Invalidation", |
22 | | - Zaamo: "Atomics extensions", |
23 | | - Zabha: "Byte/Halfword Atomics", |
24 | | - Zacas: "Compare-and-Swap Atomics", |
25 | | - Zalasr: "Atomic Logical Shift Right", |
26 | | - Zalrsc: "Load-Reserved/Store-Conditional", |
27 | | - Zawrs: "Wait-on-Reservation-Set", |
28 | | - Zba: "Address Generation Bit-Manip", |
29 | | - Zbb: "Basic Bit-Manip", |
30 | | - Zbc: "Carry-Less Multiply", |
31 | | - Zbkb: "Bit-Manip Crypto B", |
32 | | - Zbkx: "Bit-Manip Crypto X", |
33 | | - Zbs: "Single-Bit Manipulation", |
34 | | - Zcb: "Compressed Bit-Manip", |
35 | | - Zcd: "Compressed Double", |
36 | | - Zcf: "Compressed Floating Point", |
37 | | - Zcmop: "Compressed Micro-Operations", |
38 | | - Zcmp: "Compressed Pair", |
39 | | - Zfa: "Vector Atomic Floating", |
40 | | - Zfbfmin: "Vector BF16 Min", |
41 | | - Zfh: "Half-Precision Floating Point", |
42 | | - Zicbom: "Cache Block Management", |
43 | | - Zicboz: "Zero Cache Block", |
44 | | - Zicfilp: "Fetch Line Prefetch", |
45 | | - Zicfiss: "Instruction Streaming", |
46 | | - Zicond: "Conditional Ops", |
47 | | - Zicsr: "CSR Instructions", |
48 | | - Zifencei: "Instruction-Fetch Fence", |
49 | | - Zimop: "Integer Multiply and Division Ops", |
50 | | - Zkn: "Scalar Cryptography", |
51 | | - Zknd: "NIST Suite: AES Decryption", |
52 | | - Zkne: "NIST Suite: AES Encryption", |
53 | | - Zknh: "NIST Suite: Hash", |
54 | | - Zks: "Scalar Crypto Suite", |
55 | | - Zvbb: "Vector Bitwise", |
56 | | - Zvbc: "Vector Carry-less Multiply", |
57 | | - Zvfbfmin: "Vector BF16 Min", |
58 | | - Zvfbfwma: "Vector BF16 Fused Multiply-Add", |
59 | | - Zvkg: "Vector Galois Field", |
60 | | - Zvkned: "Vector AES Decryption", |
61 | | - Zvknha: "Vector Hash", |
62 | | - Zvks: "Vector Crypto Suite", |
63 | | - }; |
64 | | - const byExtension = new Map(); |
65 | 5 |
|
| 6 | +export default (): ExtensionInfo[] => { |
| 7 | + const instructions: InstructionInfo[] = loadInstructions(); |
| 8 | + const byExtension = new Map<string, ExtensionInfo>(); |
| 9 | + |
| 10 | + // Group instructions by their extension and create ExtensionInfo objects |
66 | 11 | for (const inst of instructions) { |
67 | 12 | const name = inst.extension || "unknown"; |
68 | 13 | const slug = inst.extensionSlug || "unknown"; |
69 | 14 | if (!byExtension.has(name)) { |
70 | 15 | byExtension.set(name, { |
71 | | - name, |
72 | | - slug, |
73 | | - description: descriptions[name] || null, |
| 16 | + name, slug, |
| 17 | + description: extensionDescriptions[name] || null, |
74 | 18 | instructions: [], |
75 | 19 | }); |
76 | 20 | } |
77 | | - byExtension.get(name).instructions.push(inst); |
| 21 | + byExtension.get(name)!.instructions.push(inst); |
78 | 22 | } |
79 | 23 |
|
| 24 | + // Sort instructions within each extension and count them |
80 | 25 | const list = Array.from(byExtension.values()); |
81 | 26 | for (const entry of list) { |
82 | | - entry.instructions.sort((a, b) => a.name.localeCompare(b.name)); |
| 27 | + entry.instructions.sort((a: InstructionInfo, b: InstructionInfo) => |
| 28 | + a.name.localeCompare(b.name)); |
83 | 29 | entry.count = entry.instructions.length; |
84 | 30 | } |
85 | 31 |
|
| 32 | + // Sort extensions alphabetically by name |
86 | 33 | list.sort((a, b) => a.name.localeCompare(b.name)); |
87 | 34 | return list; |
88 | 35 | }; |
0 commit comments