wuica-cli 0.1.7 → 0.1.10

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 (64) hide show
  1. package/README.md +233 -57
  2. package/dist/data/arch/ADL-P.bin.br +0 -0
  3. package/dist/data/arch/BDW.bin.br +0 -0
  4. package/dist/data/arch/CFL.bin.br +0 -0
  5. package/dist/data/arch/CLX.bin.br +0 -0
  6. package/dist/data/arch/HSW.bin.br +0 -0
  7. package/dist/data/arch/ICL.bin.br +0 -0
  8. package/dist/data/arch/ICX.bin.br +0 -0
  9. package/dist/data/arch/IVB.bin.br +0 -0
  10. package/dist/data/arch/KBL.bin.br +0 -0
  11. package/dist/data/arch/RKL.bin.br +0 -0
  12. package/dist/data/arch/SKL.bin.br +0 -0
  13. package/dist/data/arch/SKX.bin.br +0 -0
  14. package/dist/data/arch/SNB.bin.br +0 -0
  15. package/dist/data/arch/TGL.bin.br +0 -0
  16. package/dist/data/arch/ZEN3.bin.br +0 -0
  17. package/dist/data/uarch.json.br +0 -0
  18. package/dist/manifest.json +145 -66
  19. package/dist/wuica_wasm.wasm.br +0 -0
  20. package/index.d.ts +205 -13
  21. package/lib/cli.js +467 -49
  22. package/lib/core.js +9 -1
  23. package/lib/details.js +4 -23
  24. package/lib/examples.js +27 -0
  25. package/lib/files.js +26 -3
  26. package/lib/index.js +228 -42
  27. package/lib/mcp.js +107 -84
  28. package/lib/objfile.js +218 -0
  29. package/lib/thread-worker.js +15 -9
  30. package/lib/threads.js +40 -23
  31. package/lib/wasm.js +42 -11
  32. package/lib/web/ab-diff.js +217 -0
  33. package/lib/web/accum.js +10 -2
  34. package/lib/web/asm-regions.js +24 -17
  35. package/lib/web/asm-tokens.js +357 -0
  36. package/lib/web/assembler.js +36 -6
  37. package/lib/web/block-diff.js +165 -0
  38. package/lib/web/bound-core.js +211 -0
  39. package/lib/web/branch-label.js +155 -0
  40. package/lib/web/caveats.js +115 -3
  41. package/lib/web/details.js +91 -0
  42. package/lib/web/examples.js +103 -0
  43. package/lib/web/loop-find.js +139 -16
  44. package/lib/web/markdown.js +437 -0
  45. package/lib/web/showcase.js +368 -0
  46. package/lib/web/whatif-core.js +339 -0
  47. package/package.json +3 -1
  48. package/dist/data/arch/ADL-P.json.br +0 -0
  49. package/dist/data/arch/BDW.json.br +0 -0
  50. package/dist/data/arch/CFL.json.br +0 -0
  51. package/dist/data/arch/CLX.json.br +0 -0
  52. package/dist/data/arch/HSW.json.br +0 -0
  53. package/dist/data/arch/ICL.json.br +0 -0
  54. package/dist/data/arch/ICX.json.br +0 -0
  55. package/dist/data/arch/IVB.json.br +0 -0
  56. package/dist/data/arch/KBL.json.br +0 -0
  57. package/dist/data/arch/RKL.json.br +0 -0
  58. package/dist/data/arch/SKL.json.br +0 -0
  59. package/dist/data/arch/SKX.json.br +0 -0
  60. package/dist/data/arch/SNB.json.br +0 -0
  61. package/dist/data/arch/TGL.json.br +0 -0
  62. package/dist/data/arch/ZEN3.json.br +0 -0
  63. package/lib/insights.js +0 -100
  64. package/lib/whatif.js +0 -136
package/README.md CHANGED
@@ -17,7 +17,7 @@ experimental models of the fork [jtl06/uiCA](https://github.com/jtl06/uiCA): **A
17
17
  Everything runs offline. The two WebAssembly modules (the analyzer, and LLVM's x86 assembler for assembly input) and the
18
18
  instruction tables are shipped brotli-compressed. A table is loaded the first time its microarchitecture is used.
19
19
  Requirements: Node.js 20 or later. **No dependencies**: `npm install wuica-cli` (or `npx wuica-cli`) adds this one
20
- package, 2.3 MB unpacked; the MCP server is part of it.
20
+ package, 2.4 MB unpacked; the MCP server is part of it.
21
21
 
22
22
  The commands are `wuica` and `wuica-mcp`. Install them with `npm install -g wuica-cli`, or run without installing
23
23
  with `npx wuica-cli ...`. The examples below write `wuica`.
@@ -25,15 +25,24 @@ with `npx wuica-cli ...`. The examples below write `wuica`.
25
25
  ## The CLI in five minutes
26
26
 
27
27
  ```
28
+ wuica -example saxpy -arch SKL,ZEN3,ADL-P # a built-in loop, no file needed (-examples lists them)
28
29
  clang -O3 -march=haswell -S dot.c -o dot.s # AT&T, as clang and gcc write it: detected, no flag needed
29
30
  wuica dot.s # uiCA's report for SKL, of the loop wuica picked
30
31
  wuica dot.s -arch SKL,ZEN3,ADL-P # one table for several CPUs ("all": every one)
31
32
  wuica dot.s -per 8 # the loop does 8 elements per iteration: cycles per element too
32
33
  wuica dot.s -loops # the loops in the file; -loop N or -loop .LBB0_12 picks one
33
34
  wuica dot.s -whatif # unrolled, N accumulators, front end and fusion variants
35
+ wuica dot.s -arch SKL,ZEN3 -md # Markdown to paste in an issue or a chat (any mode)
36
+ wuica diff dot.s dot4.s -per 8,32 # before and after: speed-up, bottlenecks, ports, instructions changed
37
+ clang -O3 -c dot.c && wuica dot.o -func dot # an object file (ELF or Mach-O, x86-64): no objdump needed
38
+ wuica *.s -arch SKL,ZEN3 # several files in one run: one table (-files LIST for long lists)
34
39
  objdump -d dot.o | wuica # objdump output: the loop's real alignment from its address
40
+ perf annotate --stdio -s dot | wuica # a profile: the hottest loop, samples and source lines per instruction
35
41
  ```
36
42
 
43
+ On an Arm Mac, give clang `--target=x86_64-linux-gnu` (wuica analyzes x86-64 code; Apple's clang knows no
44
+ `-march=haswell` for arm64).
45
+
37
46
  - **Syntax.** Intel (noprefix) or AT&T is detected from the text (`%rdx`, `$8`, `(%rdi,%rcx,4)` are AT&T);
38
47
  stderr says which (`analyzed: loop .LBB0_9 (lines 28-47, in dot), AT&T syntax (detected)`). `-att` or `-intel`
39
48
  force one.
@@ -53,8 +62,20 @@ objdump -d dot.o | wuica # objdump output: the loop's real
53
62
  edges, as clang's remainder loops often have), both sides of the branch are simulated, one after the other, while a
54
63
  real iteration takes one. A `Not modelled: both paths: both sides of the branch at line N …` line (table note
55
64
  `both paths`; JSON caveat `paths`) says so. To analyze one side, put `# wuica-begin` and `# wuica-end` around it.
56
- - **One input per run**: a file, `-` or nothing for stdin, a hex argument, `-hex` or `-raw FILE` (bare machine code:
57
- for an object file, `objdump -d file.o | wuica`).
65
+ - **Inputs**: a file (assembly, objdump output, or an object file), `-` or nothing for stdin, a hex argument, `-hex` or
66
+ `-raw FILE` (bare machine code).
67
+ - **Object files.** An ELF or Mach-O x86-64 object, executable or shared object is read directly: its code as
68
+ `llvm-objdump -d` prints it (decoded by the analyzer), so `wuica dot.o` and `objdump -d dot.o | wuica` pick the same
69
+ loop and give the same numbers. `-func NAME` takes the symbol, without Mach-O's `_`, or a unique part of it; `-funcs`
70
+ lists the functions; `-loops` gives the loops' addresses; `-ffunction-sections` objects work. An arm64 object (what a
71
+ Mac compiles by default) says so and how to compile for x86-64 (`clang -arch x86_64 -c`, or
72
+ `--target=x86_64-linux-gnu`); COFF is not supported yet (`llvm-objdump -d f.obj | wuica`).
73
+ - **Several inputs** (`wuica a.s b.s c.o`, a glob, or `-files LIST` with one name per line, `-files -` from stdin):
74
+ one process for all of them, the analyses spread over the threads. One CPU: a row per file (file, loop, TP,
75
+ bottlenecks, notes); several: a row per file and CPU (grouped by file, a CPU column: any number of CPUs fits in 80
76
+ columns). `-TPonly`: `file<TAB>[CPU<TAB>]cycles` lines; `-report` adds uiCA's report of each file, `-whatif` the
77
+ what-if tables, after a `==> FILE <==` line. A file that fails does not stop the others: its row says why, and the
78
+ exit status is the largest of the files' statuses. One input prints exactly what it printed before.
58
79
  - **Tables.** `-arch A,B,C` prints one row per CPU; `-` means unknown (uiCA names no single bottleneck; the notes
59
80
  give the nearest limit), `5.00*` that the CPU could not decode some instructions (they are left out), and the notes
60
81
  column the caveats (what the model does not simulate, such as store forwarding through an indexed address).
@@ -65,16 +86,23 @@ objdump -d dot.o | wuica # objdump output: the loop's real
65
86
  - **What if** (`-whatif`): a table per CPU, in cycles per original iteration, or per element with `-per N`. With
66
87
  `-TPonly`, one `variant cycles` line per variant after the throughput (`acc2 16.00`; with `-per`, `acc2 16.00
67
88
  2.00`; with several CPUs, each line starts with the CPU). Estimates (`>=` in the table) are printed as plain numbers.
89
+ - **Markdown** (`-md`): GitHub-flavoured Markdown on stdout instead of the text report, for an issue, a review or a
90
+ chat: one CPU gives the headline (cycles per iteration, or per element with `-per N`; the CPU; the bottleneck or
91
+ `unknown · nearest X`), the limits, the next limit, the `not modelled` caveats, the critical chain, the uop table
92
+ (branch targets as the labels in the text) and the analyzed code; `-arch A,B,C` the CPU table; several files the
93
+ files × CPUs table (`-report`: each file's report); `-whatif` and `-loops` their tables. Columns are padded to read
94
+ in a monospace font. Not with `-json` or `-TPonly`; diagnostics and the exit status are as without it.
68
95
  - **JSON** (`-json`): one CPU gives the analyze response (`tp`, `bottlenecks`, `limits`, `rows`, `criticalPath`,
69
96
  `insights`, `loop`, `syntax`, and `perElement` / `whatIf` when asked); several give `{code, hex, loop, stderr,
70
97
  results: [{arch, tp, bottlenecks, limits, decodeErrors, perElement?, caveats?}]}`. The shapes are the same for one
71
98
  CPU and several: `whatIf` is keyed by CPU (`{SKL: {tp, variants: [{id, tp, …, perElement?}], perElement?}}`), and a
72
99
  caveat is `{id, text, title, instructions}` (in `insights.caveats` with one CPU, `results[].caveats` with several).
73
- Types: `CliAnalyzeJson`, `CliCompareJson`, `CliWhatIf` in index.d.ts. `--version -json` gives `{wuica, uiCA:
100
+ Types: `CliAnalyzeJson`, `CliCompareJson`, `CliWhatIf` in index.d.ts. Several inputs give `{code, files: [{file,
101
+ ...}]}`: each entry is what a single run prints for that file, with its name (`CliBatchJson`). `--version -json` gives `{wuica, uiCA:
74
102
  {repository, commit, branch}, node}`: the uiCA commit whose data and model the package has.
75
103
  - **Syntax mistakes.** When the assembler fails, a `hint:` line names a line with the other syntax's operands (mixed
76
104
  AT&T and Intel lines, a `.intel_syntax` directive over AT&T code, `mov rdx, $8` in Intel code) and the flag to try.
77
- - No colours and no links, on a terminal or not.
105
+ - No colours and no links, on a terminal or not (`-md` is plain text too).
78
106
 
79
107
  ## What the numbers mean
80
108
 
@@ -91,7 +119,7 @@ Decoder or DSB. `limits` gives the throughput each component alone would allow.
91
119
  ## Library
92
120
 
93
121
  ```js
94
- import { createWuica } from 'wuica-cli';
122
+ import { createWuica, markdown } from 'wuica-cli';
95
123
 
96
124
  const w = await createWuica();
97
125
  const r = await w.analyze('SKL', { source: 'loop:\n add rax, [rsi]\n add rsi, 8\n dec rcx\n jnz loop\n' });
@@ -110,18 +138,23 @@ w.archs(); // [{id, name, year, p
110
138
  await w.assemble('vaddps zmm0, zmm1, zmm2'); // {code: 0, hex, length, bytes, stderr}
111
139
  w.summarize(r); // compact form (the MCP analyze result)
112
140
  w.insights(r); // the diagnosis alone (REST's insights)
141
+ markdown.report(r, { insights: w.insights(r) }); // Markdown, as wuica -md (also cpuTable, whatIf, loops, compare)
113
142
  ```
114
143
 
115
144
  Methods never throw for bad input: they resolve to a failure `{code, error, stderr}` (see the contract below).
116
- `createWuica({ dataDir })` reads the tables from another directory (`uarch.json` and `arch/<NAME>.json`, plain or
117
- `.br`). TypeScript declarations are included (`index.d.ts`).
118
-
119
- `compare` analyzes the microarchitectures in parallel on worker threads: by default one thread per two
120
- microarchitectures (a thread's start costs about one analysis), at most `os.availableParallelism()`.
121
- `createWuica({ threads: N })` or the environment variable `WUICA_THREADS=N` uses up to N threads, one per
122
- microarchitecture; 1 runs them one after another on the calling thread. The response is the same either way. Each thread loads only the
123
- tables of the microarchitectures it analyzes and keeps them for the next `compare`; idle threads do not keep the process
124
- alive and stop after 30 s (`w.close()` stops them at once). A thread's WebAssembly memory has a lower limit (a quarter
145
+ `createWuica({ dataDir })` reads the tables from another directory (`uarch.json` and the binary `arch/<NAME>.bin`,
146
+ plain or `.br`; a uiCA export's `arch/<NAME>.json` is converted by `tools/encode-tables.sh IN_DIR OUT_DIR` of the
147
+ repository: the analyzer that ships reads no JSON tables). `w.disassemble(bytes)` turns an object file into the text `analyze` reads. TypeScript declarations are included (`index.d.ts`).
148
+
149
+ `compare`, `analyzeMany(arch, requests)` and `compareMany(requests, {archs})` analyze on worker threads when the work
150
+ is worth it: by default the number of threads comes from the work (the tables to load, the analyses and their
151
+ instructions): none when it would take less than about 0.3 s on one thread (a thread's start, its table and its first,
152
+ not yet optimized analysis cost more than they save; `-arch all` on a small block stays on one thread), else one per
153
+ 0.15 s of work, from 2 to 8, at most the cores but one. `createWuica({ threads: N })` or the environment variable
154
+ `WUICA_THREADS=N` uses up to N threads (one per job at most); 1 runs everything on the calling thread. The response is
155
+ the same either way. The threads share one compiled module and take jobs from one queue; each loads the tables of the
156
+ jobs it takes and keeps them for the next call; idle threads do not keep the process alive and stop after 30 s
157
+ (`w.close()` stops them at once). A thread's WebAssembly memory has a lower limit (a quarter
125
158
  of the RAM shared by the threads, 256 MB to 1 GB each); an analysis that exceeds it is done again on the calling thread.
126
159
 
127
160
  Inputs on which the original uiCA fails can make the WebAssembly module trap. In that case the call resolves to
@@ -134,23 +167,34 @@ wuica loop.s # assembly file (syntax detected), uiCA's r
134
167
  wuica loop.s -arch ICL -TPonly # only the throughput
135
168
  cat loop.s | wuica -arch ZEN3 # stdin (or "-")
136
169
  wuica -att loop_att.s # AT&T syntax, forced (-intel forces Intel)
137
- wuica 4801d84801c349ffcf75f5 # a hex argument (as in the Rust CLI)
170
+ wuica 4801d84801c349ffcf75f5 # a hex argument (as in the repository's reference binary)
138
171
  wuica -hex code.txt # hex from a file or stdin ("48 01 d8", "0x48,0x01" are fine)
139
172
  wuica -raw code.bin # raw machine code
140
173
  wuica loop.s -arch all # throughput table for every microarchitecture (in parallel)
141
174
  wuica loop.s -arch SKL,ICL,ZEN3 # throughput table for these
142
175
  wuica -list # the microarchitectures
143
176
  wuica loop.s -json # the JSON result (the contract's analyze response)
177
+ wuica loop.s -arch SKL,ZEN3 -md # Markdown (an issue, a review, a chat); with -whatif, -loops, several files
144
178
  wuica psum.s -loop whole # the whole text, not the loop found in it (-loop auto, the default, or -loop N)
145
179
  wuica psum.s -loops # list the loops; -loop .LBB0_12 or -func psum to choose
146
180
  wuica psum.s -whatif -per 8 # what-if variants; cycles per element (8 elements per iteration)
181
+ wuica psum.s -variants align,acc4 # these variants only; align: the 64 alignment offsets (min, median, max)
182
+ wuica dot.o -func dot # an object file (ELF or Mach-O x86-64); -funcs lists its functions
183
+ wuica a.s b.s c.o -arch SKL,ZEN3 # several inputs: one table, a row per file and CPU
184
+ wuica -files list.txt -TPonly # the names from a file (- for stdin): file<TAB>cycles lines
185
+ wuica *.s -json # {code, files: [{file, ...}]}, each entry as a single run's JSON
186
+ wuica -examples # the built-in examples (the web page's set)
187
+ wuica -example dot1 -whatif # one of them, as if it were the input file (every option applies)
188
+ wuica -example dot1 -show > dot.s # its assembly, to save and edit
189
+ wuica diff a.s b.s -per 8 [-md|-json] # two blocks (files, - or hex): before and after
147
190
  wuica --version
148
191
  ```
149
192
 
150
193
  The simulation options are uiCA's: `-alignmentOffset N`, `-initPolicy diff|same|stack`, `-simpleFrontEnd`,
151
194
  `-noMicroFusion`, `-noMacroFusion`, `-minIterations N`, `-minCycles N`, and `-trace` (with `-json`). Every flag also
152
- takes `--flag` and `--flag=value`, in any case (`--tponly`, `--arch=zen3`). With several
153
- microarchitectures, `-threads N` analyzes them on at most N threads at a time (`-threads 1`: one after another).
195
+ takes `--flag` and `--flag=value`, in any case (`--tponly`, `--arch=zen3`). With several microarchitectures or files,
196
+ the threads are chosen by the amount of work (see Library); `-threads N` uses at most N threads (`-threads 1`: one
197
+ after another).
154
198
  Diagnostics go to stderr. The exit status is the result code: 0 ok, 1 bad request or usage, 2 assembler error, 3 analysis failed.
155
199
  `wuica -h` lists everything.
156
200
 
@@ -162,41 +206,122 @@ newline-delimited JSON-RPC 2.0 with the `initialize` handshake of the protocol r
162
206
  `ping`, `tools/list` and `tools/call`. Arguments are checked against the tools' JSON Schemas; a mismatch is a tool error
163
207
  (`isError`) that says what is wrong, an unknown tool a JSON-RPC error. The server ends with its stdin, and writes only
164
208
  protocol messages to stdout. `wuica mcp --help` prints the usage. The tool table itself (names, descriptions, JSON
165
- Schemas, handlers) is exported as `mcpTools(w)` from `wuica/mcp`, with `callTool` and `validate`; the remote server
166
- (`server/`) serves the same table over HTTP. It has five tools:
209
+ Schemas, handlers) is exported as `mcpTools(w)` from `wuica-cli/mcp`, with `callTool` and `validate`; the remote server
210
+ (`server/`) serves the same table over HTTP. Its tools:
167
211
 
168
212
  | Tool | What it does |
169
213
  |---|---|
170
214
  | `analyze` | one block on one microarchitecture: `tp`, bottlenecks, limits, a compact per-instruction table (ports, uop sources, fusion notes) and uiCA's text report (`format`: `json`, `text`, `both`) |
171
- | `what_if` | one block re-analyzed with one change each (the web page's "try" row): `unroll2`/`unroll4`/`unroll8` (per original iteration), `acc2`/`acc3`/`acc4`/`acc8` (N accumulators: unrolled ×N with the loop-carried register renamed in each copy; `renamed` lists the registers, `accumulators.best` is the best N, 1 = as it is), `simpleFrontEnd`, `noMacroFusion`, `noMicroFusion`, and `nochain` (an estimate without the loop-carried chain); per variant `tp`, `delta`, `speedup` |
215
+ | `what_if` | one block re-analyzed with one change each (the web page's "try" row): `unroll2`/`unroll4`/`unroll8` (per original iteration), `acc2`/`acc3`/`acc4`/`acc8` (N accumulators: unrolled ×N with the loop-carried register renamed in each copy; `renamed` lists the registers, `accumulators.best` is the best N, 1 = as it is), `simpleFrontEnd`, `noMacroFusion`, `noMicroFusion`, `nochain` (an estimate without the loop-carried chain), and `align` when asked for (the 64 alignment offsets); per variant `tp`, `delta`, `speedup` (and `approx: {limit, shown}` when the simulation came out up to 1% under the variant's Ports or Issue limit: the text shows that limit, ≈) |
216
+ | `diff_blocks` | two blocks, A (before) and B (after), on one microarchitecture: `tp` of each, `delta`, `speedup`, per element with `per`, bottlenecks and limits before and after, each port's uops, the instructions changed, added or removed |
172
217
  | `compare_archs` | one block on several or all microarchitectures: `tp` and bottlenecks per microarchitecture |
218
+ | `list_loops` | the loops of assembly text (what `loop` can pick): index, label, function, lines, instructions, depth, the one picked by default |
173
219
  | `list_archs` | ids, names, years, prototype flags |
174
220
  | `assemble` | assembly → hex bytes, or diagnostics with line/column |
175
221
 
176
- Add it to **Claude Code** from a local checkout (after `build.sh` and `npm install`) or an installed tarball:
177
-
178
- ```
179
- claude mcp add wuica -- node /absolute/path/to/packages/wuica/bin/wuica.js mcp
180
- ```
222
+ ### Set it up in your agent
181
223
 
182
- Once the package is published on npm:
224
+ The command is `npx -y wuica-cli mcp` (stdio) in every client. **Claude Code**, **OpenAI Codex CLI**, **opencode**
225
+ and **Amp** add it with one command:
183
226
 
184
- ```
227
+ ```sh
185
228
  claude mcp add wuica -- npx -y wuica-cli mcp
229
+ codex mcp add wuica -- npx -y wuica-cli mcp
230
+ opencode mcp add wuica -- npx -y wuica-cli mcp
231
+ amp mcp add wuica -- npx -y wuica-cli mcp
186
232
  ```
187
233
 
188
- Other MCP clients (Claude Desktop, Cursor, VS Code, ...) use the same command in their JSON configuration:
234
+ Most other clients read a JSON file with an `mcpServers` object: **Claude Desktop** (Settings → Developer → Edit Config:
235
+ `claude_desktop_config.json`), **Cursor** (`~/.cursor/mcp.json`, or `.cursor/mcp.json` in a project), **Gemini CLI**
236
+ (`~/.gemini/settings.json`, or `.gemini/settings.json` in a project), **Cline** (MCP Servers → Configure → Configure MCP
237
+ Servers: `cline_mcp_settings.json`) and **Continue** (a file in `.continue/mcpServers/`):
189
238
 
190
239
  ```json
191
240
  {
192
241
  "mcpServers": {
193
- "wuica": { "command": "npx", "args": ["-y", "wuica", "mcp"] }
242
+ "wuica": { "command": "npx", "args": ["-y", "wuica-cli", "mcp"] }
194
243
  }
195
244
  }
196
245
  ```
197
246
 
247
+ Where the format differs:
248
+
249
+ - **Codex** (`~/.codex/config.toml`, or `.codex/config.toml` in a trusted project; what `codex mcp add` writes):
250
+
251
+ ```toml
252
+ [mcp_servers.wuica]
253
+ command = "npx"
254
+ args = ["-y", "wuica-cli", "mcp"]
255
+ ```
256
+
257
+ - **opencode** 2.x (`opencode.jsonc` in the project, or the global configuration):
258
+
259
+ ```json
260
+ {
261
+ "$schema": "https://opencode.ai/config.json",
262
+ "mcp": { "servers": { "wuica": { "type": "local", "command": ["npx", "-y", "wuica-cli", "mcp"] } } }
263
+ }
264
+ ```
265
+
266
+ - **VS Code** with GitHub Copilot (`~/.copilot/mcp-config.json`; `.mcp.json` at the workspace root is behind an
267
+ experimental setting):
268
+
269
+ ```json
270
+ {
271
+ "mcpServers": {
272
+ "wuica": { "type": "stdio", "command": "npx", "args": ["-y", "wuica-cli", "mcp"], "tools": ["*"] }
273
+ }
274
+ }
275
+ ```
276
+
277
+ - **Zed** (`settings.json`):
278
+
279
+ ```json
280
+ {
281
+ "context_servers": {
282
+ "wuica": { "command": "npx", "args": ["-y", "wuica-cli", "mcp"], "env": {} }
283
+ }
284
+ }
285
+ ```
286
+
287
+ - **Amp** (`~/.config/amp/settings.json`, or `.amp/settings.json` in a project):
288
+
289
+ ```json
290
+ {
291
+ "amp.mcpServers": {
292
+ "wuica": { "command": "npx", "args": ["-y", "wuica-cli", "mcp"] }
293
+ }
294
+ }
295
+ ```
296
+
297
+ - **goose** (`~/.config/goose/config.yaml`):
298
+
299
+ ```yaml
300
+ extensions:
301
+ wuica:
302
+ type: stdio
303
+ name: wuica
304
+ enabled: true
305
+ cmd: npx
306
+ args: ["-y", "wuica-cli", "mcp"]
307
+ timeout: 300
308
+ ```
309
+
310
+ The hosted server (`server/`, the REST API's host) speaks MCP over Streamable HTTP at
311
+ `https://api.wuica.jacen.li/mcp`, with nothing to install: `claude mcp add --transport http wuica
312
+ https://api.wuica.jacen.li/mcp`. Clients with a JSON or TOML file give the URL instead of the command: `"url"` in
313
+ Cursor and Zed, `"type": "http", "url"` in VS Code, `"httpUrl"` in Gemini CLI, `"type": "remote", "url"` in opencode,
314
+ `url = "…"` in Codex.
315
+
316
+ To develop wuica, point a client at a checkout instead (after `packages/wuica/build.sh` and `npm install`):
317
+ `claude mcp add wuica -- node /absolute/path/to/packages/wuica/bin/wuica.js mcp`.
318
+
198
319
  Example prompt: *"Use wuica to compare this loop on Skylake, Ice Lake and Zen 3 and explain the bottleneck."*
199
320
 
321
+ **Without MCP.** An agent that can run shell commands can use the CLI directly: `npx -y wuica-cli FILE -arch SKL,ZEN3
322
+ -json` (one JSON object; the shapes are under "JSON" in [The CLI in five minutes](#the-cli-in-five-minutes)), `-whatif`
323
+ for the variants, `-loops` and `-loop N` to choose the loop, and `-example saxpy` to try it without a file.
324
+
200
325
  ## API contract
201
326
 
202
327
  The library, the MCP tools and the REST API (https://api.wuica.jacen.li, server/) share these shapes. They follow
@@ -207,9 +332,11 @@ text, and errors with structured stderr.
207
332
  | REST | Library | MCP tool |
208
333
  |---|---|---|
209
334
  | `GET /api/archs[?fields=id,name]` | `w.archs(fields?)` | `list_archs {fields?}` |
335
+ | — | `listLoops(source, {func?})` | `list_loops {source, func?}` |
210
336
  | `POST /api/analyze/<arch>` | `w.analyze(arch, request)` | `analyze {arch, ...request, format?}` |
211
- | `POST /api/compare` | `w.compare(request)` | `compare_archs {...request}` |
212
- | — | `whatIf((a, r) => w.analyze(a, r), arch, request, variants?, {assemble: (t) => w.assemble(t)})` | `what_if {arch, ...request, variants?}` |
337
+ | `POST /api/compare` | `w.compare({...request, archs?, per?})` | `compare_archs {...request, archs?, per?}` |
338
+ | `POST /api/what-if/<arch>` | `w.whatIf(arch, {...request, variants?, per?})` | `what_if {arch, ...request, variants?, per?}` |
339
+ | `POST /api/diff/<arch>` | `w.diff(arch, {a, b, options?, per?})` | `diff_blocks {arch, a, b, options?, per?}` |
213
340
  | `POST /api/assemble` | `w.assemble(source, syntax)` | `assemble {source, syntax?}` |
214
341
 
215
342
  ### Microarchitectures: `GET /api/archs`
@@ -230,7 +357,6 @@ Request:
230
357
  ```json
231
358
  {
232
359
  "source": "loop: add rax, rbx\n dec rcx\n jnz loop",
233
- "hex": "4801d8...",
234
360
  "syntax": "intel",
235
361
  "options": {
236
362
  "alignmentOffset": 0, "initPolicy": "diff", "simpleFrontEnd": false, "noMicroFusion": false,
@@ -239,8 +365,8 @@ Request:
239
365
  }
240
366
  ```
241
367
 
242
- - Give exactly one of `source` (assembly; the library also accepts `asm`) and `hex` (machine code; spaces, commas and
243
- `0x` are allowed).
368
+ - Give exactly one of `source` (assembly; the library also accepts `asm`) and `hex` (machine code, `"4801d8..."`;
369
+ spaces, commas and `0x` are allowed).
244
370
  - `source` is read as the web page reads pasted assembly. `loop` (optional) says what of it is analyzed:
245
371
  - `"auto"` (the default): a whole function (`gcc -S`, `clang -S`, `objdump -d` lines with addresses, with or
246
372
  without the bytes, Intel or AT&T) is analyzed at its deepest loop (clang's `Inner Loop Header` notes count;
@@ -283,23 +409,39 @@ Request:
283
409
  (`{hex, arch, minIterations}`); `options` takes precedence. The MCP tools accept only the nested form.
284
410
  - The source must be 64-bit code: `.code16`, `.code16gcc` and `.code32` are an error (code 1), since the analyzer
285
411
  only models 64-bit mode. `assemble` alone accepts them.
286
- - `loop` exists in the library, REST (`/api/analyze`, `/api/compare`), the MCP tools `analyze`, `what_if` and
287
- `compare_archs`, and the package's CLI (`wuica -loop auto|whole|N`). The native CLI (`crates/wuica-cli`) reads
288
- machine code only (hex or `-raw`), so it has no `-loop`.
412
+ - `loop` exists in the library, REST (`/api/analyze`, `/api/compare`, `/api/what-if`, each block of `/api/diff`), the MCP
413
+ tools `analyze`, `what_if`, `compare_archs` and `diff_blocks` (per block), and the package's CLI (`wuica -loop
414
+ auto|whole|N`, also for `wuica diff`). The reference/test binary (`crates/wuica-cli`) reads
415
+ machine code only (hex or `-raw`), so it has no `-loop`. When the text has more than one loop, `otherLoops` lists the others (as `listLoops`
416
+ and `-loops` give them, without `auto`), in the analyze, summary and compare results.
417
+ - Assembly input: each instruction row (and `instructions[]`, `insights.chain[]`, `insights.hot.instructions[]`) has
418
+ `line`, its 1-based line in the text, and `loc` ("file.c:12") when the text has `.file`/`.loc` directives: what the
419
+ loop finder and the assembler record, not a match of the text. Machine code has neither.
420
+ - Profiles are read as they are: `objdump -dS` (or `-S`) output gives each instruction `source`, the interleaved source
421
+ line in force; `perf annotate --stdio` output gives `samples` (its percent of all the samples of the output: each
422
+ symbol's percentages weighted by its sample count; if a header has no count, each symbol's own percentages, said in a
423
+ note) and `source`, and when the text has several loops, the one whose
424
+ own instructions (not those of a loop nested in it) have the most samples is analyzed (`loop` still picks another).
425
+ `perf annotate --stdio2` output has no addresses: it is refused with a note to use `--stdio`. A text with `.rept`,
426
+ `.irp`, `.irpc`, `.macro` or `.if` has no `line` (its lines are not its instructions one to one) and is analyzed whole,
427
+ with a note; nor has code with a data directive (`.byte`, `.fill`, ...) among the analyzed instructions. A prefix alone
428
+ on its line (`lock`, then `add [rdi], eax`) is part of the next instruction.
289
429
 
290
430
  ### Option ranges per interface
291
431
 
292
- All interfaces run the same analyzer, but they accept different ranges for the numeric options. A value outside the
293
- range is refused (code 1, REST 400; the MCP tools' schema rejects it as invalid arguments), except in the web page,
294
- which clamps it into its range.
432
+ The numeric options have the same range in the library, the CLI, the MCP tools and the REST API: any integer up to
433
+ 2^53 - 1 in magnitude (`alignmentOffset`: negative values and values above 63 are read modulo 64; the reference
434
+ binary `crates/wuica-cli` refuses beyond ±2^62). Another value is refused (code 1, REST 400; the MCP tools' schema rejects
435
+ it).
436
+ Everywhere, a block of more than 250,000 uops per iteration is refused (a work budget, code 3), and very large values run
437
+ out of memory (code 3). The differences:
295
438
 
296
- | Interface | `alignmentOffset` | `minIterations` | `minCycles` | Other limits |
297
- |---|---|---|---|---|
298
- | library, `wuica` CLI, native CLI (`crates/wuica-cli`) | any integer (negative values and values above 63 are simulated as given) | any integer | any integer | none; very large values run out of memory (library: code 3) |
299
- | MCP tools of `wuica mcp` (stdio) | 0–63 | 1–100000 | 1–1000000 | |
300
- | REST API (`server/`) | any integer | at most 1000 | at most 20000 | `source` at most 64 KB, `hex` at most 65536 characters, at most 10,000 instructions |
301
- | remote MCP (`server/`, `/mcp`) | 0–63 | 1–1000 | 1–20000 | as REST |
302
- | web page | 0–63 | 1–10000 | 1–100000 | at most 1 MiB of machine code (assembled or as hex) |
439
+ | Interface | Limits |
440
+ |---|---|
441
+ | REST API and remote MCP (`server/`) | `minIterations` at most 1000, `minCycles` at most 20000; `source` at most 64 KB, `hex` at most 65536 characters, at most 10,000 instructions |
442
+ | MCP tools (stdio and remote) | `minIterations` 1–100000, `minCycles` 1–1000000 (an agent should not start a 3 GB simulation by accident) |
443
+ | API server, its rate limit | per client, a token bucket (`rateBurst`, `ratePerMinute`); a request costs in proportion to the analyses it can start, as many as a compare of every microarchitecture costing `compareCost` (3): analyze 1 token, what-if `ceil(3 × analyses / 15)` with the base and one analysis per variant (`nochain` none, `align` 64): 3 for the default variants, 13 for `align` alone, 15 for both; diff 1; a compare `compareCost` whatever it lists, and at least one token per job it can run at once (a compare split over idle workers); at least 1 per request, at most the burst; the same in REST and `/mcp`. What-if and diff run all their analyses within one job's time limit and start none once the client has gone: a what-if returns the variants that finished and marks the others `not run: deadline` (`notRun` on the result); a diff fails and says which block was analyzed |
444
+ | web page | clamps `alignmentOffset` to 0–63, `minIterations` to 1–10000, `minCycles` to 1–100000; at most 1 MiB of machine code |
303
445
 
304
446
  Microarchitecture ids are accepted the same way everywhere: exactly, or case-insensitively with `-` optional (`adlp`,
305
447
  `adl-p` → `ADL-P`). Hex may contain spaces, commas and `0x` / `\x` prefixes everywhere.
@@ -326,11 +468,20 @@ Response (JSON), on success:
326
468
  The fields from `arch` to `trace` are the analysis response of the WebAssembly module (`docs/WASM-API.md` in the wuica
327
469
  repository: `rows[].values[i]` belongs to `columns[i]`, and `notes` is `M` macro-fused, `J` JCC erratum or `X`
328
470
  unsupported). `hex` is present when `source` was given and holds the assembled bytes. `stderr` holds the assembler's
329
- warnings, the notes on exits taken as not taken, and the warning "N position(s) could not be decoded". `insights` (REST only; the library's `analyze()` result
471
+ warnings, the notes on exits taken as not taken, and the warning "N position(s) could not be decoded". `unsupported` is
472
+ present only when the CPU cannot run the code: positions its decoder skipped (AVX-512 on SKL), or an instruction of an
473
+ extension it lacks that its decoder accepts (AVX-512 on ZEN3, by the instruction's encoding). It holds the reason:
474
+ `"needs AVX-512"` when the extension is known (from the instruction, or from the analyzed assembly text without its
475
+ comments), else `"12 undecodable"`; `tp` is then the reference's number, which leaves that code out, and the text, the
476
+ Markdown and the page do not present it as a result. `noData` is present only when the CPU can run the code but some of
477
+ its instructions are not in its tables (the note X: x87 tbyte loads, syscall, CLWB on ICX): their count; the result
478
+ stands, without their cost. compare's rows have both. `insights` (REST only; the library's `analyze()` result
330
479
  does not have it, `w.insights(r)` computes it) is the diagnosis described under the compact form below, with `portSet`
331
480
  and `issueSlots` when `options.details` is true.
332
481
 
333
482
  **Plain text** (CE's `Accept: text/plain`): the response is `text` (uiCA's report), or the `stderr` lines on failure.
483
+
484
+ **Markdown** (`Accept: text/markdown`, analyze, compare, what-if and diff): what `wuica -md` prints (`markdown.report`, `markdown.cpuTable`), with the same status codes.
334
485
  In the library this is `r.text`; the MCP tool takes `format: "text"`.
335
486
 
336
487
  **Compact form** (the MCP `analyze` JSON, `w.summarize(r)`): `{code, arch, name, year, prototype, tp, unit, mode,
@@ -383,7 +534,7 @@ Every call can fail like a compiler run in Compiler Explorer, with a non-zero `c
383
534
 
384
535
  ### Compare: `POST /api/compare`
385
536
 
386
- The request is the same as for analyze, plus an optional `archs` (ids; missing or empty: all listed ones; a repeated id counts once). The response:
537
+ The request is the same as for analyze, plus an optional `archs` (ids; missing or empty: all listed ones; a repeated id counts once) and `per` (elements per iteration: `elementsPerIteration` and each row's `perElement`, as `wuica -arch A,B -per N`). The response:
387
538
 
388
539
  ```json
389
540
  {
@@ -399,24 +550,48 @@ The request is the same as for analyze, plus an optional `archs` (ids; missing o
399
550
  The top-level `code` is non-zero only if the request or the assembly fails. A failure on one microarchitecture is
400
551
  reported in its row.
401
552
 
553
+ ### What-if: `POST /api/what-if/<arch>`
554
+
555
+ The request is analyze's plus `variants` (ids, default all: `unroll2`, `unroll4`, `unroll8`, `acc2`, `acc3`, `acc4`,
556
+ `acc8`, `simpleFrontEnd`, `noMacroFusion`, `noMicroFusion`, `nochain`; also `align`, only when asked for: the block at
557
+ each of the 64 alignment offsets, 64 analyses, `tp` the median and `alignment` {min, median, max, best, worst, spread,
558
+ offset}) and `per` (elements per iteration: also cycles per element). The response is the MCP tool's and `wuica -whatif -json`'s (`WhatIfResult`): the base `tp` and per variant
559
+ `tp` per original iteration, `delta`, `speedup`, or `error`; `accumulators.best`. `text/plain` gives the CLI's table,
560
+ `text/markdown` the Markdown one. Each variant is one analysis (`nochain` none, `align` 64), and the request costs tokens
561
+ in proportion (the rate limit above).
562
+
563
+ ### Diff: `POST /api/diff/<arch>`
564
+
565
+ `{a: block, b: block, options?, per?}`: each block as analyze's request; `options` for both; `per` elements per iteration
566
+ (N for both, or [A, B]). The response (`DiffResult` in index.d.ts; `wuica diff -json`): `a` and `b` (`tp`,
567
+ `bottlenecks`, `perElement`), `delta`, `speedup`, `verdict`, `perElement`, `bottlenecks` (`gone`, `new`), `limits`,
568
+ `ports` (uops per iteration before and after) and `instructions` (`counts`; `changes`: `changed`, `modified`, `added`,
569
+ `removed`, with the change of their uops). A failure of one block has an `error` that starts with `A: ` or `B: `. `text/plain` gives the
570
+ CLI's text, `text/markdown` the page's A–B tables.
571
+
402
572
  ### Assemble: `POST /api/assemble`
403
573
 
404
574
  Request: `{"source": "...", "syntax": "intel"}`. The whole text is assembled as it is (no loop finding, no region
405
575
  markers; `;` comments as above). Response: `{"code": 0, "hex": "4801d8", "length": 3, "stderr": []}`;
406
576
  the library also returns `bytes` (a `Uint8Array`). On failure: `{code: 2, error, stderr}` as above. The assembler is
407
577
  LLVM 22.1.2's (the same bytes as `llvm-mc`). Only `.text` is returned. `.include`/`.incbin` always fail. GNU as's
408
- `{load}`/`{store}` hints, which LLVM rejects, are removed at the start of a line.
578
+ `{load}`/`{store}` hints, which LLVM rejects, are removed at the start of a line, clang 23's `.prefalign` is read as
579
+ `.p2align`, and the line table (`.loc`, numbered `.file`) is not assembled (gcc 11+ `-g` output assembles).
409
580
 
410
581
  ## Building from the repository
411
582
 
412
583
  ```
413
584
  packages/wuica/build.sh # copies and compresses the wasm modules and tables into dist/, copies the licenses
414
585
  cd packages/wuica && npm install && npm test
415
- npm pack # wuica-<version>.tgz
586
+ npm pack # wuica-cli-<version>.tgz
416
587
  ```
417
588
 
418
589
  `build.sh` uses `target/wasm32-unknown-unknown/release/wuica_wasm.wasm` (it runs `./build-wasm.sh` if the file is
419
- missing), `assembler/dist/wuica_asm.wasm` and `data/`. `dist/manifest.json` records the size and SHA-256 of each
590
+ missing), `assembler/dist/wuica_asm.wasm` and `data/`. The instruction tables are shipped in a binary form
591
+ (`dist/data/arch/<NAME>.bin.br`, written from `data/arch/*.json` by `tools/encode-tables.sh`; 6.4 MB instead of
592
+ 14.6 MB, and loaded about 40% faster); the analyzer module is built without the JSON table loader (the Cargo feature
593
+ `json-tables` of `crates/wuica`, which the native tools and tests use). `dist/manifest.json` records
594
+ the size and SHA-256 of each
420
595
  uncompressed file.
421
596
 
422
597
  ## Licenses
@@ -430,8 +605,9 @@ uncompressed file.
430
605
  repository. It also contains wasi-libc and libc++ from wasi-sdk (Apache-2.0 WITH LLVM-exception, MIT and other
431
606
  permissive licenses).
432
607
  - The instruction data comes from [uops.info](https://www.uops.info) by Andreas Abel and Jan Reineke.
433
- - The MCP server uses the [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk) (MIT) and
434
- [zod](https://zod.dev) (MIT), installed as npm dependencies.
608
+ - The package has no dependencies. Its tests use the [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
609
+ (MIT) and [zod](https://zod.dev) (MIT) as development dependencies; the remote server (`server/`) uses them at run time.
435
610
 
436
- If you use uiCA's models in research, cite the uiCA paper: Andreas Abel and Jan Reineke, *uiCA: Accurate Throughput
437
- Prediction of Basic Blocks on Recent Intel Microarchitectures*, ICS 2022.
611
+ uiCA is described in: Andreas Abel and Jan Reineke, *uiCA: Accurate Throughput Prediction of Basic Blocks on Recent
612
+ Intel Microarchitectures*, ICS 2022. The Intel models are uiCA's; the ZEN3, ADL-P and ICX models are prototypes of the
613
+ fork [jtl06/uiCA](https://github.com/jtl06/uiCA) and are not part of that work.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file