xqvm 0.2.1

X-Quadratic Virtual Machine — bytecode interpreter for the XQuad Toolchain
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# XQVM Opcode Table — machine-readable canonical source
#
# This file is the single source of truth for the XQVM opcode set. Both the
# Rust production implementation (xqvm/src/bytecode/types/table.rs,
# validated at compile time by xqvm/build.rs) and the Python reference
# implementation (xqvm_py/opcodes.py, validated by
# scripts/check-opcode-parity.py) are checked against this table.
#
# Schema per entry:
#   code:      u8 wire encoding (hex).
#   mnemonic:  uppercase assembly name.
#   variant:   PascalCase Rust enum identifier.
#   category:  taxonomic bucket (matches spec/xqvm/SPEC.md sections).
#   operands:  list of {name, type, width} objects. Empty list = no operands.
#              type ∈ {register, label, immediate}; width = byte count.
#   stack_pop: number of stack slots consumed.
#   stack_push: number of stack slots produced.
#   doc:       single-sentence description (used by gen-bytecode-docs.py).
#
# Reserved wire bytes (rejected by the decoder as illegal): 0x0D, 0x19, 0x35.

version: 1

opcodes:

  # ------------------------------------------------------------------------
  # Control Flow (0x00-0x09)
  # ------------------------------------------------------------------------

  - code: 0x00
    mnemonic: TARGET
    variant: Target
    category: control-flow
    operands: []
    stack_pop: 0
    stack_push: 0
    doc: "Mark a valid jump destination."

  - code: 0x01
    mnemonic: JUMP1
    variant: Jump1
    category: control-flow
    operands:
      - {name: label, type: label, width: 1}
    stack_pop: 0
    stack_push: 0
    doc: "Unconditionally jump to a basic block by u8 label index (narrow form)."

  - code: 0x02
    mnemonic: JUMPI1
    variant: JumpI1
    category: control-flow
    operands:
      - {name: label, type: label, width: 1}
    stack_pop: 1
    stack_push: 0
    doc: "Jump to a basic block by u8 label index if the top of the stack is non-zero (narrow form)."

  - code: 0x03
    mnemonic: JUMP2
    variant: Jump2
    category: control-flow
    operands:
      - {name: label, type: label, width: 2}
    stack_pop: 0
    stack_push: 0
    doc: "Unconditionally jump to a basic block by u16 label index (wide form)."

  - code: 0x04
    mnemonic: JUMPI2
    variant: JumpI2
    category: control-flow
    operands:
      - {name: label, type: label, width: 2}
    stack_pop: 1
    stack_push: 0
    doc: "Jump to a basic block by u16 label index if the top of the stack is non-zero (wide form)."

  - code: 0x05
    mnemonic: LIDX
    variant: Lidx
    category: control-flow
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 0
    stack_push: 0
    doc: "Copy the current loop index (offset-adjusted) into a register."

  - code: 0x06
    mnemonic: LVAL
    variant: LVal
    category: control-flow
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 0
    stack_push: 0
    doc: "Copy the current loop value into a register."

  - code: 0x07
    mnemonic: NEXT
    variant: Next
    category: control-flow
    operands: []
    stack_pop: 0
    stack_push: 0
    doc: "Advance the loop index; jump back or exit the current loop."

  - code: 0x08
    mnemonic: RANGE
    variant: Range
    category: control-flow
    operands: []
    stack_pop: 2
    stack_push: 0
    doc: "Start a range loop over [start, start + count)."

  - code: 0x09
    mnemonic: ITER
    variant: Iter
    category: control-flow
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 2
    stack_push: 0
    doc: "Start a vec iteration over a slice of a register's vec."

  # ------------------------------------------------------------------------
  # Register I/O (0x0A-0x0F, gap at 0x0D)
  # ------------------------------------------------------------------------

  - code: 0x0A
    mnemonic: LOAD
    variant: Load
    category: register-io
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 0
    stack_push: 1
    doc: "Push the value of an int register onto the stack."

  - code: 0x0B
    mnemonic: STOW
    variant: Stow
    category: register-io
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 1
    stack_push: 0
    doc: "Pop the top of the stack into an int register."

  - code: 0x0C
    mnemonic: DROP
    variant: Drop
    category: register-io
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 0
    stack_push: 0
    doc: "Reset a register to Int(0)."

  - code: 0x0E
    mnemonic: INPUT
    variant: Input
    category: register-io
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 1
    stack_push: 0
    doc: "Pop a calldata slot index and load that slot into a register."

  - code: 0x0F
    mnemonic: OUTPUT
    variant: Output
    category: register-io
    operands:
      - {name: reg, type: register, width: 1}
    stack_pop: 1
    stack_push: 0
    doc: "Pop an output slot index and write the register to it."

  # ------------------------------------------------------------------------
  # Stack Manipulation (0x10-0x1C, gap at 0x19)
  # ------------------------------------------------------------------------

  - code: 0x10
    mnemonic: POP
    variant: Pop
    category: stack
    operands: []
    stack_pop: 1
    stack_push: 0
    doc: "Discard the top of the stack."

  - code: 0x11
    mnemonic: PUSH1
    variant: Push1
    category: stack
    operands:
      - {name: val, type: immediate, width: 1}
    stack_pop: 0
    stack_push: 1
    doc: "Push a 1-byte big-endian signed constant, sign-extended to i64."

  - code: 0x12
    mnemonic: PUSH2
    variant: Push2
    category: stack
    operands:
      - {name: val, type: immediate, width: 2}
    stack_pop: 0
    stack_push: 1
    doc: "Push a 2-byte big-endian signed constant, sign-extended to i64."

  - code: 0x13
    mnemonic: PUSH3
    variant: Push3
    category: stack
    operands:
      - {name: val, type: immediate, width: 3}
    stack_pop: 0
    stack_push: 1
    doc: "Push a 3-byte big-endian signed constant, sign-extended to i64."

  - code: 0x14
    mnemonic: PUSH4
    variant: Push4
    category: stack
    operands:
      - {name: val, type: immediate, width: 4}
    stack_pop: 0
    stack_push: 1
    doc: "Push a 4-byte big-endian signed constant, sign-extended to i64."

  - code: 0x15
    mnemonic: PUSH5
    variant: Push5
    category: stack
    operands:
      - {name: val, type: immediate, width: 5}
    stack_pop: 0
    stack_push: 1
    doc: "Push a 5-byte big-endian signed constant, sign-extended to i64."

  - code: 0x16
    mnemonic: PUSH6
    variant: Push6
    category: stack
    operands:
      - {name: val, type: immediate, width: 6}
    stack_pop: 0
    stack_push: 1
    doc: "Push a 6-byte big-endian signed constant, sign-extended to i64."

  - code: 0x17
    mnemonic: PUSH7
    variant: Push7
    category: stack
    operands:
      - {name: val, type: immediate, width: 7}
    stack_pop: 0
    stack_push: 1
    doc: "Push a 7-byte big-endian signed constant, sign-extended to i64."

  - code: 0x18
    mnemonic: PUSH8
    variant: Push8
    category: stack
    operands:
      - {name: val, type: immediate, width: 8}
    stack_pop: 0
    stack_push: 1
    doc: "Push a full 8-byte big-endian signed constant (i64)."

  - code: 0x1A
    mnemonic: SCLR
    variant: Sclr
    category: stack
    operands: []
    stack_pop: 0
    stack_push: 0
    doc: "Clear the entire value stack."

  - code: 0x1B
    mnemonic: SWAP
    variant: Swap
    category: stack
    operands: []
    stack_pop: 2
    stack_push: 2
    doc: "Swap the top two stack elements."

  - code: 0x1C
    mnemonic: COPY
    variant: Copy
    category: stack
    operands: []
    stack_pop: 1
    stack_push: 2
    doc: "Duplicate the top of the stack."

  # ------------------------------------------------------------------------
  # Arithmetic (0x20-0x2B)
  # ------------------------------------------------------------------------

  - {code: 0x20, mnemonic: ADD, variant: Add, category: arithmetic, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a + b."}
  - {code: 0x21, mnemonic: SUB, variant: Sub, category: arithmetic, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a - b."}
  - {code: 0x22, mnemonic: MUL, variant: Mul, category: arithmetic, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a * b."}
  - {code: 0x23, mnemonic: DIV, variant: Div, category: arithmetic, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a / b (truncating integer division)."}
  - {code: 0x24, mnemonic: MOD, variant: Modulo, category: arithmetic, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a % b."}
  - {code: 0x25, mnemonic: SQR, variant: Sqr, category: arithmetic, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push a * a."}
  - {code: 0x26, mnemonic: ABS, variant: Abs, category: arithmetic, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push |a|."}
  - {code: 0x27, mnemonic: NEG, variant: Neg, category: arithmetic, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push -a."}
  - {code: 0x28, mnemonic: MIN, variant: Min, category: arithmetic, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push min(a, b)."}
  - {code: 0x29, mnemonic: MAX, variant: Max, category: arithmetic, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push max(a, b)."}
  - {code: 0x2A, mnemonic: INC, variant: Inc, category: arithmetic, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push a + 1."}
  - {code: 0x2B, mnemonic: DEC, variant: Dec, category: arithmetic, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push a - 1."}
  - {code: 0x2C, mnemonic: BITLEN, variant: BitLen, category: arithmetic, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push floor(log2(a))+1. If a <= 0, push 0."}

  # ------------------------------------------------------------------------
  # Comparison (0x30-0x34) — result is 1 if true, 0 if false
  # ------------------------------------------------------------------------

  - {code: 0x30, mnemonic: EQ,  variant: Eq,  category: comparison, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if a == b, else 0."}
  - {code: 0x31, mnemonic: LT,  variant: Lt,  category: comparison, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if a < b, else 0."}
  - {code: 0x32, mnemonic: GT,  variant: Gt,  category: comparison, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if a > b, else 0."}
  - {code: 0x33, mnemonic: LTE, variant: Lte, category: comparison, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if a <= b, else 0."}
  - {code: 0x34, mnemonic: GTE, variant: Gte, category: comparison, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if a >= b, else 0."}

  # ------------------------------------------------------------------------
  # Logical Boolean (0x36-0x39, gap at 0x35)
  # ------------------------------------------------------------------------

  - {code: 0x36, mnemonic: NOT, variant: Not, category: logical, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push 1 if a == 0, else 0."}
  - {code: 0x37, mnemonic: AND, variant: And, category: logical, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if both are non-zero, else 0."}
  - {code: 0x38, mnemonic: OR,  variant: Or,  category: logical, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if either is non-zero, else 0."}
  - {code: 0x39, mnemonic: XOR, variant: Xor, category: logical, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push 1 if exactly one is non-zero, else 0."}

  # ------------------------------------------------------------------------
  # Bitwise (0x3A-0x3F)
  # ------------------------------------------------------------------------

  - {code: 0x3A, mnemonic: BAND, variant: BAnd, category: bitwise, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a & b."}
  - {code: 0x3B, mnemonic: BOR,  variant: BOr,  category: bitwise, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a | b."}
  - {code: 0x3C, mnemonic: BXOR, variant: BXor, category: bitwise, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a ^ b."}
  - {code: 0x3D, mnemonic: BNOT, variant: BNot, category: bitwise, operands: [], stack_pop: 1, stack_push: 1, doc: "Pop a; push ~a."}
  - {code: 0x3E, mnemonic: SHL,  variant: Shl,  category: bitwise, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a << b."}
  - {code: 0x3F, mnemonic: SHR,  variant: Shr,  category: bitwise, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop b and a; push a >> b (arithmetic right shift, sign-preserving)."}

  # ------------------------------------------------------------------------
  # Allocators — Models (0x40-0x45)
  # ------------------------------------------------------------------------

  - code: 0x40
    mnemonic: BQMX
    variant: Bqmx
    category: allocators
    operands: [{name: reg, type: register, width: 1}]
    stack_pop: 1
    stack_push: 0
    doc: "Pop size; allocate a binary QUBO model ([0, 1] domain) into a register."

  - code: 0x41
    mnemonic: SQMX
    variant: Sqmx
    category: allocators
    operands: [{name: reg, type: register, width: 1}]
    stack_pop: 1
    stack_push: 0
    doc: "Pop size; allocate a spin Ising model ([-1, 1] domain) into a register."

  - code: 0x42
    mnemonic: XQMX
    variant: Xqmx
    category: allocators
    operands: [{name: reg, type: register, width: 1}]
    stack_pop: 2
    stack_push: 0
    doc: "Pop k then size; allocate a discrete model with signed centered domain [-k, k-1] into a register. Errors when k < 2."

  - code: 0x43
    mnemonic: BSMX
    variant: Bsmx
    category: allocators
    operands: [{name: reg, type: register, width: 1}]
    stack_pop: 1
    stack_push: 0
    doc: "Pop size; allocate a binary sample ([0, 1] domain) into a register."

  - code: 0x44
    mnemonic: SSMX
    variant: Ssmx
    category: allocators
    operands: [{name: reg, type: register, width: 1}]
    stack_pop: 1
    stack_push: 0
    doc: "Pop size; allocate a spin sample ([-1, 1] domain) into a register."

  - code: 0x45
    mnemonic: XSMX
    variant: Xsmx
    category: allocators
    operands: [{name: reg, type: register, width: 1}]
    stack_pop: 2
    stack_push: 0
    doc: "Pop k then size; allocate a discrete sample with signed centered domain [-k, k-1] into a register. Errors when k < 2."

  # ------------------------------------------------------------------------
  # Allocators — Vec (0x4A-0x4C)
  # ------------------------------------------------------------------------

  - {code: 0x4A, mnemonic: VEC,  variant: Vec,  category: allocators, operands: [{name: reg, type: register, width: 1}], stack_pop: 0, stack_push: 0, doc: "Create an empty vec (element type inferred on first push) in a register."}
  - {code: 0x4B, mnemonic: VECI, variant: VecI, category: allocators, operands: [{name: reg, type: register, width: 1}], stack_pop: 0, stack_push: 0, doc: "Create an empty `vec<int>` in a register."}
  - {code: 0x4C, mnemonic: VECX, variant: VecX, category: allocators, operands: [{name: reg, type: register, width: 1}], stack_pop: 0, stack_push: 0, doc: "Create an empty `vec<xqmx>` in a register."}

  # ------------------------------------------------------------------------
  # Vector Access (0x50-0x53)
  # ------------------------------------------------------------------------

  - {code: 0x50, mnemonic: VECPUSH, variant: VecPush, category: vector-ops, operands: [{name: reg, type: register, width: 1}], stack_pop: 1, stack_push: 0, doc: "Pop a value; append it to the register's vec."}
  - {code: 0x51, mnemonic: VECGET,  variant: VecGet,  category: vector-ops, operands: [{name: reg, type: register, width: 1}], stack_pop: 1, stack_push: 1, doc: "Pop index; push `vec[index]` from the register's vec."}
  - {code: 0x52, mnemonic: VECSET,  variant: VecSet,  category: vector-ops, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 0, doc: "Pop value and index; set `vec[index]` in the register's vec."}
  - {code: 0x53, mnemonic: VECLEN,  variant: VecLen,  category: vector-ops, operands: [{name: reg, type: register, width: 1}], stack_pop: 0, stack_push: 1, doc: "Push the length of the register's vec onto the stack."}

  - code: 0x54
    mnemonic: SLACK
    variant: Slack
    category: vector-ops
    operands:
      - {name: indices, type: register, width: 1}
      - {name: coeffs, type: register, width: 1}
    stack_pop: 2
    stack_push: 0
    doc: "Pop capacity and start_index; append slack variable indices and power-of-two coefficients to two register vecs."

  # ------------------------------------------------------------------------
  # Index Math (0x5A-0x5B)
  # ------------------------------------------------------------------------

  - {code: 0x5A, mnemonic: IDXGRID, variant: IdxGrid, category: index-math, operands: [], stack_pop: 3, stack_push: 1, doc: "Pop cols, col, row; push the flat grid index row * cols + col."}
  - {code: 0x5B, mnemonic: IDXTRIU, variant: IdxTriu, category: index-math, operands: [], stack_pop: 2, stack_push: 1, doc: "Pop j and i (i <= j); push the upper-triangular index for (i, j)."}

  # ------------------------------------------------------------------------
  # XQMX Coefficient Access (0x60-0x65)
  # ------------------------------------------------------------------------

  - {code: 0x60, mnemonic: GETLINE, variant: GetLine, category: xqmx-access, operands: [{name: reg, type: register, width: 1}], stack_pop: 1, stack_push: 1, doc: "Pop i; push `linear[i]` from the register's model (0 if absent)."}
  - {code: 0x61, mnemonic: SETLINE, variant: SetLine, category: xqmx-access, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 0, doc: "Pop value and i; set `linear[i]` in the register's model."}
  - {code: 0x62, mnemonic: ADDLINE, variant: AddLine, category: xqmx-access, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 0, doc: "Pop delta and i; add delta to `linear[i]` in the register's model."}
  - {code: 0x63, mnemonic: GETQUAD, variant: GetQuad, category: xqmx-access, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 1, doc: "Pop j and i; push `quadratic[i, j]` from the register's model (0 if absent)."}
  - {code: 0x64, mnemonic: SETQUAD, variant: SetQuad, category: xqmx-access, operands: [{name: reg, type: register, width: 1}], stack_pop: 3, stack_push: 0, doc: "Pop value, j, and i; set `quadratic[i, j]` in the register's model."}
  - {code: 0x65, mnemonic: ADDQUAD, variant: AddQuad, category: xqmx-access, operands: [{name: reg, type: register, width: 1}], stack_pop: 3, stack_push: 0, doc: "Pop delta, j, and i; add delta to `quadratic[i, j]` in the register's model."}

  # ------------------------------------------------------------------------
  # XQMX Grid (0x66-0x6A)
  # ------------------------------------------------------------------------

  - {code: 0x66, mnemonic: RESIZE,  variant: Resize,  category: xqmx-grid, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 0, doc: "Pop cols and rows; set the grid dimensions of the register's model."}
  - {code: 0x67, mnemonic: ROWFIND, variant: RowFind, category: xqmx-grid, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 1, doc: "Pop value and row; push the first column where the value matches, or -1."}
  - {code: 0x68, mnemonic: COLFIND, variant: ColFind, category: xqmx-grid, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 1, doc: "Pop value and col; push the first row where the value matches, or -1."}
  - {code: 0x69, mnemonic: ROWSUM,  variant: RowSum,  category: xqmx-grid, operands: [{name: reg, type: register, width: 1}], stack_pop: 1, stack_push: 1, doc: "Pop row; push the sum of all linear values in that grid row."}
  - {code: 0x6A, mnemonic: COLSUM,  variant: ColSum,  category: xqmx-grid, operands: [{name: reg, type: register, width: 1}], stack_pop: 1, stack_push: 1, doc: "Pop col; push the sum of all linear values in that grid column."}

  # ------------------------------------------------------------------------
  # XQMX High-Level Constraints (0x70-0x73, 0x7F)
  # ------------------------------------------------------------------------

  - {code: 0x70, mnemonic: ONEHOTR, variant: OneHotR, category: xqmx-high-level, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 0, doc: "Pop penalty and row; add a one-hot constraint over the grid row."}
  - {code: 0x71, mnemonic: ONEHOTC, variant: OneHotC, category: xqmx-high-level, operands: [{name: reg, type: register, width: 1}], stack_pop: 2, stack_push: 0, doc: "Pop penalty and col; add a one-hot constraint over the grid column."}
  - {code: 0x72, mnemonic: EXCLUDE, variant: Exclude, category: xqmx-high-level, operands: [{name: reg, type: register, width: 1}], stack_pop: 3, stack_push: 0, doc: "Pop penalty, j, and i; add a mutual-exclusion constraint between variables i and j."}
  - {code: 0x73, mnemonic: IMPLIES, variant: Implies, category: xqmx-high-level, operands: [{name: reg, type: register, width: 1}], stack_pop: 3, stack_push: 0, doc: "Pop penalty, j, and i; add an implication constraint from variable i to variable j."}

  - code: 0x74
    mnemonic: EQUALITY
    variant: Equality
    category: xqmx-high-level
    operands:
      - {name: model, type: register, width: 1}
      - {name: indices, type: register, width: 1}
      - {name: coeffs, type: register, width: 1}
    stack_pop: 2
    stack_push: 0
    doc: "Pop penalty and target; expand weighted equality constraint into QUBO terms on a model."

  - code: 0x75
    mnemonic: ATLEAST
    variant: AtLeast
    category: xqmx-high-level
    operands:
      - {name: model, type: register, width: 1}
      - {name: indices, type: register, width: 1}
    stack_pop: 2
    stack_push: 0
    doc: "Pop penalty and k; allocate slack variables and apply at-least-k constraint."

  - code: 0x76
    mnemonic: ATLEASTW
    variant: AtLeastW
    category: xqmx-high-level
    operands:
      - {name: model, type: register, width: 1}
      - {name: indices, type: register, width: 1}
      - {name: coeffs, type: register, width: 1}
    stack_pop: 2
    stack_push: 0
    doc: "Pop penalty and k; allocate slack variables and apply weighted at-least-k constraint."

  - code: 0x77
    mnemonic: REDUCE
    variant: Reduce
    category: xqmx-high-level
    operands:
      - {name: model, type: register, width: 1}
    stack_pop: 3
    stack_push: 1
    doc: "Pop P_aux, var_b, var_a; allocate auxiliary variable and add Rosenberg enforcement terms; push aux index."

  - code: 0x7F
    mnemonic: ENERGY
    variant: Energy
    category: xqmx-high-level
    operands:
      - {name: model,  type: register, width: 1}
      - {name: sample, type: register, width: 1}
    stack_pop: 0
    stack_push: 1
    doc: "Compute the Hamiltonian energy of a sample against a model; push the result."

  # ------------------------------------------------------------------------
  # Special (0xF0, 0xFF)
  # ------------------------------------------------------------------------

  - {code: 0xF0, mnemonic: NOP,  variant: Nop,  category: special, operands: [], stack_pop: 0, stack_push: 0, doc: "No operation."}
  - {code: 0xFF, mnemonic: HALT, variant: Halt, category: special, operands: [], stack_pop: 0, stack_push: 0, doc: "Stop execution."}

reserved:
  - 0x0D
  - 0x19
  - 0x35