Back to Blog
AIPublished on October 29, 2026

Emulating Silicon in Transformer Weights: Inside Qwenputer and Deterministic RISC-V Execution

Can an autoregressive language model reliably function as a deterministic, cycle-accurate processor? Here is an architectural deep dive into Qwenputer, exploring how RISC-V RV32I instruction decode, register state transitions, and memory addressing operate within LLM context spaces.

<h2>Beyond Token Prediction: Can a Transformer Act as a Formal State Machine?</h2>

Autoregressive Large Language Models (LLMs) are fundamentally probabilistic sequence predictors modeled around conditional token distributions: $P(w_t \mid w_1, \dots, w_{t-1})$. Consequently, executing deterministic algorithms over long horizons often leads to drift, error compounding, and arithmetic hallucinations. However, the emergence of Qwenputer—a project demonstrating a functioning, deterministic RISC-V CPU running entirely within the inference pass of Qwen 2.5/3.5 models—has upended conventional assumptions regarding neural computational bounds.

Simulating a central processing unit (CPU) is not merely a benchmark of syntactic comprehension; it is an unforgiving test of formal state encapsulation. A processor is mathematically a discrete state machine defined by a tuple $(S, I, \delta)$, where state $S$ comprises architectural registers, status flags, and program counters, input $I$ represents machine instructions, and $\delta: S \times I \to S$ defines the transition function. In a hardware core, this transition occurs deterministically at every clock edge. In Qwenputer, this entire transition pipeline—fetch, decode, execute, memory access, and writeback—is executed across transformer self-attention layers and autoregressive token generation without external code interpretation.

This article deconstructs the architecture of Qwenputer, analyzing how an LLM can maintain cycle-accurate deterministic state, parse binary and assembly representations, execute two's complement integer logic, and emulate a complete RV32I instruction set architecture (ISA).


<h2>Deconstructing the RV32I Pipeline in Autoregressive Space</h2>

The RISC-V RV32I base integer instruction set was designed with extreme architectural minimalism: exactly 32 general-purpose registers (x0 through x31, where x0 is hardwired to zero), a 32-bit Program Counter (pc), an unsegmented 32-bit address space, and a reduced instruction format (R, I, S, B, U, and J types). This simplicity makes RV32I the ideal target for transformer-driven instruction emulation.

+-------------------------------------------------------------+
|                        Qwenputer Pipeline                   |
+-------------------------------------------------------------+
|  1. Fetch     : Read instruction from virtual RAM at PC     |
|  2. Decode    : Decompose hex/binary into Opcode, rd, rs    |
|  3. Execute   : Compute ALU operations (Bitwise, Add, Shift)|
|  4. Memory    : Evaluate Load/Store offsets against RAM map |
|  5. Writeback : Commit state delta to Register Context      |
+-------------------------------------------------------------+

In a traditional software emulator written in C or Rust, execution involves an infinite while(running) loop with a giant switch(opcode) statement updating a struct. In Qwenputer, the model itself is prompted or fine-tuned to act as the execution kernel. Each generated response corresponds to one or more execution cycles, outputting the mutated architectural state in a structured intermediate representation:

CYCLE: 00000412 | PC: 0x80000028 | INSTR: 0x00528293 (addi t0, t0, 5)
PREV_STATE: t0 = 0x0000000A (10)
ALU_OP    : 0x0000000A + 0x00000005 = 0x0000000F
NEXT_STATE: t0 = 0x0000000F (15) | PC = 0x8000002C

To make this deterministic, the model must not take shortcuts. It cannot guess the outcome of a loop; it must serialize the exact micro-architectural state transitions token by token.


<h2>State Representation: Registers, PC, and Memory Management</h2>

The fundamental barrier to running a virtual machine inside an autoregressive model is the volatility of internal state. Standard transformer inference lacks writable non-volatile memory; its only state persistence mechanisms are the KV-cache (historical context) and weight parameters.

1. Register File Encapsulation

Qwenputer serializes the 32-bit register file into structured text blocks at each step or execution block. The zero register (x0) invariant must be strictly enforced: any instruction targeting x0 as rd (such as nop, which is encoded as addi x0, x0, 0) must produce no mutation in the serialized register file. Maintaining 32 distinct hex values across thousands of generated tokens requires absolute attention fidelity to prevent the attention heads from attending to stale register values from previous cycles.

2. Byte-Addressable Memory Emulation

Emulating RAM inside context length presents a scaling challenge. Standard RV32I memory operations (LB, LH, LW, SB, SH, SW) interact with byte-addressable linear memory. In Qwenputer, dynamic memory is maintained as an explicit sparse memory table formatted within the context:

"memory": {
  "0x80001000": "0xDEADBEEF",
  "0x80001004": "0x0000002A"
}

When a store instruction like sw t1, 4(sp) executes, the model calculates the effective target address $EA = \text{Reg}[sp] + \text{sign_extend}(\text{offset})$, queries the context history for the target memory cell, updates the entry, and generates an updated memory segment. Endianness conversion (little-endian byte ordering) is handled via internal token mapping during half-word and byte loads.


<h2>The Arithmetic Challenge: Bitwise Logic and Two's Complement</h2>

Transformers routinely fail at 32-bit arithmetic due to byte-pair encoding (BPE) fragmentation. Numbers like 4294967295 are tokenized into arbitrary digit chunks (e.g., 429, 496, 72, 95), destroying the alignment required for carry-propagate adders or bitwise shifts.

Qwen 2.5 and 3.5 mitigate this through refined tokenization that preserves individual byte or digit boundaries, but raw binary logic remains non-trivial. Qwenputer overcomes this by structuring the ALU phase through internal chain-of-state verification steps:

Two's Complement Subtraction and Overflow

When processing sub rd, rs1, rs2, the model calculates the inverted bits plus one ($rs1 + (\sim rs2 + 1)$). By forcing the model to explicitly emit the intermediate hexadecimal or binary chunks, the self-attention mechanism computes column-wise additions with explicit ripple carries:

$$\begin{aligned} A &= \mathtt{0x7FFFFFFF} \ B &= \mathtt{0x00000001} \ A+B &= \mathtt{0x80000000} \quad (\text{Signed overflow occurs; } \text{msb flips to } 1) \end{aligned}$$

Barrel Shifting (SLL, SRL, SRA)

Arithmetic shifts (SRA) require preserving the most significant sign bit (msb) while shifting the mantissa rightward. Standard LLMs often mistake SRA for logical shift SRL. Qwenputer resolves this by extracting the shift amount ($shamt = rs2[4:0]$), computing the mask dynamically, and showing sign extension explicitly in the chain-of-execution tokens.


<h2>Branch Hazards, Loops, and Execution Trace Determinism</h2>

A critical failure point in naive LLM code execution is the loop convergence hallucination. When presented with a loop running 100 iterations, most models will simulate 3 iterations and jump directly to what they assume the terminal condition looks like, skipping critical side-effects or off-by-one boundary conditions.

In Qwenputer, control flow is locked via rigid execution schemas:

Instruction: beq t0, t1, offset_target
Condition Evaluation:
  t0: 0x00000004
  t1: 0x00000005
  Predicate: 0x00000004 == 0x00000005 -> FALSE
Next PC: PC + 4 (0x80000010)

By forcing the predicate calculation (TRUE or FALSE) to generate as an explicit token prior to generating the target PC, the causal attention mechanism conditions the subsequent PC generation strictly on the boolean output. This prevents speculative execution errors and guarantees that loops are executed step-by-step without skipping iterations.


<h2>Running Real ELF Binaries: The Performance Paradigm</h2>

To test the limits of Qwenputer, real C programs can be compiled using the standard GNU RISC-V toolchain:

riscv32-unknown-elf-gcc -O2 -nostdlib -Tlink.ld -o fibonacci.elf fibonacci.c
riscv32-unknown-elf-objcopy -O binary fibonacci.elf fibonacci.bin

The resulting flat binary is converted to hexadecimal string representations and loaded into Qwenputer's virtual text-memory array. The model then executes the entry point (_start), progressing through the binary instructions until encountering an ebreak or infinite halt loop.

// A typical test kernel compiled for Qwenputer execution
int fib(int n) {
    if (n <= 1) return n;
    return fib(n - 1) + fib(n - 2);
}

Clock Frequency vs. Tokens per Second

In this execution model, traditional concepts of computational frequency are inverted:

  • Physical Silicon: A real microcontroller (e.g., ESP32-C3 running RV32IMC) executes at 160 MHz (160,000,000 cycles per second) consuming milliwatts.
  • Qwenputer on GPUs: Running on a cluster of H100s, generating at ~60 tokens per second, where each RV32I execution step consumes roughly 40 tokens of state trace, yields an effective execution speed of ~1.5 Hz (1.5 instructions per second), consuming hundreds of watts.

While this efficiency profile makes it absurd for general computing, the metric here is not throughput—it is functional universality. It proves that the model's weights contain a sufficiently complete internal model of formal operational semantics to simulate arbitrary Turing-complete machines.


<h2>Implications for Neurosymbolic Computing and Sandboxed AI</h2>

The real-world implications of Qwenputer extend far beyond the novelty of running a slow virtual CPU:

  1. Provable Tool Verification: Rather than relying on external Python sandboxes which can be hijacked or misconfigured, language models with native ISA emulation capabilities can execute untrusted microcode within their own latent reasoning processes, verifying security and memory bounds before executing operations on real systems.
  2. Zero-Shot Dynamic Code Analysis: An analyst can pass unknown shellcode or firmware fragments into the LLM, prompting it to trace execution paths cycle by cycle. Because the execution happens inside the model's attention space, symbolic analysis, register taint tracking, and anomaly detection can occur simultaneously alongside disassembly.
  3. Formal Reasoning Validation: If an LLM can simulate a cycle-accurate RISC-V CPU without hallucinating register corruption, its capacity for deterministic logic, formal mathematical proofs, and verified software synthesis is substantially higher than standard conversational evaluations suggest.

Qwenputer demonstrates that modern LLMs are not merely stochastic parrots generating associative text; under the right constraints, their attention heads can be assembled into an accurate, programmable, silicon-free computer.

#RISC-V#LLM#Computer Architecture#Machine Learning#Emulation