← Back to research

Research Article

nCPU: A Neural CPU Achieving 100% Accuracy on Integer Arithmetic

What if every component of a CPU was a trained neural network? Not approximately - exactly. nCPU proves this is possible, then goes further: a neural operating system, a GPU-native UNIX with compiled C, and structural immunity to timing side-channel attacks.

Robert PriceBlackweb.AIMarch 2026
0%
ALU Accuracy
All integer ALU ops
0
Neural Models
13 ALU + 11 neurOS
0+
Tests
Across 15 test files
0
Execution Modes
Neural / Fast / Compute

The Core Insight

Neural networks are inherently continuous and approximate. Integer arithmetic is inherently discrete and exact. Prior work - Neural Turing Machines, NALU, Neural GPUs - achieved approximate results or worked on small bit-widths. nCPU closes this gap with a design principle called memorization-by-decomposition.

1
Decompose

Break 32-bit ops into sub-problems with tiny input spaces

2
Train

Train exhaustively on every possible input (8 entries, 65K entries)

3
Threshold

sigmoid > 0.5 converts continuous activations to exact discrete bits

4
Compose

Wire sub-problems together structurally, like digital logic

MEMORIZATION-BY-DECOMPOSITION: 32-BIT ADDITION32-bit A, B4,294,967,296 pairsDECOMPOSEBit 0–7Full adderBit 8–15Full adderBit 16–23Full adderBit 24–31Full adderNeural Net8 inputs → 1 outputCarry CombineKogge-Stone CLAThresholdsigmoid > 0.5Exact Bits100% accurateEach sub-problem has a tiny input space (8 or 65K entries) → can be memorized exhaustively

three execution modes

Each mode represents a different point in the design space. The neural mode is the research contribution. The compute mode is the most powerful - it runs a complete UNIX OS and uses zero neural models.

Neural Mode

The Research Contribution

Every ALU operation routed through trained PyTorch models. Zero arithmetic fallbacks.

Execution Pipeline
Input
ARM64 Binary
4 bytes
Decode
Neural CNN
167K params
ALU Bridge
64→32 bit
Narrowing
Neural Op
.pt Model
13 ALU models
Threshold
σ > 0.5
Exact bits
Result
100%
Exact
OperationModelStrategyLatency
ADD / SUB / CMParithmetic.pt + carry_combine.ptKogge-Stone CLA (8 neural passes)~248 us
MULmultiply.ptByte-pair LUT (65,536 entries)~21 us
AND / OR / XORlogical.ptNeural truth tables (28 params)~21 us
SHL / SHRlsl.pt / lsr.ptAttention-based bit routing (3 batched passes)~434 us
DIVarithmetic.ptRestoring division (32-bit loop)Sequential
sin / cos / sqrt / exp / log / atan26 math modelsSpecialized neural approximators21–935 us
~5,000
IPS (Programs)
~2.5
FPS (DOOM)
~49 MB
Total Weights

Fast Mode

Native Tensor Ops

Same GPU-resident architecture, but bypasses neural models for native PyTorch tensor arithmetic.

Execution Pipeline
Input
ARM64 Binary
4 bytes
Decode
Bitfield Extract
Native tensor
Execute
torch.add/mul
Native ops
State
GPU Tensors
Regs, flags, PC
Result
Fast
No models

Same architecture, no neural overhead. Registers, flags, memory, and PC are still GPU-resident PyTorch tensors. The only difference: arithmetic uses torch.add(), torch.mul(), etc. instead of dispatching through .pt models.

~5,000
FPS (DOOM)
~1.35M
IPS (Programs)

Compute Mode

Most Powerful - Runs the OS

Native Metal GPU compute shaders. Zero neural models. Compiled C runs directly on GPU silicon.

Execution Pipeline
Source
C Code
Freestanding
Compile
aarch64-gcc
-O2 -ffreestanding
Extract
objcopy
Raw binary
Load
GPU Memory
16 MB buffer
Execute
Metal GPU
~1,600 lines MSL
I/O
SVC Trap
Python mediates

No neural models whatsoever. This is a qemu-style fetch-decode-execute loop written entirely in Metal Shading Language. 130+ ARM64 instructions including all data movement, arithmetic, logic, shifts, bit manipulation, conditionals, memory ops, branches, and system instructions. The entire UNIX OS - shell, filesystem, multi-process, C runtime - runs on this engine.

Data
MOVZ/K/N, MOV, ADRP, ADR
Arithmetic
ADD/SUB/MUL/SDIV/UDIV/NEG
Logic
AND/ORR/EOR/EON/ORN/BIC/MVN
Shifts/Bits
LSL/LSR/ASR, CLZ, REV, RBIT
Memory
LDR/STR all widths, LDP/STP
Branch
B/BL/BR/BLR/RET, B.cond
Conditional
CSEL/CSINC/CSINV/CSNEG
System
SVC, HLT, NOP, DMB/DSB/ISB
~4.4M
IPS Sustained
130+
ARM64 Instructions
28
Syscalls
Relative Speed Comparison
Neural Mode~5K IPS
Fast Mode~1.35M IPS
Compute Mode~4.4M IPS

Neural mode is ~880x slower than compute - but it proves neural networks can do exact arithmetic. These are complementary findings, not competing approaches.

Key Finding: Performance Inversion

In conventional CPUs, multiplication is 3–10x slower than addition. In nCPU, the relationship is inverted: neural multiplication is 12x faster than neural addition.

O(1) Operations
~21 us
mul, and, or, xor, exp, log
Single-pass lookup / MLP
O(log n) Operations
~248 us
add, sub, cmp
Kogge-Stone CLA (8 passes)
Batched Operations
~434 us
shl, shr
3 batched attention passes

Insight: Carry propagation, not operation semantics, is the dominant cost. Model size doesn't predict latency - the 4 MB multiply LUT (21 us) is 12x faster than the 38 KB adder (248 us).

Formal Verification: Not Statistical - Complete

Unlike typical ML systems evaluated on held-out test sets, nCPU's sub-components are verified by exhaustive enumeration of every possible input. This is a mathematical proof, not a statistical estimate.

ModelInput SpaceVerifiedResult
Full adder (arithmetic.pt)2³ = 8 inputs8 / 8100% correct
Carry-combine (carry_combine.pt)2⁴ = 16 inputs16 / 16100% correct
Logical truth tables (logical.pt)5 ops × 4 = 20 inputs20 / 20100% correct
Multiply LUT (multiply.pt)256 × 256 = 65,536 pairs65,536 / 65,536100% correct

Weights are frozen after training. Sigmoid outputs have margins > 0.4 from the 0.5 threshold. 100 repeated executions produce identical results. Accuracy is permanent by construction.

neurOS: a neural operating system

If the CPU can be neural, can the entire operating system? 17 modules, 11 trained models, zero fallbacks. All OS state lives as PyTorch tensors on GPU.

0
Neural Models
Zero fallbacks needed
0ms
Boot Time
15 subsystems
0%
MMU Accuracy
Neural page translation
0us
Compiler
Per program
neurOS BOOT SEQUENCE - 11 NEURAL SUBSYSTEMS - 78ms TOTALMMU100%TLB99.6%Cache99.7%Sched99.2%GIC93.7%Prefetch97.8%Alloc98.4%AsmTok99.4%AsmGen100%Compiler95.2%Watchdog100%TLB, Cache, Scheduler continue learning at runtime - single gradient steps adapt to workload0ms78ms

Neural Components

ComponentNeural ArchitectureAccuracy
MMUEmbedding-based page table (VPN + ASID → PFN classification)100.0%
TLBMLP eviction policy (5 features → score)99.6%
Cache ReplacementLSTM sequence model over access history99.7%
PrefetchLSTM address predictor (next K page accesses)97.8%
SchedulerTransformer encoder with self-attention over process queue99.2%
GIC (Interrupt Controller)MLP priority encoder (96 floats → 32 scores)93.7%
Block AllocatorMLP region scorer for fragmentation minimization98.4%
Assembler TokenizerCharacter-level CNN (char → token type)99.4%
Assembler CodegenMLP → 32 sigmoid bits (byte-identical to classical)100.0%
Compiler OptimizerMLP peephole window classifier (3-instruction windows)95.2%
WatchdogLSTM anomaly detector (8 metrics, ring buffer)100.0%

Online adaptation: TLB, cache, and scheduler take single gradient steps during normal operation, adapting to workload-specific patterns in real time. No conventional OS learns from its own scheduling and caching decisions at runtime.

GPU-native UNIX OS

A complete UNIX environment running as compiled C on the Metal compute kernel. No neural models - pure GPU compute shaders executing real ARM64 binaries.

nCPU GPU Shell - Metal Compute
25 Shell Commands
ls cd pwd cat echo mkdir rm rmdir touch wc cp head cc run env export grep sort uniq tee ps kill help exit
Plus pipes (|), background (&), chaining (; && ||), redirect (> >>)
Multi-Process

fork/wait/pipe/dup2 via memory swapping (classic UNIX technique). Up to 15 concurrent processes, 1 MB backing store each. Round-robin scheduler, per-process fd tables, pipe blocking with wakeup.

Fork bomb protection (32/process), SIGTERM/SIGKILL, orphan reparenting, per-process env vars.
C Runtime Library

Header-only freestanding libc. malloc/free/calloc/realloc, printf with full format specifiers, fork/wait/pipe/dup2/getpid/kill, qsort, strtol, sscanf, string functions.

All functions compile directly into user binaries - zero external dependencies.
OperationGPU CyclesNotes
Fork + exit + wait216 cyclesDominated by Metal dispatch overhead
Context switch166 cycles/switchMemory swap + register save/restore
Pipe throughput (1KB)0.9 cycles/byteNear-optimal utilization
Process create (N=8)62 cycles/processExcellent scaling
Single vs multi IPS~3,030 IPS0% overhead for compute-only workloads

13+ GPU Demo Applications

All compiled from freestanding C with aarch64-elf-gcc -O2, executing on the Metal compute kernel. No neural models involved.

Cryptography
  • SHA-256 - Full hash with HMAC (492 lines)
  • AES-128 - ECB + CBC modes, 6/6 FIPS tests
  • Password vault - SHA-256 KDF + XOR encryption
Games
  • Tetris - 7 tetrominoes, rotation, scoring, levels
  • Snake - 40x20 grid, WASD controls
  • Roguelike - Procedural dungeons, FOV, combat
  • Text Adventure - Room graph, inventory, puzzles
VMs, Tools, Net
  • Brainfuck - 3 layers deep: Python→Metal→ARM→BF
  • Forth REPL - Stack ops, word definitions, loops
  • CHIP-8 - 35 opcodes, 64x32 ASCII display
  • HTTP server - TCP via Python proxy to browsers
  • MNIST NN - 784→128→10, Q8.8 fixed-point
  • ed editor - Line editor with search/replace
Total: 13 C programs, 7,811 lines of freestanding C, all running on Metal GPU silicon

timing side-channel immunity

GPU-sandboxed execution provides structural immunity to timing attacks - without requiring constant-time coding, compiler annotations, or hardware mitigations.

GPU Cycles
σ = 0.0
Perfectly deterministic
Zero std dev across 30 runs per position
Native CPU
47–73%
Coefficient of variation
Exploitable by statistical accumulation
Host-Side
<0.5%
Dispatch masks everything
5x internal cycle diff invisible externally
THREE-LAYER TIMING ISOLATIONLAYER 1: GPU EXECUTIONAES Round 11 cycleAES Round 21 cycleAES Round N1 cycleσ = 0.0 (deterministic)SVCLAYER 2: SVC TRAPGPU → Python → GPURound-trip overheadSyscall mediationDwarfs ns differencesOverhead masks signalLAYER 3: EXTERNAL~1,300ms total dispatchInternal diff: 137 cyclesAttacker sees: CoV < 0.5%Unexecutable attackTiming info destroyedEach layer independently sufficient - combined, they provide structural immunity (not just mitigation)

AES-128 validated: Passes all 6 FIPS 197 test vectors on GPU. T-table timing attacks - the canonical AES side-channel vulnerability (Bernstein 2005) - are structurally impossible. No data cache, no cache lines, no cache-miss penalty. Every S-box lookup = exactly 1 cycle.

Project Evolution

01

Neural ALU

Foundation

Bit-serial full adder, byte-pair multiplication LUT, neural truth tables for logic. Proved 100% exact integer arithmetic via memorization-by-decomposition.

02

Carry-Lookahead & Vectorization

Optimization

Kogge-Stone parallel-prefix CLA reduced addition from 826us to 248us (3.3x). Shift vectorization from 2,833us to 434us (6.5x). Five novel findings about neural computation.

03

neurOS - Neural Operating System

Neural

17 modules across 10 phases. Neural MMU, TLB, scheduler, cache, assembler, compiler. All neural, zero fallbacks. Online adaptation for TLB/cache/scheduler.

04

Metal Compute Kernel

Native GPU

130+ ARM64 instructions in ~1,600 lines Metal Shading Language. C-to-GPU compilation pipeline. 42K–61K IPS sustained, ~4.4M IPS on nCPU ISA. Zero neural models.

05

GPU-Native UNIX OS

Native GPU

25-command shell, freestanding C libc, in-shell compilation, multi-process (fork/pipe/wait/dup2). 13+ demo apps: crypto, games, VMs, HTTP server, MNIST. All on compute kernel.

06

Side-Channel Immunity

Security

GPU timing determinism (σ=0.0). AES-128 passes all FIPS vectors. T-table attacks structurally impossible. Three-layer defense: deterministic execution, SVC trap, dispatch masking.

Seven Novel Contributions

1

First fully neural operating system - every component from MMU to compiler is a neural network

2

GPU-native architecture with zero CPU-GPU synchronization for all OS state

3

Neural multiplication 12x faster than neural addition, inverting the conventional CPU hierarchy

4

Memorization-by-decomposition as a general principle for exact neural computation

5

Neural compiler with learned peephole optimization passes trained from a classical oracle

6

Online adaptation of OS policies (TLB, cache, scheduler) during normal runtime operation

7

Structural timing side-channel immunity for real cryptographic primitives (AES-128, SHA-256)

Future Directions

O(1) Neural Carry Network

Train a monolithic network to compute all 32 carries simultaneously, reducing addition from O(log n) to O(1).

Differentiable Execution

Backpropagate through program execution for gradient-based program synthesis - learning instruction sequences via gradient descent.

Native 64-bit Models

Retrain all models on 64-bit operands, eliminating the bridge narrowing from 64-bit to 32-bit.

Conference Targets

ICML 2027 for neural computation findings. OSDI/SOSP for GPU-native OS architecture and neural scheduling.

This work is licensed under CC BY 4.0. Free to share and adapt with attribution.

nCPU: A Neural CPU Achieving 100% Accuracy on Integer Arithmetic | Research | Blackweb.AI | Blackweb AI