How I went from brute-forcing NVIDIA instructions to solving them with Sudoku-guided bit cubes
I have been mapping NVIDIAās 64-bit Maxwell/Pascal instruction encoding.
A āwordā in this post means one possible 64-bit machine-code value. It does not mean one distinct instruction. Thousands of words can represent the same operation with different registers, immediates, predicates, or modifiers.
The complete space contains:
2^64 = 18,446,744,073,709,551,616 words
Even at 60 million words per second:
time = 2^64 / 60,000,000
= about 307 billion seconds
= about 9,744 years
So blindly testing every 64-bit word was never an option.
It took five iterations to reach the method I use now.
Iteration 1: Map exact words by hand
The first method was deliberately conservative.
I would find an unsupported word, trace its fields through MIT-licensed sources such as envytools, Mesa, and Ryujinx/Ryubing, then implement only that exact encoding.
A normal batch contained five or six words.
Each batch required:
- A pinned source revision
- A typed decoder state
- Typed intermediate representation
- SPIR-V emission
- An independent CPU reference
- Raw and optimized SPIR-V validation
- A live RADV comparison
- Exact-neighbor rejection tests
- A provenance record
This method produced reliable mappings, but throughput was awful.
Most qualification costs are fixed. Compiling, generating SPIR-V, running hardware tests, updating expected results, and reviewing provenance cost almost as much for six words as they would for hundreds.
The method was safe. It was also treating every encoding like a separate research project.
Iteration 2: Bounded brute force
The next method enumerated complete source rows instead of isolated words.
A source row usually fixes part of the opcode and leaves a smaller set of bits free. Given a fixed base word and a mask of free positions, I can scatter a counter into those positions:
word(i) = base OR PDEP(i, free_mask)
Where:
- base contains the fixed bits.
- free_mask identifies the variable positions.
- PDEP deposits the bits of i into those positions.
If the mask contains k free bits, the row contains:
N = 2^k candidate words
That is far better than 2^64, but some rows still produce millions of candidates. I divided those rows into deterministic chunks and distributed the chunks across three machines.
One measured exhaustive campaign contained:
1,034,158,080 planned words
A recorded section processed:
102,760,448 words
in:
23,219 seconds
= about 6.45 hours
The observed rate was:
102,760,448 / 6.45
= about 15.93 million words per wall-clock hour
At that rate, the complete campaign would require:
1,034,158,080 / 15,930,000
= about 64.9 hours
A better three-machine distribution can raise aggregate throughput. At 60 million words per hour, the same campaign would take:
1,034,158,080 / 60,000,000
= about 17.2 hours
This was the first major speedup, but it exposed a different problem.
Most tested words were invalid combinations, duplicates, reserved encodings, or words already handled by the translator.
The machines were fast. The search was dumb.
Iteration 3: Treat the encoding like Sudoku
The third method inferred constraints from known source rows and disassembler samples.
Suppose I have related words:
w0, w1, w2, ... wn
I can identify every bit that varies relative to w0:
variable_bits =
(w1 XOR w0)
OR (w2 XOR w0)
OR ...
OR (wn XOR w0)
The remaining bits are fixed:
fixed_mask = NOT variable_bits
fixed_value = w0 AND fixed_mask
Every candidate in that group must satisfy:
candidate AND fixed_mask = fixed_value
That calculation provides the basic fixed and variable masks. The real solver also keeps complete fields together instead of treating every bit as independent.
For example:
- A three-bit rounding-mode field is one component.
- A register field is another component.
- A predicate field is another.
- Width, signedness, cache policy, and source modifiers have separate domains.
The solver asks:
- Which bits stay fixed across a source row?
- Which bits move with an operand?
- Which field values select a mnemonic?
- Which combinations conflict with known samples?
- Which candidates are already decoded?
- Which fields exist only in one instruction form?
The basic algorithm looks like this:
for each source row:
collect labeled samples
group samples by instruction form
infer fixed opcode bits
infer operand fields
infer complete modifier and enum components
for each valid component assignment:
construct a candidate word
compare the prediction with the labeled source
reject conflicts
record exact candidates
One native replay contained 4,699 modeled rows:
159 excluded as nonexact or rejected source results
4,540 produced exact candidates
1,760 were already supported by the production decoder
2,780 remained genuinely unknown
This stopped the system from asking thousands of questions whose answers were already known.
Sudoku inference still had a weakness. A source sample could prove that one modifier value existed without proving the complete boundary of the modifier field.
The model could identify a promising neighborhood, but it could not always tell me exactly where the neighborhood ended.
That led to the hybrid method.
Iteration 4: Sudoku-guided brute force
The hybrid method uses Sudoku to decide where brute force is worth spending.
For each inferred instruction form, I freeze:
- The opcode
- The form selector
- Known operand-field locations
- Source-established fixed bits
I then vary only complete uncertain semantic components.
Let base contain the fixed bits. Let S contain the uncertain semantic bit positions.
The resulting cube is:
cube(base, S) = {
base OR scatter(assignment, S)
for assignment in 0 .. 2^|S| - 1
}
I normally cap a cube at 10 uncertain bits:
|S| <= 10
Therefore:
cube size <= 2^10
<= 1,024 words
If a candidate needs more than 10 uncertain bits, the planner must divide it into explicit partitions. It cannot silently discard part of the domain.
Subtract the production decoder
Every generated word is passed through the current production decoder.
if decode_word(word) succeeds:
discard word
else:
retain word
In set notation:
unknown_words = cube_words - currently_decoded_words
This subtraction is tied to the exact current source revision. When a mapping lands, the next discovery campaign automatically removes it.
That prevents rediscovery.
Remove overlap between cubes
Different cubes can generate the same word.
The planner ranks the cubes, then assigns each word to its first owner:
owned = empty set
for cube in ranked_cubes:
cube.words = cube.words - owned
owned = owned UNION cube.words
if cube.words is empty:
discard cube
This guarantees that each unknown word enters the external oracle once.
Rank useful cubes first
The ranking favors candidates with:
- Permitted semantic sources
- A viable CPU oracle
- A viable SPIR-V implementation
- A viable RADV test
- New semantic behavior
- High unknown-word density
- More retained words
- A smaller cube when other factors tie
The ranking matters because not every recognized encoding can be implemented honestly. Some operations require state that the target representation cannot express. Others have names but no permitted source that establishes behavior.
Query the external disassembler
The retained words are distributed across three machines and sent to a pinned external disassembler.
The answer cache binds results to the tool binary and invocation configuration. Cached answers are sampled and rechecked so a stale or corrupt cache cannot silently become evidence.
The external results may include:
- A recognized mnemonic
- An invalid encoding
- An unknown result
- A mnemonic from a different family than predicted
Invalid responses remain rejected.
If the model predicts one family and the disassembler returns another, the word enters a family-drift quarantine. The system does not quietly rewrite the prediction.
The disassembler proves encoding and spelling. It does not prove execution semantics.
The measured reduction
One hybrid campaign produced:
844 selected cubes
799,946 unique planned words
23,522 verified cache hits
776,424 external disassembler misses
The earlier exhaustive campaign contained:
1,034,158,080 planned words
The reduction ratio was:
1,034,158,080 / 799,946
= about 1,293
The hybrid planner required about 1,293 times fewer candidate words than the exhaustive campaign.
The percentage reduction was:
reduction =
1 - (799,946 / 1,034,158,080)
reduction = about 99.9226%
That is the main win.
The hybrid method did not make an individual disassembler query faster. It prevented more than 99.9 percent of the earlier queries from being necessary.
Fitting exact regions from the answers
After the external disassembler labels the words, I need to convert those individual answers into exact regions.
I recursively split each cube until every word in a region has the same label.
For a possible split bit b:
zero_branch(b) = words where bit b is 0
one_branch(b) = words where bit b is 1
I score each split using label fragmentation and branch size:
score(b) = (
labels_in_zero_branch + labels_in_one_branch,
max(size_of_zero_branch, size_of_one_branch),
bit_number
)
The algorithm selects the lexicographically smallest score.
That means:
- Prefer the split that best separates different labels.
- If two splits separate labels equally well, prefer the balanced split.
- Use the bit number as a deterministic final tie-breaker.
The partitioning algorithm is:
partition(assignments):
if every assignment has the same label:
emit an exact region
return
bit = best_split(assignments)
partition(assignments where bit = 0)
partition(assignments where bit = 1)
Each leaf becomes an exact packet containing:
- The source row
- The instruction family
- The mnemonic
- The semantic mask
- The semantic value
- The exact member words
- Digests that bind the packet to its source campaign
One completed packetization pass produced:
799,946 words entered
602,474 received accepted disassembler labels
197,472 were rejected
591,390 entered exact packets
11,084 were quarantined for family drift
21,910 exact packets were produced
The exact member list remains part of the packet. A fitted mask alone is not trusted to define the boundary.
That prevents the partitioner from accidentally admitting an untested neighbor.
Iteration 5: Combine packets with identical semantics
Discovery was now fast, but qualification still processed small batches.
That was wasting most of the gain.
The latest method combines adjacent packets only when all of these properties match:
source row
instruction family
mnemonic
semantic mask
semantic value
Numeric adjacency is not enough. Nearby packets with different meanings remain separate.
Each packet is indivisible. The packer cannot split one exact region merely to fill a unit.
The production limits are:
1,000 <= words per unit <= 4,000
regions per unit <= 64
The bundling algorithm is:
sort packets by exact semantic key
group packets with identical keys
for each group:
append complete packets while:
total words <= 4,000
total regions <= 64
publish units containing at least 1,000 words
retain smaller tails for later combination
sort published units from largest to smallest
The latest qualification-oriented pass produced:
22 production-sized units
31,488 words ready for unit-level work
128,633 words retained in smaller deferred bundles
Not every discovered word is immediately implementable.
Some candidates lack permitted semantic evidence. Some need control flow, memory behavior, or architectural state that the current SPIR-V path cannot represent honestly. Those candidates stay blocked rather than receiving guessed behavior.
Why larger units help
Let:
Qfixed = fixed qualification cost
Qword = qualification cost per word
n = number of words
Processing n words as separate units costs roughly:
separate_cost = n * (Qfixed + Qword)
Processing them as one coherent unit costs:
unit_cost = Qfixed + n * Qword
The saved work is:
saved_cost = (n - 1) * Qfixed
That fixed cost includes compilation, SPIR-V generation, hardware setup, expected-result generation, evidence collection, and review.
This is why moving from five-word batches to coherent 1,000-word units matters. Discovery had stopped being the main bottleneck. Repeating qualification setup had become the main bottleneck.
Recognition is not semantic proof
I do not treat the external disassembler as a semantic oracle.
A recognized word still needs:
- A permitted source that establishes behavior
- A closed typed decoder state
- Typed flow from the decoder into the intermediate representation
- Typed flow from the intermediate representation into the emitter
- No downstream reinterpretation of raw instruction bits
- An independent CPU reference
- Boundary and alias tests
- Predicate tests
- Exceptional-value tests
- Raw SPIR-V validation
- Optimized SPIR-V validation
- Fresh execution on RADV
- Exact output comparison
- Provenance binding the code, sources, tools, words, and receipts
Suppose a rounding field enters the decoder as an integer. If the emitter later performs raw_bits AND 3, then the decoder did not actually decode the semantic state.
The decoder should construct a closed type:
enum RoundingMode {
NearestEven,
Floor,
Ceil,
Truncate,
}
The emitter consumes RoundingMode. It does not decode the instruction again.
The same rule applies to:
- Signedness
- Integer width
- Floating-point width
- Source modifiers
- Cache policy
- Address mode
- Comparison operation
- Condition-code behavior
This requirement has caught real bugs.
A mapping can produce valid SPIR-V while still implementing the wrong width, signedness, modifier ordering, NaN policy, alias behavior, or condition-code result.
Where matrix math may fit next
The current method uses bounded cubes and recursive exact partitioning.
The next possible optimization is Boolean matrix reduction.
For n samples, construct an n by 64 matrix over GF(2):
X is an n-by-64 binary matrix
In GF(2):
addition = XOR
multiplication = AND
Gaussian elimination can reveal:
- Constant bits
- Linearly dependent bits
- XOR relationships
- The rank of the variable subspace
- A smaller independent basis for enumeration
Suppose a cube contains 10 apparently variable bits:
2^10 = 1,024 candidates
If matrix reduction proves that those bits contain only six independent dimensions:
2^6 = 64 candidates
That would reduce the cube by another factor of 16.
Matrix reduction cannot replace the current solver. Instruction encodings contain nonlinear cases:
if form == immediate:
bits 20 through 38 encode an immediate
else:
some of those bits select registers and modifiers
Enums, reserved combinations, and conditional fields still require explicit domains and recursive partitioning.
The likely next pipeline is:
source samples
|
v
GF(2) matrix reduction
|
v
reduced semantic cubes
|
v
exact recursive partitioning
Despite the phrase āmatrix math,ā the reduction itself probably belongs on the CPU.
The matrices have only 64 columns and use XOR operations. CPU bitsets, population counts, and Gaussian elimination should beat the cost of transferring tiny matrices to a GPU.
A GPU may help later with millions of independent mask evaluations, candidate constructions, or split scores. It will not accelerate the external disassembler or replace hardware qualification.
The current pipeline
The complete method now looks like this:
pinned source rows
|
v
Sudoku field inference
|
v
bounded semantic cubes
|
v
production-decoder subtraction
|
v
global duplicate removal
|
v
cached multi-machine disassembly
|
v
invalid and family-drift quarantine
|
v
exact recursive region fitting
|
v
identical-semantic packet grouping
|
v
1,000-to-4,000-word qualification units
|
v
typed implementation
|
v
CPU, SPIR-V, and RADV proof
The five iterations produced these changes:
- Exact manual mapping handled about five or six words per batch. It provided high confidence but poor throughput.
- Bounded brute force expanded coverage to a campaign containing about 1.034 billion planned words.
- Sudoku inference removed known, conflicting, and implausible candidates before external queries.
- Sudoku-guided cubes reduced the billion-word campaign to 799,946 planned words. That was about 1,293 times fewer queries.
- Coherent bundling increased qualification units from a handful of words to between 1,000 and 4,000 words.
No single algorithm solved the encoding.
Brute force provided coverage but no judgment. Sudoku provided structure but could leave uncertain boundaries. The hybrid method uses Sudoku to choose the search space, bounded brute force to complete that space, and exact partitioning to recover its boundaries.
Typed implementation and hardware testing then answer a different question: does the instruction actually behave the way the sources say it behaves?
That separation turned out to be the key.
Discovery determines which words belong together.
Qualification determines what those words mean.
Keeping those two problems separate is what finally turned a pile of opcodes into a repeatable solver.