Setnex ISA balanced-ternary processor simulator
Project description
setnex-sim
Python simulator for the Setnex ISA — an open balanced ternary instruction set architecture.
Implements the full fetch/decode/execute cycle for a 27-trit processor: 27 general-purpose registers, 5 configurable ternary logic modes (LMODE), and fixed-length R/I/J/U/B instructions.
Built on tritlib.
Status
v0.3 — fully functional simulator. 46 opcodes implemented, 98% test coverage.
Implemented:
- Decoder (R, I, J, U, B formats)
- ALU (ADD, SUB, MUL, DIV, MOD, NEG, TAND, TOR, TNOT, TIMPL, CONS, ACONS, TSHIFT, TCMP, TGET, TSET, TSIGN, TABS, TMIN, TMAX)
- Configurable ternary logic via LMODE (Kleene, Łukasiewicz, Heyting, RM3, Bochvar)
- Registers (27 GPR + CSR: PC, LMODE, FLAGS, EPC, ECAUSE, EVEC, STATUS, ESAVE)
- Sparse word-addressed memory
- CPU fetch/decode/execute loop with ternary FLAGS (sign, carry)
- Branches and jumps (BEQ, BNE, BLT, BGT, BLE, BGE, BF, BRT3, JMP, JMPA, CALL)
- System instructions (CSRR, CSRW, CSRX, ECALL, IRET, TSEL)
Install
pip install setnex-sim
Or from source:
git clone https://codeberg.org/setnex/setnex-sim
cd setnex-sim
pip install -e ".[dev]"
Usage
from setnex_sim.cpu import CPU
from setnex_sim.assembler import encode_R, encode_I
cpu = CPU()
program = [
encode_I(-24, rd=1, rs1=0, imm=5), # LI r1, 5
encode_I(-24, rd=2, rs1=0, imm=3), # LI r2, 3
encode_R(-40, rd=3, rs1=1, rs2=2), # ADD r3, r1, r2
encode_R(0, rd=0, rs1=0, rs2=0), # HALT
]
cpu.load(program)
cpu.run()
print(int(cpu.regs[3])) # 8
Setnex ISA
The full ISA specification is available at setnex.org and on Codeberg — Apache 2.0, patent-free.
Licence
MIT — Copyright 2026 Eric Tellier
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file setnex_sim-0.3.0.tar.gz.
File metadata
- Download URL: setnex_sim-0.3.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf5e344b96e7e857664f43ad282c71c7628e6694d9e1c8e259a5c51571b0bfb0
|
|
| MD5 |
08a98309aa793b3c3d9cf5df216cb43a
|
|
| BLAKE2b-256 |
95fcd2dd90d94eb323ae2b46fa235e62b396d7c37349b962b7314fc86a82915f
|
File details
Details for the file setnex_sim-0.3.0-py3-none-any.whl.
File metadata
- Download URL: setnex_sim-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
726098ff7922cbb3d58f0f118ea13ca9e4460087a4caee6d1874f7c37de7acdb
|
|
| MD5 |
6b1897a12d448b534d5773eb5451e9ea
|
|
| BLAKE2b-256 |
be834cb47d387aaa39aba7e43bd34d8422826f9f3514cfe8cc8eeb366e269e65
|