wuica-cli 0.0.0-stage → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +546 -2
  3. package/bin/wuica-mcp.js +16 -0
  4. package/bin/wuica.js +25 -0
  5. package/dist/data/arch/ADL-P.bin.br +0 -0
  6. package/dist/data/arch/BDW.bin.br +0 -0
  7. package/dist/data/arch/CFL.bin.br +0 -0
  8. package/dist/data/arch/CLX.bin.br +0 -0
  9. package/dist/data/arch/HSW.bin.br +0 -0
  10. package/dist/data/arch/ICL.bin.br +0 -0
  11. package/dist/data/arch/ICX.bin.br +0 -0
  12. package/dist/data/arch/IVB.bin.br +0 -0
  13. package/dist/data/arch/KBL.bin.br +0 -0
  14. package/dist/data/arch/RKL.bin.br +0 -0
  15. package/dist/data/arch/SKL.bin.br +0 -0
  16. package/dist/data/arch/SKX.bin.br +0 -0
  17. package/dist/data/arch/SNB.bin.br +0 -0
  18. package/dist/data/arch/TGL.bin.br +0 -0
  19. package/dist/data/arch/ZEN3.bin.br +0 -0
  20. package/dist/data/uarch.json.br +0 -0
  21. package/dist/manifest.json +160 -0
  22. package/dist/wuica_asm.wasm.br +0 -0
  23. package/dist/wuica_wasm.wasm.br +0 -0
  24. package/index.d.ts +410 -0
  25. package/lib/archs.js +44 -0
  26. package/lib/cli.js +693 -0
  27. package/lib/core.js +36 -0
  28. package/lib/details.js +60 -0
  29. package/lib/examples.js +26 -0
  30. package/lib/files.js +40 -0
  31. package/lib/index.js +577 -0
  32. package/lib/insights.js +100 -0
  33. package/lib/mcp.js +366 -0
  34. package/lib/objfile.js +216 -0
  35. package/lib/thread-worker.js +49 -0
  36. package/lib/threads.js +235 -0
  37. package/lib/wasm.js +246 -0
  38. package/lib/web/accum.js +202 -0
  39. package/lib/web/asm-regions.js +415 -0
  40. package/lib/web/assembler.js +188 -0
  41. package/lib/web/caveats.js +214 -0
  42. package/lib/web/examples.js +99 -0
  43. package/lib/web/loop-find.js +492 -0
  44. package/lib/web/showcase.js +368 -0
  45. package/lib/whatif.js +136 -0
  46. package/licenses/LICENSE-LLVM.txt +279 -0
  47. package/licenses/LICENSE-XED.txt +178 -0
  48. package/package.json +58 -4
@@ -0,0 +1,160 @@
1
+ {
2
+ "uiCA": {
3
+ "repository": "https://github.com/jtl06/uiCA",
4
+ "commit": "640e40e",
5
+ "branch": "improve-r9"
6
+ },
7
+ "tables": {
8
+ "format": "WUICATBL 1",
9
+ "sha256": "d1dce7edf3a6e0af263c94ed8712fb11ee8f4572c8685057201d2309e5e24631"
10
+ },
11
+ "files": {
12
+ "wuica_wasm.wasm": {
13
+ "size": 3111653,
14
+ "sha256": "1a004180a1c1a79a02b039a4737c9c457ceacf507d735c6955046b071f28e818"
15
+ },
16
+ "wuica_asm.wasm": {
17
+ "size": 3802001,
18
+ "sha256": "ee66811d0671cdea73176a3670f82816dcbb3cbb1fed13cd7dc2acbb69cb627d"
19
+ },
20
+ "data/uarch.json": {
21
+ "size": 51318,
22
+ "sha256": "f543714ba2927986671f1de045a6162296ce860c5d34a086cc4c72d6c828e7a1"
23
+ },
24
+ "data/arch/ADL-P.bin": {
25
+ "size": 819776,
26
+ "sha256": "3a6623b7086ada2689d068745929537046655b444641885e09154221b5edac87",
27
+ "source": {
28
+ "file": "data/arch/ADL-P.json",
29
+ "size": 1771348,
30
+ "sha256": "1632dd7f57d26efa6e465c25c72e38523302c906f8db403af6ba1c432b1e1ccb"
31
+ }
32
+ },
33
+ "data/arch/BDW.bin": {
34
+ "size": 197075,
35
+ "sha256": "7c9f3af2afaaebb8ec49f9d02e5e85cd5be606b75d19c498bbc7159a3a0c7d2d",
36
+ "source": {
37
+ "file": "data/arch/BDW.json",
38
+ "size": 526864,
39
+ "sha256": "48e3e00ba260d97abcdae17a330c1e426b09b8e55b35c6d65932cc226237be0e"
40
+ }
41
+ },
42
+ "data/arch/CFL.bin": {
43
+ "size": 199949,
44
+ "sha256": "91616eec3eeaabb032e42e3e87c25945121513036041e200bea5dc109f2d7bb2",
45
+ "source": {
46
+ "file": "data/arch/CFL.json",
47
+ "size": 535543,
48
+ "sha256": "26806383a9a25e1fdd327ad3140c32f2b0a2b919c23d72cbd017e268177bfb7a"
49
+ }
50
+ },
51
+ "data/arch/CLX.bin": {
52
+ "size": 654383,
53
+ "sha256": "5fb768f2d4aab8c876183640b1fc5425f357f958356052172c3be00970a01c5a",
54
+ "source": {
55
+ "file": "data/arch/CLX.json",
56
+ "size": 1397578,
57
+ "sha256": "368c51d6fb60c91480346dd592239f09b5dce8e523034e27da439f19f97673d7"
58
+ }
59
+ },
60
+ "data/arch/HSW.bin": {
61
+ "size": 201318,
62
+ "sha256": "7ee63a4845a64c96948ee343148ce9db770d5c3347edb1414a35a6a305bd3cd7",
63
+ "source": {
64
+ "file": "data/arch/HSW.json",
65
+ "size": 537696,
66
+ "sha256": "52ca060485b45c73e7c4229bb77f3637cacb5544349789cf0913fd329d6f18c9"
67
+ }
68
+ },
69
+ "data/arch/ICL.bin": {
70
+ "size": 691859,
71
+ "sha256": "92d27cfb556b46617a1cfe433d5956f455192459888447e6276bdfdb9255eec2",
72
+ "source": {
73
+ "file": "data/arch/ICL.json",
74
+ "size": 1465390,
75
+ "sha256": "3315a5d3463e3b2453943e9984d28c8135b8b20168c283a4d4d4c610a99e94de"
76
+ }
77
+ },
78
+ "data/arch/ICX.bin": {
79
+ "size": 698165,
80
+ "sha256": "b01057f584a837604ad9c08c4eeae45e09161dce826234d5f010e807a0a18b21",
81
+ "source": {
82
+ "file": "data/arch/ICX.json",
83
+ "size": 1495406,
84
+ "sha256": "dd45538e22584305d5186d78673b3d4f8bc83fd2d0c0e600ec98540a6d0f2eff"
85
+ }
86
+ },
87
+ "data/arch/IVB.bin": {
88
+ "size": 163769,
89
+ "sha256": "484f4e7d1552a44084a7d1298eec1d94c4229b24c385a474a3b56a915933e4b9",
90
+ "source": {
91
+ "file": "data/arch/IVB.json",
92
+ "size": 464357,
93
+ "sha256": "53c297d60bba360223c44c1403c820555a2c01c2dc680f229c44036f8c89bda8"
94
+ }
95
+ },
96
+ "data/arch/KBL.bin": {
97
+ "size": 201120,
98
+ "sha256": "26ab42345e8de863ae825f278143bf4ba234635d532268cf5e5f18d165528435",
99
+ "source": {
100
+ "file": "data/arch/KBL.json",
101
+ "size": 541457,
102
+ "sha256": "a5381d040f4c38e2c67a740d28e522b6918650044bb4cbd3e92e45c749a2a607"
103
+ }
104
+ },
105
+ "data/arch/RKL.bin": {
106
+ "size": 696724,
107
+ "sha256": "c839f40ac2aaed5c10d6f122edcffe6e1a5eecfcfcd21be8fc75e1f68098dc36",
108
+ "source": {
109
+ "file": "data/arch/RKL.json",
110
+ "size": 1487905,
111
+ "sha256": "8b2fee3a39a5632e845add182f1f1f0a5ab6158b6c2141952accb37b85ecc2a6"
112
+ }
113
+ },
114
+ "data/arch/SKL.bin": {
115
+ "size": 199362,
116
+ "sha256": "690d24c0478ed18e4280491dde5cbbcd5c739664cd87be5f1f22aa3236b95267",
117
+ "source": {
118
+ "file": "data/arch/SKL.json",
119
+ "size": 532918,
120
+ "sha256": "c4c216edb3af2bf19847a9398dbc3c2cc46e5ad1fe609b2dd2db07203d2d191f"
121
+ }
122
+ },
123
+ "data/arch/SKX.bin": {
124
+ "size": 647385,
125
+ "sha256": "50b8496690e3cb8b7bad0f2ecb36ad61c7a110193ce798838902257ea92a1bf6",
126
+ "source": {
127
+ "file": "data/arch/SKX.json",
128
+ "size": 1379117,
129
+ "sha256": "5dea6ecf323367fe217fafe624c92a5e6085ed3112fb3a173ab081353fd11480"
130
+ }
131
+ },
132
+ "data/arch/SNB.bin": {
133
+ "size": 162979,
134
+ "sha256": "a14e6a77ec41fe14db1745acbfb6a4df4d360b58068b391f0df9a6804c247589",
135
+ "source": {
136
+ "file": "data/arch/SNB.json",
137
+ "size": 460620,
138
+ "sha256": "3ba130e0858faa73bd16677e740b9fda75329df87eae339326a74a4a27e16e69"
139
+ }
140
+ },
141
+ "data/arch/TGL.bin": {
142
+ "size": 692074,
143
+ "sha256": "abaeb3cb2f10a3e68c4f1f5374007b574982f09ae5832fcd9f5ed1d3f60ff3cd",
144
+ "source": {
145
+ "file": "data/arch/TGL.json",
146
+ "size": 1461441,
147
+ "sha256": "6f799ff308e1f9e62c0b5118921dcca3253644b7a028e50d0737cc4d731f2780"
148
+ }
149
+ },
150
+ "data/arch/ZEN3.bin": {
151
+ "size": 198979,
152
+ "sha256": "525e66430a3ddc9f0c88d914f32083fbdc0c32f17233dd972548286b4d43b7c7",
153
+ "source": {
154
+ "file": "data/arch/ZEN3.json",
155
+ "size": 527963,
156
+ "sha256": "72097d0e154b17ef71c12547946c2750f388cdae479b9af99ed5633959c9059a"
157
+ }
158
+ }
159
+ }
160
+ }
Binary file
Binary file
package/index.d.ts ADDED
@@ -0,0 +1,410 @@
1
+ // Type declarations for the wuica package. The shapes are the API contract of README.md ("API contract").
2
+
3
+ /** Simulation options (as in uiCA); the defaults are shown. */
4
+ export interface AnalysisOptions {
5
+ /** Offset of the block relative to a 64-byte cache line. Default 0. */
6
+ alignmentOffset?: number;
7
+ /** Initial register state. Default "diff". */
8
+ initPolicy?: 'diff' | 'same' | 'stack';
9
+ /** Simulate a front end that is only limited by the issue width. Default false. */
10
+ simpleFrontEnd?: boolean;
11
+ noMicroFusion?: boolean;
12
+ noMacroFusion?: boolean;
13
+ /** Simulate at least this many iterations. Default 10. */
14
+ minIterations?: number;
15
+ /** Simulate at least this many cycles. Default 500. */
16
+ minCycles?: number;
17
+ /** Include uiCA's cycle-by-cycle events (`trace`; large). Default false. */
18
+ includeTrace?: boolean;
19
+ /** Include `details` (per instruction allowed ports, latencies, front-end facts; the port set behind the Ports limit;
20
+ * issue slots per cause: docs/WASM-API.md). Default false. */
21
+ details?: boolean;
22
+ }
23
+
24
+ /** "auto" (the default): detected from the text (%registers, $immediates: AT&T; else Intel noprefix). */
25
+ export type Syntax = 'auto' | 'intel' | 'att';
26
+
27
+ /** What of `source` is analyzed: "auto" (default: the innermost loop of a whole function, or its body if it has no
28
+ * loop; else the text as it is), "whole", or the index of a loop (innermost first, in code order). */
29
+ export type LoopChoice = 'auto' | 'whole' | number | string;
30
+ /** The named loop choices ('auto', 'whole'); a number is a loop's index (0-based), any other string its label. */
31
+ export declare const LOOP_CHOICES: readonly ['auto', 'whole'];
32
+ /** A loop of assembly text (listLoops; the CLI's -loops). */
33
+ export interface LoopListing {
34
+ /** Its index for `loop` (0-based): the deepest loops first, then in code order. */
35
+ index: number;
36
+ label: string;
37
+ /** The function it is in (the last non-local label before it), or null. */
38
+ function: string | null;
39
+ line: number;
40
+ endLine: number;
41
+ instructions: number;
42
+ /** 1 for a loop in no other loop (clang's Depth when its notes say). */
43
+ depth: number;
44
+ /** The loop "auto" analyzes. */
45
+ auto: boolean;
46
+ }
47
+ /** The loops of assembly text, as `loop` and `func` choose among them (no assembling). */
48
+ export function listLoops(source: string, options?: { func?: string | null }): LoopListing[] | { error: string };
49
+ /** A built-in example: the web page's set (the CLI's -examples / -example NAME). */
50
+ export interface Example {
51
+ /** "saxpy", "dot1", ... (findExample and the CLI take it in any case). */
52
+ name: string;
53
+ title: string;
54
+ group: 'basics' | 'classic' | 'showcase';
55
+ /** The CPU the page shows it on first. */
56
+ arch: string;
57
+ instructions: number;
58
+ /** Its machine code. */
59
+ hex: string;
60
+ /** Its assembly (a request's `source` with syntax 'intel' or 'att'); absent for the showcase (machine code only). */
61
+ intel?: string;
62
+ att?: string;
63
+ }
64
+ /** What a file is from its first bytes ('elf', 'macho', 'fat', 'macho32', 'coff', 'pe', 'archive'), or null. */
65
+ export function objectKind(bytes: Uint8Array): { kind: string } | null;
66
+ /** The built-in examples: basics, classic loops, the SHA-256 showcase. */
67
+ export function examples(): readonly Example[];
68
+ /** The example called `name` (case-insensitive), or null. */
69
+ export function findExample(name: string): Example | null;
70
+ /** 'att' or 'intel' from the text's signs, or null. */
71
+ export function detectSyntax(source: string): 'att' | 'intel' | null;
72
+ /** Per instruction details and the port set / issue slots of an analysis with options.details (the MCP summary's). */
73
+ export function detailInsights(result: AnalyzeResult): Partial<Insights>;
74
+
75
+ /** What was analyzed when it is not the whole text as given (AnalyzeResult.loop). */
76
+ export interface LoopInfo {
77
+ /** The loop's index; null for a function's body or the whole text. */
78
+ index: number | null;
79
+ /** The number of loops in the text. */
80
+ count: number;
81
+ /** "loop .L3", "loop 0x10" (objdump), "body" or "whole". */
82
+ name: string;
83
+ /** Its first and last line in the source (null: the whole text). */
84
+ line: number | null;
85
+ endLine: number | null;
86
+ /** The source line of each of its instructions, in order (a picked loop or body): row k of the analysis is line lines[k]. */
87
+ lines?: number[];
88
+ /** The function it is in, its nesting depth and its instruction count (for a loop). */
89
+ function?: string | null;
90
+ depth?: number;
91
+ instructions?: number;
92
+ /** Its address (objdump input). */
93
+ address?: number;
94
+ /** The alignment offset from the addresses (objdump input): used unless options.alignmentOffset is given. */
95
+ alignmentOffset?: number;
96
+ }
97
+
98
+ /** The code: exactly one of `source` (assembly; `asm` is accepted as an alias) and `hex` (machine code). */
99
+ export type CodeRequest =
100
+ | { source: string; asm?: undefined; hex?: undefined; syntax?: Syntax; loop?: LoopChoice; func?: string }
101
+ | { asm: string; source?: undefined; hex?: undefined; syntax?: Syntax; loop?: LoopChoice; func?: string }
102
+ | { hex: string | Uint8Array; source?: undefined; asm?: undefined; syntax?: Syntax; loop?: LoopChoice };
103
+
104
+ /** Body of POST /api/analyze/<arch>. */
105
+ export type AnalyzeRequest = CodeRequest & { options?: AnalysisOptions };
106
+
107
+ /** Body of POST /api/compare. */
108
+ export type CompareRequest = CodeRequest & { archs?: string[]; options?: AnalysisOptions };
109
+
110
+ /** Result codes, like an exit status. */
111
+ export declare const CODES: Readonly<{ OK: 0; REQUEST: 1; ASSEMBLER: 2; ANALYSIS: 3 }>;
112
+ export type ResultCode = 0 | 1 | 2 | 3;
113
+
114
+ /** One line of stderr, as in Compiler Explorer; lines with a source position carry a tag. */
115
+ export interface StderrLine {
116
+ text: string;
117
+ tag?: { line: number; column: number; severity: 'error' | 'warning' | 'note'; text: string };
118
+ }
119
+
120
+ /** A failed call. code 1: bad request; 2: assembler error; 3: the analysis failed for this input. */
121
+ export interface Failure {
122
+ code: 1 | 2 | 3;
123
+ error: string;
124
+ stderr: StderrLine[];
125
+ /** The WebAssembly module trapped on this input; it has been restarted and the next call works. */
126
+ trapped?: boolean;
127
+ }
128
+
129
+ export interface Limit {
130
+ name: string;
131
+ tp: number;
132
+ }
133
+
134
+ export interface Row {
135
+ kind: 'instr' | 'regMerge' | 'stackSync';
136
+ label: string;
137
+ opcode?: string;
138
+ instrStr?: string;
139
+ url?: string | null;
140
+ /** "M" macro-fused with the previous instruction, "J" JCC erratum, "X" not supported, or "". */
141
+ notes: string;
142
+ /** values[i] belongs to columns[i]; averages per iteration. */
143
+ values: number[];
144
+ }
145
+
146
+ /** A successful analysis: the response of docs/WASM-API.md plus code, hex and stderr. */
147
+ export interface AnalyzeResult {
148
+ code: 0;
149
+ arch: string;
150
+ /** Predicted throughput in cycles per iteration. */
151
+ tp: number;
152
+ /** "loop" if the block ends with a branch, else "unroll". */
153
+ mode: 'loop' | 'unroll';
154
+ decodeErrors: number;
155
+ bottlenecks: string[];
156
+ limits: Limit[];
157
+ columns: string[];
158
+ rows: Row[];
159
+ /** uiCA's complete text report. */
160
+ text: string;
161
+ trace: unknown | null;
162
+ /** The loop-carried dependency cycle behind the "Dependencies" limit; only if that limit is not 0 (docs/WASM-API.md). */
163
+ criticalPath?: {
164
+ ratio: number;
165
+ edges: { from: number; to: number; operand: string; latency: number; carried: boolean }[];
166
+ };
167
+ /** With options.details: per row its allowed ports, latencies, front-end facts; the port set and issue slots
168
+ * (docs/WASM-API.md, "Details"). */
169
+ details?: { rows: unknown[]; ports?: unknown; slots?: unknown };
170
+ /** The assembled machine code (lower-case hex), when `source` was given. */
171
+ hex?: string;
172
+ /** What of `source` was analyzed, when not the whole text as given (request.loop). */
173
+ loop?: LoopInfo;
174
+ /** The syntax `source` was read in (detected unless the request said). */
175
+ syntax?: 'intel' | 'att';
176
+ /** Assembler warnings, notes (exits taken as not taken), and the decode warning. */
177
+ stderr: StderrLine[];
178
+ }
179
+
180
+ /** The compact form of an analysis (summarize(); the MCP `analyze` JSON). */
181
+ export interface AnalyzeSummary {
182
+ code: 0;
183
+ arch: string;
184
+ name: string;
185
+ year: number | null;
186
+ prototype: boolean;
187
+ tp: number;
188
+ unit: 'cycles per iteration';
189
+ mode: 'loop' | 'unroll';
190
+ bottlenecks: string[];
191
+ limits: Limit[];
192
+ decodeErrors: number;
193
+ hex?: string;
194
+ loop?: LoopInfo;
195
+ stderr: StderrLine[];
196
+ instructions: Array<{
197
+ instr: string;
198
+ bytes?: string;
199
+ kind?: 'regMerge' | 'stackSync';
200
+ issued?: number;
201
+ executed?: number;
202
+ uopSource?: Record<string, number>;
203
+ ports?: Record<string, number>;
204
+ notes?: string;
205
+ uopsInfo?: string;
206
+ /** With options.details: */
207
+ allowedPorts?: string;
208
+ uops?: number;
209
+ fusedUops?: number;
210
+ msUops?: number;
211
+ latencies?: string[];
212
+ frontEnd?: { length: number; offset: number; crosses?: number[]; lcp?: true; microcoded?: true; complexDecoder?: true; macroFusedWithNext?: true; macroFusedWithPrev?: true };
213
+ }>;
214
+ /** A diagnosis derived from the analysis (the web page's bound view); absent if tp is 0. */
215
+ insights?: Insights;
216
+ }
217
+
218
+ export interface Insights {
219
+ /** Each limit (by name) and execution port (by column name): cycles / tp. 1 = busy every cycle. */
220
+ utilization: Record<string, number>;
221
+ /** The bottleneck(s) uiCA names: the same as the response's `bottlenecks` (limit names, and "Divider", which has no limit of its own). [] when it names none (no
222
+ * single limit explains tp; the web page says "unknown"): then see `largest`. */
223
+ binding: string[];
224
+ /** Only when `binding` is []: the largest limit(s), the nearest bound, which alone does not reach tp. */
225
+ largest?: string[];
226
+ /** The largest limit below the binding (or largest) one; maxSpeedup = tp / next.tp (an upper bound). */
227
+ next?: { limit: string; tp: number; maxSpeedup: number | null };
228
+ /** Cycles per iteration that no single limit explains. */
229
+ unexplained?: number;
230
+ /** The critical loop-carried dependency chain (index: into `instructions`). */
231
+ chain?: { index: number; instr: string; operand: string; latency: number; carried: boolean }[];
232
+ /** The instructions with the largest share of the binding resource, or of the largest limit (top 5). */
233
+ hot?: { resource: string; ports?: string[]; instructions: { index: number; instr: string; share: number }[] };
234
+ /** Known blind spots of the model the block meets (absent if none): rmw-index, paths, exit, split. */
235
+ caveats?: Caveat[];
236
+ /** With options.details: the ports behind the Ports limit (cycles = uops / ports) and the instructions that load them. */
237
+ portSet?: { ports: string[]; uops: number; cycles: number; instructions: { index: number; instr: string; uops: number }[] };
238
+ /** With options.details: issue slots per iteration, used and lost by cause. */
239
+ issueSlots?: { width: number; perIteration: { issued: number; frontEnd: number; rob: number; rs: number; other: number } };
240
+ }
241
+
242
+ export interface ArchInfo {
243
+ /** The id to pass as `arch`, e.g. "SKL". */
244
+ id: string;
245
+ /** Display name, e.g. "Skylake". */
246
+ name: string;
247
+ year: number | null;
248
+ /** An experimental model of the fork jtl06/uiCA (ZEN3, ADL-P, ICX). */
249
+ prototype: boolean;
250
+ /** The instruction table it uses (data/arch/<table>.json). */
251
+ table: string;
252
+ /** XED chip name used for decoding. */
253
+ xedChip: string;
254
+ }
255
+ export type ArchField = keyof ArchInfo;
256
+
257
+ export interface AssembleResult {
258
+ code: 0;
259
+ hex: string;
260
+ length: number;
261
+ bytes: Uint8Array;
262
+ /** Warnings, if any. */
263
+ stderr: StderrLine[];
264
+ }
265
+
266
+ export type CompareRow =
267
+ | { arch: string; name: string; year: number | null; prototype: boolean; code: 0; tp: number; mode: 'loop' | 'unroll'; bottlenecks: string[]; limits: Limit[]; decodeErrors: number }
268
+ | { arch: string; name: string; year: number | null; prototype: boolean; code: 1 | 2 | 3; error: string };
269
+
270
+ export interface CompareResult {
271
+ code: 0;
272
+ /** The assembled machine code, when `source` was given. */
273
+ hex?: string;
274
+ loop?: LoopInfo;
275
+ stderr: StderrLine[];
276
+ results: CompareRow[];
277
+ }
278
+
279
+ export interface Wuica {
280
+ /** POST /api/analyze/<arch>. Failures resolve to a Failure (never throw for bad input). */
281
+ analyze(arch: string, request: AnalyzeRequest): Promise<AnalyzeResult | Failure>;
282
+ /** Single-object form: `arch` in the request (default "SKL"). */
283
+ analyze(request: AnalyzeRequest & { arch?: string }): Promise<AnalyzeResult | Failure>;
284
+ /** The machine code an analysis of assembly text gets (as the web page reads it: the loop of a whole function, objdump
285
+ * lines, exits as not taken, ';' comments, a marked region); `bytes` and `hex` of the analyzed code, `loop` what was picked. */
286
+ machineCode(source: string, syntax?: Syntax, loop?: LoopChoice): Promise<{ code: 0; hex: string; bytes: Uint8Array; stderr: StderrLine[]; loop: LoopInfo | null } | Failure>;
287
+ /** POST /api/compare: one block on several microarchitectures (default: all of archs()); assembled once. The
288
+ * microarchitectures are analyzed on worker threads (CreateOptions.threads); the response is the same either way. */
289
+ compare(request: CompareRequest): Promise<CompareResult | Failure>;
290
+ /** Several blocks on one microarchitecture: each result exactly what analyze(arch, request) returns, in the same
291
+ * order. The code is assembled on the calling thread; the analyses run on worker threads when the work is worth it. */
292
+ analyzeMany(arch: string, requests: AnalyzeRequest[]): Promise<(AnalyzeResult | Failure)[]>;
293
+ /** Several blocks on several microarchitectures: each result exactly what compare() returns for that request (its
294
+ * `archs`, else options.archs, else all); every block x microarchitecture is one job for the threads. */
295
+ compareMany(requests: CompareRequest[], options?: { archs?: string[] }): Promise<(CompareResult | Failure)[]>;
296
+ /** An object file or executable (ELF or Mach-O, x86-64; a universal file's x86-64 slice) as llvm-objdump -d's text
297
+ * of its code sections, which analyze() and compare() read as `source` (the loop at its address, the alignment from
298
+ * it). Another architecture or format is a Failure that says what it is and how to get x86-64. `func` is resolved
299
+ * (exact, without Mach-O's "_", or a unique part of a name) and returned as `func`. */
300
+ disassemble(bytes: Uint8Array, options?: { name?: string; func?: string | null }): { code: 0; text: string; format: string; functions: { name: string; section: string; address: number; size: number }[]; func?: string } | Failure;
301
+ /** GET /api/archs: in order of release (uiCA's ablation variants, ids with "_", are left out). */
302
+ archs(): ArchInfo[];
303
+ archs(fields: ArchField[] | string): Partial<ArchInfo>[];
304
+ /** POST /api/assemble: LLVM's x86 assembler (Intel noprefix by default). */
305
+ assemble(source: string, syntax?: Syntax): Promise<AssembleResult | Failure>;
306
+ /** The compact form of a successful analyze() result; a Failure is returned unchanged. */
307
+ summarize(result: AnalyzeResult): AnalyzeSummary;
308
+ summarize(result: Failure): Failure;
309
+ /** The derived diagnosis of a successful analyze() result with its microarchitecture's configuration (as in the REST
310
+ * response and summarize()); null for a failure. */
311
+ insights(result: AnalyzeResult | Failure): Insights | null;
312
+ /** The id for a user-supplied name (case-insensitive, "-" optional), DEFAULT_ARCH for empty input, or null. */
313
+ resolveArch(arch?: string | null): string | null;
314
+ /** How many times the analyzer was restarted after a trap. */
315
+ readonly restarts: number;
316
+ /** The number of compare()'s worker threads running now (they stop after 30 s without work). */
317
+ readonly threads: number;
318
+ /** Stops compare()'s worker threads now (idle threads never keep the process alive). The instance stays usable. */
319
+ close(): Promise<void>;
320
+ }
321
+
322
+ export interface CreateOptions {
323
+ /** Directory with uarch.json and arch/<NAME>.json (plain or .br). Default: the tables shipped in the package. */
324
+ dataDir?: string;
325
+ /** Path of wuica_wasm.wasm (plain or .br). */
326
+ analyzerWasm?: string;
327
+ /** Path of wuica_asm.wasm (plain or .br). */
328
+ assemblerWasm?: string;
329
+ /** The most worker threads compare(), analyzeMany() and compareMany() use. A number: up to that many (one per job at
330
+ * most); 1: none (one after another on the calling thread). Default: the environment variable WUICA_THREADS, else
331
+ * "auto": by the amount of work (blocks x microarchitectures, their instructions, the tables to load): none when it
332
+ * would take less than about 0.3 s on one thread, else 2 to 8, at most the cores but one (none inside a worker
333
+ * thread). */
334
+ threads?: number | 'auto';
335
+ }
336
+
337
+ export function createWuica(options?: CreateOptions): Promise<Wuica>;
338
+
339
+ /** Normalizes hex input ("48 01 d8", "0x48,0x01", "\\x48\\x01") to lower-case hex; null if invalid. */
340
+ export function normalizeHex(input: string | Uint8Array): string | null;
341
+
342
+ /** llvm-mc diagnostics as stderr lines with tags. */
343
+ export function stderrLines(message: string): StderrLine[];
344
+ export function parseDiagnostics(text: string): Array<{ line: number | null; column: number | null; severity: 'error' | 'warning' | 'note'; message: string }>;
345
+
346
+ export const OPTION_DEFAULTS: Readonly<Required<AnalysisOptions>>;
347
+ export const ARCH_FIELDS: readonly ArchField[];
348
+ export const DEFAULT_ARCH: string;
349
+ /** A 482-instruction loop (hex) for warming up the analyzer: after one analysis of it (and a pause, while V8 optimizes
350
+ * in the background), the first analysis of a large block runs at nearly full speed. */
351
+ export const WARM_HEX: string;
352
+ export const ARCH_ORDER: string[];
353
+ export const ARCH_INFO: Record<string, { name: string; year: number }>;
354
+
355
+ /** The derived diagnosis of an analysis (the web page's bound view; also `insights` in the MCP summary and the REST response).
356
+ * `config` is the microarchitecture's configuration in uarch.json (only `splitLoadCycles` is read, for the `split` caveat);
357
+ * without it, as on a CPU without a split-load cost. The instance's insights() passes it. */
358
+ export function insights(result: AnalyzeResult, config?: { splitLoadCycles?: number } | null): Insights | null;
359
+
360
+ /** A known blind spot of the model that the block meets (Insights.caveats; the CLI's -json, one CPU or several). */
361
+ export interface Caveat {
362
+ /** rmw-index: a read-modify-write to an indexed address (store forwarding depends on the data); paths: a conditional
363
+ * branch inside the block (an if/else, a second back edge): both sides are simulated, a real iteration takes one;
364
+ * exit: an exit before the loop's branch (its mispredict); split: loads that may cross a cache line. */
365
+ id: 'rmw-index' | 'paths' | 'exit' | 'split';
366
+ /** The short form ("both paths"). */
367
+ text: string;
368
+ /** The explanation (paths: the branch's source line when the result has loop.lines, else its instruction number). */
369
+ title: string;
370
+ /** Indexes into the instructions (rows). */
371
+ instructions: number[];
372
+ }
373
+
374
+ export type WhatIfVariant = 'unroll2' | 'unroll4' | 'unroll8' | 'acc2' | 'acc3' | 'acc4' | 'acc8' | 'simpleFrontEnd' | 'noMacroFusion' | 'noMicroFusion' | 'nochain';
375
+ export const WHAT_IF_VARIANTS: readonly WhatIfVariant[];
376
+ export interface WhatIfResult {
377
+ code: 0;
378
+ arch: string;
379
+ tp: number;
380
+ mode: 'loop' | 'unroll';
381
+ bottlenecks: string[];
382
+ unit: 'cycles per original iteration';
383
+ loop?: LoopInfo;
384
+ /** tp per original iteration, delta = tp − base tp, speedup = base tp / tp; estimate: no analysis (nochain);
385
+ * renamed (accN): the chain's registers and the ones of the copies after the first. */
386
+ variants: { id: WhatIfVariant; label: string; tp?: number; delta?: number; speedup?: number | null; estimate?: boolean; bottlenecks?: string[]; renamed?: { from: string; to: string[] }[]; error?: string }[];
387
+ /** With accumulator variants: the best N (the smallest within 1% of the fastest; 1 = as it is) and its tp. */
388
+ accumulators?: { best: number; tp: number };
389
+ }
390
+
391
+ /** The CLI's `-json -whatif`: one WhatIfResult per CPU, keyed by its id, with one CPU as with several. With `-per N`,
392
+ * each has elementsPerIteration (N) and perElement (tp / N), and each variant with a tp its perElement. */
393
+ export type CliWhatIf = Record<string, (WhatIfResult & { elementsPerIteration?: number; perElement?: number; variants: (WhatIfResult['variants'][number] & { perElement?: number })[] }) | Failure>;
394
+ /** The CLI's `-json` with one CPU: the analyze result with insights (caveats in insights.caveats), perElement (-per)
395
+ * and whatIf (-whatif). */
396
+ export type CliAnalyzeJson = AnalyzeResult & { insights?: Insights; perElement?: number; whatIf?: CliWhatIf };
397
+ /** The CLI's `-json` with several CPUs: the compare result; each result with perElement (-per) and caveats (the same
398
+ * objects as insights.caveats with one CPU); whatIf (-whatif) as with one CPU. */
399
+ export type CliCompareJson = CompareResult & { results: (CompareResult['results'][number] & { perElement?: number; caveats?: Caveat[] })[]; whatIf?: CliWhatIf };
400
+ /** The CLI's `--version -json`: the package's version and the uiCA reference whose data and model it has (from the
401
+ * repository's ci/data-asset.txt at build time; null if the package was not built). */
402
+ /** The CLI's `-json` with several inputs (wuica a.s b.s ..., -files LIST): `code` is the largest of the files' codes
403
+ * (the exit status); each entry is what a single run prints for that file (CliAnalyzeJson, CliCompareJson, a Failure,
404
+ * or with -loops {code, loops}), with the file's name as given. */
405
+ export interface CliBatchJson { code: number; files: ({ file: string } & (CliAnalyzeJson | CliCompareJson | Failure | { code: 0; loops: LoopListing[] }))[] }
406
+ export interface CliVersionJson { wuica: string; uiCA: { repository: string; commit: string; branch?: string } | null; node: string }
407
+ /** The what-if experiments of the web page (the MCP tool `what_if`), with `analyze` (e.g. a Wuica's analyze, bound) and,
408
+ * for the accumulator variants, `assemble` (e.g. a Wuica's assemble, bound). */
409
+ export function whatIf(analyze: (arch: string, request: AnalyzeRequest) => Promise<AnalyzeResult | Failure>, arch: string, request: AnalyzeRequest, variants?: readonly WhatIfVariant[],
410
+ tools?: { assemble?: (text: string) => Promise<AssembleResult | Failure> }): Promise<WhatIfResult | Failure>;
package/lib/archs.js ADDED
@@ -0,0 +1,44 @@
1
+ // Display names, release years and order of the microarchitecture models (the keys of `configs` in uarch.json).
2
+
3
+ // In order of release (explicit: several share a year).
4
+ export const ARCH_ORDER = ['SNB', 'IVB', 'HSW', 'BDW', 'SKL', 'KBL', 'SKX', 'CFL', 'CLX', 'ICL', 'TGL', 'ZEN3', 'RKL', 'ICX', 'ADL-P'];
5
+
6
+ export const ARCH_INFO = {
7
+ SNB: { name: 'Sandy Bridge', year: 2011 },
8
+ IVB: { name: 'Ivy Bridge', year: 2012 },
9
+ HSW: { name: 'Haswell', year: 2013 },
10
+ BDW: { name: 'Broadwell', year: 2014 },
11
+ SKL: { name: 'Skylake', year: 2015 },
12
+ KBL: { name: 'Kaby Lake', year: 2016 },
13
+ SKX: { name: 'Skylake-X', year: 2017 },
14
+ CFL: { name: 'Coffee Lake', year: 2017 },
15
+ CLX: { name: 'Cascade Lake', year: 2019 },
16
+ ICL: { name: 'Ice Lake client', year: 2019 },
17
+ TGL: { name: 'Tiger Lake', year: 2020 },
18
+ ZEN3: { name: 'AMD Zen 3', year: 2020 },
19
+ RKL: { name: 'Rocket Lake', year: 2021 },
20
+ ICX: { name: 'Ice Lake server', year: 2021 },
21
+ 'ADL-P': { name: 'Alder Lake P-core', year: 2021 },
22
+ };
23
+
24
+ export const DEFAULT_ARCH = 'SKL';
25
+
26
+ // configs: uarch.json's `configs`. Returns the public list: keys with "_" (uiCA's ablation variants) are left out;
27
+ // unknown keys come last, by key.
28
+ export function archList(configs) {
29
+ const keys = Object.keys(configs).filter((k) => !k.includes('_'));
30
+ const rank = (k) => { const i = ARCH_ORDER.indexOf(k); return i < 0 ? ARCH_ORDER.length : i; };
31
+ keys.sort((a, b) => rank(a) - rank(b) || (a < b ? -1 : a > b ? 1 : 0));
32
+ return keys.map((key) => {
33
+ const c = configs[key];
34
+ const info = ARCH_INFO[key];
35
+ return {
36
+ id: key,
37
+ name: info?.name ?? key,
38
+ year: info?.year ?? null,
39
+ prototype: !!c.experimental,
40
+ table: c.name,
41
+ xedChip: c.XEDName,
42
+ };
43
+ });
44
+ }