wuica-cli 0.1.9 → 0.1.12

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.
package/README.md CHANGED
@@ -8,6 +8,9 @@ port's test corpus. The package contains:
8
8
  - a **command-line tool**: `npx wuica-cli loop.s -arch SKL`
9
9
  - a local **MCP server** (stdio) for AI agents: `npx wuica-cli mcp`
10
10
 
11
+ In the browser: [wuica.jacen.li](https://wuica.jacen.li) · source and issues: [github.com/jtl06/wuica](https://github.com/jtl06/wuica) ·
12
+ hosted API: [api.wuica.jacen.li](https://api.wuica.jacen.li)
13
+
11
14
  This is **not the official uiCA** (that is [uiCA.uops.info](https://uiCA.uops.info) and the
12
15
  [uiCA repository](https://github.com/andreas-abel/uiCA)). The instruction data (latencies, throughputs, port usage) comes
13
16
  from [uops.info](https://www.uops.info). Besides uiCA's Intel models (Sandy Bridge to Rocket Lake), wuica includes the
@@ -17,7 +20,7 @@ experimental models of the fork [jtl06/uiCA](https://github.com/jtl06/uiCA): **A
17
20
  Everything runs offline. The two WebAssembly modules (the analyzer, and LLVM's x86 assembler for assembly input) and the
18
21
  instruction tables are shipped brotli-compressed. A table is loaded the first time its microarchitecture is used.
19
22
  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.
23
+ package, 2.4 MB unpacked; the MCP server is part of it.
21
24
 
22
25
  The commands are `wuica` and `wuica-mcp`. Install them with `npm install -g wuica-cli`, or run without installing
23
26
  with `npx wuica-cli ...`. The examples below write `wuica`.
@@ -32,11 +35,17 @@ wuica dot.s -arch SKL,ZEN3,ADL-P # one table for several CPUs ("al
32
35
  wuica dot.s -per 8 # the loop does 8 elements per iteration: cycles per element too
33
36
  wuica dot.s -loops # the loops in the file; -loop N or -loop .LBB0_12 picks one
34
37
  wuica dot.s -whatif # unrolled, N accumulators, front end and fusion variants
38
+ wuica dot.s -arch SKL,ZEN3 -md # Markdown to paste in an issue or a chat (any mode)
39
+ wuica diff dot.s dot4.s -per 8,32 # before and after: speed-up, bottlenecks, ports, instructions changed
35
40
  clang -O3 -c dot.c && wuica dot.o -func dot # an object file (ELF or Mach-O, x86-64): no objdump needed
36
41
  wuica *.s -arch SKL,ZEN3 # several files in one run: one table (-files LIST for long lists)
37
42
  objdump -d dot.o | wuica # objdump output: the loop's real alignment from its address
43
+ perf annotate --stdio -s dot | wuica # a profile: the hottest loop, samples and source lines per instruction
38
44
  ```
39
45
 
46
+ On an Arm Mac, give clang `--target=x86_64-linux-gnu` (wuica analyzes x86-64 code; Apple's clang knows no
47
+ `-march=haswell` for arm64).
48
+
40
49
  - **Syntax.** Intel (noprefix) or AT&T is detected from the text (`%rdx`, `$8`, `(%rdi,%rcx,4)` are AT&T);
41
50
  stderr says which (`analyzed: loop .LBB0_9 (lines 28-47, in dot), AT&T syntax (detected)`). `-att` or `-intel`
42
51
  force one.
@@ -46,10 +55,35 @@ objdump -d dot.o | wuica # objdump output: the loop's real
46
55
  in the register's units: `rcx += 8 per iteration (index; ×4 bytes in [rdi+rcx*4])` is 8 elements of 4 bytes,
47
56
  `r13 += 64 per iteration (bytes; the base of [r13+0x20])` is 64 bytes (16 floats: `-per 16`), `(register step)` a
48
57
  counter no address uses.
49
- - **Which loop.** A whole function or file is analyzed at one loop: the deepest one (clang's
50
- `# =>This Inner Loop Header` notes count), among equals the first in the code. That can be a remainder loop: clang
51
- often emits it before the main loop, gcc after it. Stderr says what was picked and how many others there are;
52
- `-loops` lists them (index, label, function, lines, instructions, depth, auto), `-loop N` (0-based) or
58
+ - **Which loop.** A whole function or file is analyzed at one loop, by default (`auto`):
59
+ 1. only the innermost loops at the greatest depth (clang's `# =>This Inner Loop Header` notes count), and of those
60
+ only the ones in the function of the first of them: in a file with several functions the default stays in that
61
+ function (`-func` picks another); and not a remainder of another of them: a loop that continues the counter of an
62
+ earlier loop toward the same bound register after that loop stopped (the earlier loop's only exit is that compare,
63
+ and the counter comes from the register it compares), so it runs less than one of its steps: clang's scalar tail
64
+ of an unrolled loop, even when it has more instructions;
65
+ 2. among those, the one whose vector instructions use the widest registers (zmm, then ymm, then xmm, then none), then
66
+ the one with more vector instructions;
67
+ 3. then the one with more instructions, then the first in the text.
68
+
69
+ A vector instruction is an SSE/AVX/AVX-512 instruction that names an xmm, ymm or zmm register and works on several
70
+ elements. Scalar code uses xmm registers too, so these do not count: scalar floating point (a mnemonic, without its
71
+ `v`, that does not start with `p` and ends in `ss`, `sd` or `sh`: `addss`, `vfmadd231sd`, `movsd`, `cvtsi2sd`, and
72
+ `cvttsd2si`, but not the broadcasts), one element moved to or from a general-purpose register or memory (`movd`,
73
+ `movq`, `pinsr*`, `pextr*`, `insertps`, `extractps`, `movlpd`, `movhpd`), zero idioms (`vxorps xmm0, xmm0, xmm0`),
74
+ register-to-register copies (`movaps xmm1, xmm0`), and `andps`/`andnps`/`orps`/`xorps` (and `pd`) on xmm registers,
75
+ which compilers use for `fabs`, negation and `copysign` of scalars. So a vectorized loop is picked over its scalar
76
+ remainder or peel loop wherever the compiler put them, and a scalar float loop does not beat a larger integer loop for
77
+ touching xmm. The rule can still miss: a vectorized loop with a fixed, small trip count (merging sub-histograms)
78
+ beats the scalar main loop (a small constant trip count is not used against it: in an 8x8 transform the 8-iteration
79
+ loops are the work), a cleanup loop the compiler vectorized and unrolled with a counter of its own can beat a
80
+ hand-written intrinsics loop or a loop unrolled by hand, gcc's vectorized peel loop (`-O3`) can
81
+ beat the main loop, and clang's conversion of a `uint64_t` to `double` without AVX-512 (`vunpcklps`, `vsubpd`, `vshufpd` around a
82
+ `vaddsd`) makes a scalar loop look like a 128-bit vector loop. Without clang's notes (objdump output) a loop with
83
+ several back edges can be found as overlapping loops, so `-S` and objdump of it may differ. Stderr says what was
84
+ picked and how many others there are;
85
+ `-loops` lists them (index, label, function, lines, instructions, depth, auto; for a loop three or more deep in
86
+ clang's notes the list keeps the place it had when only the notes' first two lines were read), `-loop N` (0-based) or
53
87
  `-loop LABEL` picks one, `-func NAME` keeps one function's loops, `-loop whole` analyzes the whole text. A label
54
88
  that names loops in several functions (`1:` … `jnz 1b`) is an error that lists them; `-func` or the index picks one.
55
89
  - **Branches inside the loop.** uiCA runs the analyzed code straight through: in a loop with an if/else (or two back
@@ -60,9 +94,13 @@ objdump -d dot.o | wuica # objdump output: the loop's real
60
94
  `-raw FILE` (bare machine code).
61
95
  - **Object files.** An ELF or Mach-O x86-64 object, executable or shared object is read directly: its code as
62
96
  `llvm-objdump -d` prints it (decoded by the analyzer), so `wuica dot.o` and `objdump -d dot.o | wuica` pick the same
63
- loop and give the same numbers. `-func NAME` takes the symbol, without Mach-O's `_`, or a unique part of it; `-funcs`
64
- lists the functions; `-loops` gives the loops' addresses; `-ffunction-sections` objects work. An arm64 object (what a
65
- Mac compiles by default) says so and how to compile for x86-64 (`clang -arch x86_64 -c`, or
97
+ loop and give the same numbers. `-func NAME` takes the symbol, without Mach-O's `_`, or a unique part of it, and
98
+ analyzes that function alone (its loop, or its body if it has none); `-funcs` lists the functions; `-loops` gives the
99
+ loops' addresses; `-ffunction-sections` objects work. A name the file gives several functions (static functions of
100
+ different source files, gcc's `.cold` parts: any static executable has them) is listed as `NAME.0xADDR`, with its
101
+ address; `-func NAME` then lists them, and `-func NAME.0xADDR` picks one. Give a large executable a `-func`: with it
102
+ a 2.6 MB static executable takes 0.2 s, without it the whole file is read, which takes minutes and can fail. An
103
+ arm64 object (what a Mac compiles by default) says so and how to compile for x86-64 (`clang -arch x86_64 -c`, or
66
104
  `--target=x86_64-linux-gnu`); COFF is not supported yet (`llvm-objdump -d f.obj | wuica`).
67
105
  - **Several inputs** (`wuica a.s b.s c.o`, a glob, or `-files LIST` with one name per line, `-files -` from stdin):
68
106
  one process for all of them, the analyses spread over the threads. One CPU: a row per file (file, loop, TP,
@@ -80,6 +118,12 @@ objdump -d dot.o | wuica # objdump output: the loop's real
80
118
  - **What if** (`-whatif`): a table per CPU, in cycles per original iteration, or per element with `-per N`. With
81
119
  `-TPonly`, one `variant cycles` line per variant after the throughput (`acc2 16.00`; with `-per`, `acc2 16.00
82
120
  2.00`; with several CPUs, each line starts with the CPU). Estimates (`>=` in the table) are printed as plain numbers.
121
+ - **Markdown** (`-md`): GitHub-flavoured Markdown on stdout instead of the text report, for an issue, a review or a
122
+ chat: one CPU gives the headline (cycles per iteration, or per element with `-per N`; the CPU; the bottleneck or
123
+ `unknown · nearest X`), the limits, the next limit, the `not modelled` caveats, the critical chain, the uop table
124
+ (branch targets as the labels in the text) and the analyzed code; `-arch A,B,C` the CPU table; several files the
125
+ files × CPUs table (`-report`: each file's report); `-whatif` and `-loops` their tables. Columns are padded to read
126
+ in a monospace font. Not with `-json` or `-TPonly`; diagnostics and the exit status are as without it.
83
127
  - **JSON** (`-json`): one CPU gives the analyze response (`tp`, `bottlenecks`, `limits`, `rows`, `criticalPath`,
84
128
  `insights`, `loop`, `syntax`, and `perElement` / `whatIf` when asked); several give `{code, hex, loop, stderr,
85
129
  results: [{arch, tp, bottlenecks, limits, decodeErrors, perElement?, caveats?}]}`. The shapes are the same for one
@@ -90,7 +134,7 @@ objdump -d dot.o | wuica # objdump output: the loop's real
90
134
  {repository, commit, branch}, node}`: the uiCA commit whose data and model the package has.
91
135
  - **Syntax mistakes.** When the assembler fails, a `hint:` line names a line with the other syntax's operands (mixed
92
136
  AT&T and Intel lines, a `.intel_syntax` directive over AT&T code, `mov rdx, $8` in Intel code) and the flag to try.
93
- - No colours and no links, on a terminal or not.
137
+ - No colours and no links, on a terminal or not (`-md` is plain text too).
94
138
 
95
139
  ## What the numbers mean
96
140
 
@@ -107,7 +151,7 @@ Decoder or DSB. `limits` gives the throughput each component alone would allow.
107
151
  ## Library
108
152
 
109
153
  ```js
110
- import { createWuica } from 'wuica-cli';
154
+ import { createWuica, markdown } from 'wuica-cli';
111
155
 
112
156
  const w = await createWuica();
113
157
  const r = await w.analyze('SKL', { source: 'loop:\n add rax, [rsi]\n add rsi, 8\n dec rcx\n jnz loop\n' });
@@ -126,11 +170,13 @@ w.archs(); // [{id, name, year, p
126
170
  await w.assemble('vaddps zmm0, zmm1, zmm2'); // {code: 0, hex, length, bytes, stderr}
127
171
  w.summarize(r); // compact form (the MCP analyze result)
128
172
  w.insights(r); // the diagnosis alone (REST's insights)
173
+ markdown.report(r, { insights: w.insights(r) }); // Markdown, as wuica -md (also cpuTable, whatIf, loops, compare)
129
174
  ```
130
175
 
131
176
  Methods never throw for bad input: they resolve to a failure `{code, error, stderr}` (see the contract below).
132
- `createWuica({ dataDir })` reads the tables from another directory (`uarch.json` and `arch/<NAME>.json` or the binary
133
- `arch/<NAME>.bin`, plain or `.br`). `w.disassemble(bytes)` turns an object file into the text `analyze` reads. TypeScript declarations are included (`index.d.ts`).
177
+ `createWuica({ dataDir })` reads the tables from another directory (`uarch.json` and the binary `arch/<NAME>.bin`,
178
+ plain or `.br`; a uiCA export's `arch/<NAME>.json` is converted by `tools/encode-tables.sh IN_DIR OUT_DIR` of the
179
+ repository: the analyzer that ships reads no JSON tables). `w.disassemble(bytes)` turns an object file into the text `analyze` reads (`{func}`: of that function alone). TypeScript declarations are included (`index.d.ts`).
134
180
 
135
181
  `compare`, `analyzeMany(arch, requests)` and `compareMany(requests, {archs})` analyze on worker threads when the work
136
182
  is worth it: by default the number of threads comes from the work (the tables to load, the analyses and their
@@ -153,16 +199,18 @@ wuica loop.s # assembly file (syntax detected), uiCA's r
153
199
  wuica loop.s -arch ICL -TPonly # only the throughput
154
200
  cat loop.s | wuica -arch ZEN3 # stdin (or "-")
155
201
  wuica -att loop_att.s # AT&T syntax, forced (-intel forces Intel)
156
- wuica 4801d84801c349ffcf75f5 # a hex argument (as in the Rust CLI)
202
+ wuica 4801d84801c349ffcf75f5 # a hex argument (as in the repository's reference binary)
157
203
  wuica -hex code.txt # hex from a file or stdin ("48 01 d8", "0x48,0x01" are fine)
158
204
  wuica -raw code.bin # raw machine code
159
205
  wuica loop.s -arch all # throughput table for every microarchitecture (in parallel)
160
206
  wuica loop.s -arch SKL,ICL,ZEN3 # throughput table for these
161
207
  wuica -list # the microarchitectures
162
208
  wuica loop.s -json # the JSON result (the contract's analyze response)
209
+ wuica loop.s -arch SKL,ZEN3 -md # Markdown (an issue, a review, a chat); with -whatif, -loops, several files
163
210
  wuica psum.s -loop whole # the whole text, not the loop found in it (-loop auto, the default, or -loop N)
164
211
  wuica psum.s -loops # list the loops; -loop .LBB0_12 or -func psum to choose
165
212
  wuica psum.s -whatif -per 8 # what-if variants; cycles per element (8 elements per iteration)
213
+ wuica psum.s -variants align,acc4 # these variants only; align: the 64 alignment offsets (min, median, max)
166
214
  wuica dot.o -func dot # an object file (ELF or Mach-O x86-64); -funcs lists its functions
167
215
  wuica a.s b.s c.o -arch SKL,ZEN3 # several inputs: one table, a row per file and CPU
168
216
  wuica -files list.txt -TPonly # the names from a file (- for stdin): file<TAB>cycles lines
@@ -170,6 +218,7 @@ wuica *.s -json # {code, files: [{file, ...}]}, each entry
170
218
  wuica -examples # the built-in examples (the web page's set)
171
219
  wuica -example dot1 -whatif # one of them, as if it were the input file (every option applies)
172
220
  wuica -example dot1 -show > dot.s # its assembly, to save and edit
221
+ wuica diff a.s b.s -per 8 [-md|-json] # two blocks (files, - or hex): before and after
173
222
  wuica --version
174
223
  ```
175
224
 
@@ -190,13 +239,15 @@ newline-delimited JSON-RPC 2.0 with the `initialize` handshake of the protocol r
190
239
  (`isError`) that says what is wrong, an unknown tool a JSON-RPC error. The server ends with its stdin, and writes only
191
240
  protocol messages to stdout. `wuica mcp --help` prints the usage. The tool table itself (names, descriptions, JSON
192
241
  Schemas, handlers) is exported as `mcpTools(w)` from `wuica-cli/mcp`, with `callTool` and `validate`; the remote server
193
- (`server/`) serves the same table over HTTP. It has five tools:
242
+ (`server/`) serves the same table over HTTP. Its tools:
194
243
 
195
244
  | Tool | What it does |
196
245
  |---|---|
197
246
  | `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`) |
198
- | `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` |
247
+ | `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, ≈) |
248
+ | `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 |
199
249
  | `compare_archs` | one block on several or all microarchitectures: `tp` and bottlenecks per microarchitecture |
250
+ | `list_loops` | the loops of assembly text (what `loop` can pick): index, label, function, lines, instructions, depth, the one picked by default |
200
251
  | `list_archs` | ids, names, years, prototype flags |
201
252
  | `assemble` | assembly → hex bytes, or diagnostics with line/column |
202
253
 
@@ -313,9 +364,11 @@ text, and errors with structured stderr.
313
364
  | REST | Library | MCP tool |
314
365
  |---|---|---|
315
366
  | `GET /api/archs[?fields=id,name]` | `w.archs(fields?)` | `list_archs {fields?}` |
367
+ | — | `listLoops(source, {func?})` | `list_loops {source, func?}` |
316
368
  | `POST /api/analyze/<arch>` | `w.analyze(arch, request)` | `analyze {arch, ...request, format?}` |
317
- | `POST /api/compare` | `w.compare(request)` | `compare_archs {...request}` |
318
- | — | `whatIf((a, r) => w.analyze(a, r), arch, request, variants?, {assemble: (t) => w.assemble(t)})` | `what_if {arch, ...request, variants?}` |
369
+ | `POST /api/compare` | `w.compare({...request, archs?, per?})` | `compare_archs {...request, archs?, per?}` |
370
+ | `POST /api/what-if/<arch>` | `w.whatIf(arch, {...request, variants?, per?})` | `what_if {arch, ...request, variants?, per?}` |
371
+ | `POST /api/diff/<arch>` | `w.diff(arch, {a, b, options?, per?})` | `diff_blocks {arch, a, b, options?, per?}` |
319
372
  | `POST /api/assemble` | `w.assemble(source, syntax)` | `assemble {source, syntax?}` |
320
373
 
321
374
  ### Microarchitectures: `GET /api/archs`
@@ -336,7 +389,6 @@ Request:
336
389
  ```json
337
390
  {
338
391
  "source": "loop: add rax, rbx\n dec rcx\n jnz loop",
339
- "hex": "4801d8...",
340
392
  "syntax": "intel",
341
393
  "options": {
342
394
  "alignmentOffset": 0, "initPolicy": "diff", "simpleFrontEnd": false, "noMicroFusion": false,
@@ -345,17 +397,19 @@ Request:
345
397
  }
346
398
  ```
347
399
 
348
- - Give exactly one of `source` (assembly; the library also accepts `asm`) and `hex` (machine code; spaces, commas and
349
- `0x` are allowed).
400
+ - Give exactly one of `source` (assembly; the library also accepts `asm`) and `hex` (machine code, `"4801d8..."`;
401
+ spaces, commas and `0x` are allowed).
350
402
  - `source` is read as the web page reads pasted assembly. `loop` (optional) says what of it is analyzed:
351
403
  - `"auto"` (the default): a whole function (`gcc -S`, `clang -S`, `objdump -d` lines with addresses, with or
352
- without the bytes, Intel or AT&T) is analyzed at its deepest loop (clang's `Inner Loop Header` notes count;
353
- among equals the first in the code, which may be a remainder loop: clang often emits it first). A span that holds a `ret` or another function's label is not a loop (a tail
404
+ without the bytes, Intel or AT&T) is analyzed at its default loop ("Which loop" above: among the deepest innermost
405
+ loops, in the function of the first of them, the widest vector loop, then the one with the most vector instructions,
406
+ then the largest, then the first). A span that holds a `ret` or another function's label is not a loop (a tail
354
407
  call jumping back). A compiler's function without a loop (it has a function label, directives or a
355
408
  prologue/epilogue, and ends in `ret`) is analyzed at its body, without prologue, epilogue and `ret`; a bare snippet
356
409
  such as `add rax, 1` / `ret` is analyzed as typed. A text that is one loop already, or has region markers, is
357
410
  analyzed as it is.
358
- - `"whole"`: the whole text, never a pick; a number: that loop (0-based: deepest first, then in code order); any
411
+ - `"whole"`: the whole text, never a pick; a number: that loop (0-based, in the order `listLoops` and `-loops` list
412
+ them: the deepest innermost first, then in code order; the default need not be 0); any
359
413
  other string: the loop with that label (`".LBB0_12"`, `"0x10"`). `func` (optional) keeps one function's loops.
360
414
  - `syntax` is `"auto"` (the default: detected from the text), `"intel"` or `"att"`; the response's `syntax` says
361
415
  which was used.
@@ -389,23 +443,39 @@ Request:
389
443
  (`{hex, arch, minIterations}`); `options` takes precedence. The MCP tools accept only the nested form.
390
444
  - The source must be 64-bit code: `.code16`, `.code16gcc` and `.code32` are an error (code 1), since the analyzer
391
445
  only models 64-bit mode. `assemble` alone accepts them.
392
- - `loop` exists in the library, REST (`/api/analyze`, `/api/compare`), the MCP tools `analyze`, `what_if` and
393
- `compare_archs`, and the package's CLI (`wuica -loop auto|whole|N`). The native CLI (`crates/wuica-cli`) reads
394
- machine code only (hex or `-raw`), so it has no `-loop`.
446
+ - `loop` exists in the library, REST (`/api/analyze`, `/api/compare`, `/api/what-if`, each block of `/api/diff`), the MCP
447
+ tools `analyze`, `what_if`, `compare_archs` and `diff_blocks` (per block), and the package's CLI (`wuica -loop
448
+ auto|whole|N`, also for `wuica diff`). The reference/test binary (`crates/wuica-cli`) reads
449
+ 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`
450
+ and `-loops` give them, without `auto`), in the analyze, summary and compare results.
451
+ - Assembly input: each instruction row (and `instructions[]`, `insights.chain[]`, `insights.hot.instructions[]`) has
452
+ `line`, its 1-based line in the text, and `loc` ("file.c:12") when the text has `.file`/`.loc` directives: what the
453
+ loop finder and the assembler record, not a match of the text. Machine code has neither.
454
+ - Profiles are read as they are: `objdump -dS` (or `-S`) output gives each instruction `source`, the interleaved source
455
+ line in force; `perf annotate --stdio` output gives `samples` (its percent of all the samples of the output: each
456
+ symbol's percentages weighted by its sample count; if a header has no count, each symbol's own percentages, said in a
457
+ note) and `source`, and when the text has several loops, the one whose
458
+ own instructions (not those of a loop nested in it) have the most samples is analyzed (`loop` still picks another).
459
+ `perf annotate --stdio2` output has no addresses: it is refused with a note to use `--stdio`. A text with `.rept`,
460
+ `.irp`, `.irpc`, `.macro` or `.if` has no `line` (its lines are not its instructions one to one) and is analyzed whole,
461
+ with a note; nor has code with a data directive (`.byte`, `.fill`, ...) among the analyzed instructions. A prefix alone
462
+ on its line (`lock`, then `add [rdi], eax`) is part of the next instruction.
395
463
 
396
464
  ### Option ranges per interface
397
465
 
398
- All interfaces run the same analyzer, but they accept different ranges for the numeric options. A value outside the
399
- range is refused (code 1, REST 400; the MCP tools' schema rejects it as invalid arguments), except in the web page,
400
- which clamps it into its range.
466
+ The numeric options have the same range in the library, the CLI, the MCP tools and the REST API: any integer up to
467
+ 2^53 - 1 in magnitude (`alignmentOffset`: negative values and values above 63 are read modulo 64; the reference
468
+ binary `crates/wuica-cli` refuses beyond ±2^62). Another value is refused (code 1, REST 400; the MCP tools' schema rejects
469
+ it).
470
+ Everywhere, a block of more than 250,000 uops per iteration is refused (a work budget, code 3), and very large values run
471
+ out of memory (code 3). The differences:
401
472
 
402
- | Interface | `alignmentOffset` | `minIterations` | `minCycles` | Other limits |
403
- |---|---|---|---|---|
404
- | 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) |
405
- | MCP tools of `wuica mcp` (stdio) | 0–63 | 1–100000 | 1–1000000 | |
406
- | 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 |
407
- | remote MCP (`server/`, `/mcp`) | 0–63 | 1–1000 | 1–20000 | as REST |
408
- | web page | 0–63 | 1–10000 | 1–100000 | at most 1 MiB of machine code (assembled or as hex) |
473
+ | Interface | Limits |
474
+ |---|---|
475
+ | 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 |
476
+ | MCP tools (stdio and remote) | `minIterations` 1–100000, `minCycles` 1–1000000 (an agent should not start a 3 GB simulation by accident) |
477
+ | 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 |
478
+ | web page | clamps `alignmentOffset` to 0–63, `minIterations` to 1–10000, `minCycles` to 1–100000; at most 1 MiB of machine code |
409
479
 
410
480
  Microarchitecture ids are accepted the same way everywhere: exactly, or case-insensitively with `-` optional (`adlp`,
411
481
  `adl-p` → `ADL-P`). Hex may contain spaces, commas and `0x` / `\x` prefixes everywhere.
@@ -432,11 +502,20 @@ Response (JSON), on success:
432
502
  The fields from `arch` to `trace` are the analysis response of the WebAssembly module (`docs/WASM-API.md` in the wuica
433
503
  repository: `rows[].values[i]` belongs to `columns[i]`, and `notes` is `M` macro-fused, `J` JCC erratum or `X`
434
504
  unsupported). `hex` is present when `source` was given and holds the assembled bytes. `stderr` holds the assembler's
435
- 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
505
+ warnings, the notes on exits taken as not taken, and the warning "N position(s) could not be decoded". `unsupported` is
506
+ present only when the CPU cannot run the code: positions its decoder skipped (AVX-512 on SKL), or an instruction of an
507
+ extension it lacks that its decoder accepts (AVX-512 on ZEN3, by the instruction's encoding). It holds the reason:
508
+ `"needs AVX-512"` when the extension is known (from the instruction, or from the analyzed assembly text without its
509
+ comments), else `"12 undecodable"`; `tp` is then the reference's number, which leaves that code out, and the text, the
510
+ 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
511
+ its instructions are not in its tables (the note X: x87 tbyte loads, syscall, CLWB on ICX): their count; the result
512
+ stands, without their cost. compare's rows have both. `insights` (REST only; the library's `analyze()` result
436
513
  does not have it, `w.insights(r)` computes it) is the diagnosis described under the compact form below, with `portSet`
437
514
  and `issueSlots` when `options.details` is true.
438
515
 
439
516
  **Plain text** (CE's `Accept: text/plain`): the response is `text` (uiCA's report), or the `stderr` lines on failure.
517
+
518
+ **Markdown** (`Accept: text/markdown`, analyze, compare, what-if and diff): what `wuica -md` prints (`markdown.report`, `markdown.cpuTable`), with the same status codes.
440
519
  In the library this is `r.text`; the MCP tool takes `format: "text"`.
441
520
 
442
521
  **Compact form** (the MCP `analyze` JSON, `w.summarize(r)`): `{code, arch, name, year, prototype, tp, unit, mode,
@@ -489,7 +568,7 @@ Every call can fail like a compiler run in Compiler Explorer, with a non-zero `c
489
568
 
490
569
  ### Compare: `POST /api/compare`
491
570
 
492
- 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:
571
+ 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:
493
572
 
494
573
  ```json
495
574
  {
@@ -505,13 +584,33 @@ The request is the same as for analyze, plus an optional `archs` (ids; missing o
505
584
  The top-level `code` is non-zero only if the request or the assembly fails. A failure on one microarchitecture is
506
585
  reported in its row.
507
586
 
587
+ ### What-if: `POST /api/what-if/<arch>`
588
+
589
+ The request is analyze's plus `variants` (ids, default all: `unroll2`, `unroll4`, `unroll8`, `acc2`, `acc3`, `acc4`,
590
+ `acc8`, `simpleFrontEnd`, `noMacroFusion`, `noMicroFusion`, `nochain`; also `align`, only when asked for: the block at
591
+ each of the 64 alignment offsets, 64 analyses, `tp` the median and `alignment` {min, median, max, best, worst, spread,
592
+ 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
593
+ `tp` per original iteration, `delta`, `speedup`, or `error`; `accumulators.best`. `text/plain` gives the CLI's table,
594
+ `text/markdown` the Markdown one. Each variant is one analysis (`nochain` none, `align` 64), and the request costs tokens
595
+ in proportion (the rate limit above).
596
+
597
+ ### Diff: `POST /api/diff/<arch>`
598
+
599
+ `{a: block, b: block, options?, per?}`: each block as analyze's request; `options` for both; `per` elements per iteration
600
+ (N for both, or [A, B]). The response (`DiffResult` in index.d.ts; `wuica diff -json`): `a` and `b` (`tp`,
601
+ `bottlenecks`, `perElement`), `delta`, `speedup`, `verdict`, `perElement`, `bottlenecks` (`gone`, `new`), `limits`,
602
+ `ports` (uops per iteration before and after) and `instructions` (`counts`; `changes`: `changed`, `modified`, `added`,
603
+ `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
604
+ CLI's text, `text/markdown` the page's A–B tables.
605
+
508
606
  ### Assemble: `POST /api/assemble`
509
607
 
510
608
  Request: `{"source": "...", "syntax": "intel"}`. The whole text is assembled as it is (no loop finding, no region
511
609
  markers; `;` comments as above). Response: `{"code": 0, "hex": "4801d8", "length": 3, "stderr": []}`;
512
610
  the library also returns `bytes` (a `Uint8Array`). On failure: `{code: 2, error, stderr}` as above. The assembler is
513
611
  LLVM 22.1.2's (the same bytes as `llvm-mc`). Only `.text` is returned. `.include`/`.incbin` always fail. GNU as's
514
- `{load}`/`{store}` hints, which LLVM rejects, are removed at the start of a line.
612
+ `{load}`/`{store}` hints, which LLVM rejects, are removed at the start of a line, clang 23's `.prefalign` is read as
613
+ `.p2align`, and the line table (`.loc`, numbered `.file`) is not assembled (gcc 11+ `-g` output assembles).
515
614
 
516
615
  ## Building from the repository
517
616
 
@@ -524,7 +623,8 @@ npm pack # wuica-cli-<version>.tgz
524
623
  `build.sh` uses `target/wasm32-unknown-unknown/release/wuica_wasm.wasm` (it runs `./build-wasm.sh` if the file is
525
624
  missing), `assembler/dist/wuica_asm.wasm` and `data/`. The instruction tables are shipped in a binary form
526
625
  (`dist/data/arch/<NAME>.bin.br`, written from `data/arch/*.json` by `tools/encode-tables.sh`; 6.4 MB instead of
527
- 14.6 MB, and loaded about 40% faster); `createWuica({ dataDir })` also reads JSON tables. `dist/manifest.json` records
626
+ 14.6 MB, and loaded about 40% faster); the analyzer module is built without the JSON table loader (the Cargo feature
627
+ `json-tables` of `crates/wuica`, which the native tools and tests use). `dist/manifest.json` records
528
628
  the size and SHA-256 of each
529
629
  uncompressed file.
530
630
 
Binary file
Binary file
Binary file
Binary file
@@ -1,33 +1,33 @@
1
1
  {
2
2
  "uiCA": {
3
3
  "repository": "https://github.com/jtl06/uiCA",
4
- "commit": "640e40e",
5
- "branch": "improve-r9"
4
+ "commit": "5429430",
5
+ "branch": "improve-r11"
6
6
  },
7
7
  "tables": {
8
8
  "format": "WUICATBL 1",
9
- "sha256": "d1dce7edf3a6e0af263c94ed8712fb11ee8f4572c8685057201d2309e5e24631"
9
+ "sha256": "75f55cc6e568603e1c1f73cff43b1b5ce9d1e4e2af42a18d6b60edc07fa72ce3"
10
10
  },
11
11
  "files": {
12
12
  "wuica_wasm.wasm": {
13
- "size": 3111653,
14
- "sha256": "1a004180a1c1a79a02b039a4737c9c457ceacf507d735c6955046b071f28e818"
13
+ "size": 3104338,
14
+ "sha256": "288d6ff11eb6c80372964644596b6e92c1cffe3cfd064face5184ac50b8de729"
15
15
  },
16
16
  "wuica_asm.wasm": {
17
17
  "size": 3802001,
18
18
  "sha256": "ee66811d0671cdea73176a3670f82816dcbb3cbb1fed13cd7dc2acbb69cb627d"
19
19
  },
20
20
  "data/uarch.json": {
21
- "size": 51318,
22
- "sha256": "f543714ba2927986671f1de045a6162296ce860c5d34a086cc4c72d6c828e7a1"
21
+ "size": 60681,
22
+ "sha256": "71e003392f4ca0cffeb884f6631e13727cfef764c9aa9e3c1c65965990341b8b"
23
23
  },
24
24
  "data/arch/ADL-P.bin": {
25
- "size": 819776,
26
- "sha256": "3a6623b7086ada2689d068745929537046655b444641885e09154221b5edac87",
25
+ "size": 819806,
26
+ "sha256": "47f6c9e689e0635bf802b1e0d8cf9beedf3387b32e803d9d3c139ba9390f014f",
27
27
  "source": {
28
28
  "file": "data/arch/ADL-P.json",
29
- "size": 1771348,
30
- "sha256": "1632dd7f57d26efa6e465c25c72e38523302c906f8db403af6ba1c432b1e1ccb"
29
+ "size": 1771497,
30
+ "sha256": "749e4a3e3453375083f35d90f2a772f36e7fb86709dbf11338c09fab1c537285"
31
31
  }
32
32
  },
33
33
  "data/arch/BDW.bin": {
@@ -76,12 +76,12 @@
76
76
  }
77
77
  },
78
78
  "data/arch/ICX.bin": {
79
- "size": 698165,
80
- "sha256": "b01057f584a837604ad9c08c4eeae45e09161dce826234d5f010e807a0a18b21",
79
+ "size": 710771,
80
+ "sha256": "10f3524a3e2cc00340fcbe2c6191e3931bf5e8e51612b5032ec65761c46ba167",
81
81
  "source": {
82
82
  "file": "data/arch/ICX.json",
83
- "size": 1495406,
84
- "sha256": "dd45538e22584305d5186d78673b3d4f8bc83fd2d0c0e600ec98540a6d0f2eff"
83
+ "size": 1565345,
84
+ "sha256": "69a5145d629da84f4319eb3eafe9e82827e618e6647b4b751439d02f20f4db41"
85
85
  }
86
86
  },
87
87
  "data/arch/IVB.bin": {
@@ -148,12 +148,12 @@
148
148
  }
149
149
  },
150
150
  "data/arch/ZEN3.bin": {
151
- "size": 198979,
152
- "sha256": "525e66430a3ddc9f0c88d914f32083fbdc0c32f17233dd972548286b4d43b7c7",
151
+ "size": 202810,
152
+ "sha256": "a1fd9019fc464af020e04892d8d782f92ad0688a061d62a5d62899c62d05aecd",
153
153
  "source": {
154
154
  "file": "data/arch/ZEN3.json",
155
- "size": 527963,
156
- "sha256": "72097d0e154b17ef71c12547946c2750f388cdae479b9af99ed5633959c9059a"
155
+ "size": 553459,
156
+ "sha256": "41a147bba4a7419cb5552d457cde022b0130bbf89f4c78e9b9a2725857dabcff"
157
157
  }
158
158
  }
159
159
  }
Binary file