{"by":"rafa_rrayes","descendants":21,"id":46794281,"kids":[46803536,46800511,46810083,46803200,46801095,46804322,46802280,46805777,46804185,46802416,46800947],"score":48,"text":"Hi, everyone!<p>I built SHDL (Simple Hardware Description Language) as an experiment in stripping hardware description down to its absolute fundamentals.<p>In SHDL, there are no arithmetic operators, no implicit bit widths, and no high-level constructs. You build everything explicitly from logic gates and wires, and then compose larger components hierarchically. The goal is not synthesis or performance, but understanding: what digital systems actually look like when abstractions are removed.<p>SHDL is accompanied by PySHDL, a Python interface that lets you load circuits, poke inputs, step the simulation, and observe outputs. Under the hood, SHDL compiles circuits to C for fast execution, but the language itself remains intentionally small and transparent.<p>This is not meant to replace Verilog or VHDL. It’s aimed at: - learning digital logic from first principles - experimenting with HDL and language design - teaching or visualizing how complex hardware emerges from simple gates.<p>I would especially appreciate feedback on: - the language design choices - what feels unnecessarily restrictive vs. educationally valuable - whether this kind of “anti-abstraction” HDL is useful to you.<p>Repo: <a href=\"https:&#x2F;&#x2F;github.com&#x2F;rafa-rrayes&#x2F;SHDL\" rel=\"nofollow\">https:&#x2F;&#x2F;github.com&#x2F;rafa-rrayes&#x2F;SHDL</a><p>Python package: PySHDL on PyPI<p>To make this concrete, here are a few small working examples written in SHDL:<p>1. Full Adder<p>component FullAdder(A, B, Cin) -&gt; (Sum, Cout) {<p><pre><code>    x1: XOR; a1: AND;\n    x2: XOR; a2: AND;\n    o1: OR;\n\n    connect {\n        A -&gt; x1.A; B -&gt; x1.B;\n        A -&gt; a1.A; B -&gt; a1.B;\n\n        x1.O -&gt; x2.A; Cin -&gt; x2.B;\n        x1.O -&gt; a2.A; Cin -&gt; a2.B;\n        a1.O -&gt; o1.A; a2.O -&gt; o1.B;\n\n        x2.O -&gt; Sum; o1.O -&gt; Cout;\n    }</code></pre>\n}<p>2. 16 bit register<p># clk must be high for two cycles to store a value<p>component Register16(In[16], clk) -&gt; (Out[16]) {<p><pre><code>    &gt;i[16]{\n        a1{i}: AND;\n        a2{i}: AND;\n        not1{i}: NOT;\n        nor1{i}: NOR;\n        nor2{i}: NOR;\n    }\n    \n    connect {\n        &gt;i[16]{\n            # Capture on clk\n            In[{i}] -&gt; a1{i}.A;\n            In[{i}] -&gt; not1{i}.A;\n            not1{i}.O -&gt; a2{i}.A;\n            \n            clk -&gt; a1{i}.B;\n            clk -&gt; a2{i}.B;\n            \n            a1{i}.O -&gt; nor1{i}.A;\n            a2{i}.O -&gt; nor2{i}.A;\n            nor1{i}.O -&gt; nor2{i}.B;\n            nor2{i}.O -&gt; nor1{i}.B;\n            nor2{i}.O -&gt; Out[{i}];\n        }\n    }</code></pre>\n}<p>3. 16-bit Ripple-Carry Adder<p>use fullAdder::{FullAdder};<p>component Adder16(A[16], B[16], Cin) -&gt; (Sum[16], Cout) {<p><pre><code>    &gt;i[16]{ fa{i}: FullAdder; }\n\n    connect {\n        A[1] -&gt; fa1.A;\n        B[1] -&gt; fa1.B;\n        Cin -&gt; fa1.Cin;\n        fa1.Sum -&gt; Sum[1];\n\n        &gt;i[2,16]{\n            A[{i}] -&gt; fa{i}.A;\n            B[{i}] -&gt; fa{i}.B;\n            fa{i-1}.Cout -&gt; fa{i}.Cin;\n            fa{i}.Sum -&gt; Sum[{i}];\n        }\n\n        fa16.Cout -&gt; Cout;\n    }\n}</code></pre>","time":1769601978,"title":"Show HN: SHDL – A minimal hardware description language built from logic gates","type":"story","url":"https://github.com/rafa-rrayes/SHDL"}