LibFPGA Library

An MIT-licensed, vendor-neutral library of FPGA building blocks, developed in the open at github.com/libfpga/libfpga. Plain Verilog-2005 that synthesizes on Vivado, Quartus and the open Yosys flow, with a quality bar most libraries only claim.

Every module is verified

CI enforces four gates on the fully open toolchain: a self-checking testbench (Icarus), lint (Verilator -Wall), a Yosys synthesis check with honest LUT/FF stats, and formal proofs (yosys + z3, by induction) on the safety-critical modules, contracts that hold for every input, for all time.

Documented like a textbook

Each module's header explains what it is, when to use it, and its gotchas, and pairs with this site's course, glossary and playground, where you can simulate library code in your browser.

Learn the patterns first

New to a building block? The RTL Recipes explain each one, run live in your browser, and link straight back to the verified module here, so you can understand the pattern, then ship the packaged version.

Two-flop synchronizer

Safely bring an asynchronous signal into your clock domain.

Button debouncer

Reject the mechanical bounce on a switch or button.

Edge detector

Turn a level into a one-clock pulse on its rising (or falling) edge.

Clock divider (do it with an enable)

Run logic at a slower rate without gating the clock.

One-hot state machine

Give every state its own flip-flop for fast, readable FSMs.

PWM generator

Dim an LED or drive a motor with a duty-cycled pulse.

Synchronous FIFO

Buffer a stream between a producer and a consumer on one clock.

UART transmitter

Send a byte down a wire, one start bit, eight data bits, one stop bit.

Gray-code converter

Count so that only one bit ever changes at a time.

SPI master

Clock a byte out to a peripheral, MSB-first, in SPI mode 0.

CRC-8 (serial)

Catch transmission errors with a cyclic redundancy check.

Round-robin arbiter

Share one resource fairly among many requesters.

UART receiver

Recover a byte from a serial line with no shared clock.

Asynchronous FIFO

Move a data stream safely between two independent clocks.

Skid buffer

A valid/ready pipeline register that keeps full throughput under backpressure.

Priority encoder

Find the lowest set bit: index plus a valid flag.

Barrel shifter

Shift by a variable amount in a single cycle.

LFSR (pseudo-random)

Cheap pseudo-random numbers from a handful of XOR gates.

Modules, v0.2.0

ModuleWhat it isCost*
CDC
lfpga_sync_bitN-flop synchronizer for one async level bit2 FF
lfpga_sync_pulseToggle-based pulse crossing, either direction2 LUT4 + 4 FF
lfpga_reset_syncReset: async assert, sync deassert2 FF
FIFOs & streams
lfpga_fifo_syncSynchronous show-ahead FIFO with count154 LUT4 + 145 FF
lfpga_fifo_asyncDual-clock FIFO, gray pointers (Cummings)154 LUT4 + 168 FF
lfpga_skid_buffervalid/ready register slice, full throughput16 LUT4 + 18 FF
lfpga_arbiter_rrRound-robin arbiter, one-hot grant18 LUT4 + 4 FF
Serial
lfpga_uart_txUART transmitter, 8N1, valid/ready48 LUT4 + 24 FF
lfpga_uart_rxUART receiver, mid-bit sampling, glitch reject63 LUT4 + 32 FF
lfpga_spi_masterSPI master, mode 0, full duplex32 LUT4 + 27 FF
lfpga_i2c_masterI2C master, 7-bit, open-drain123 LUT4 + 38 FF
Utilities
lfpga_popcountCount set bits (combinational tree)12 LUT4
lfpga_priority_encoderLowest-set-bit: one-hot + index18 LUT4
lfpga_onehot_muxAND-OR mux for one-hot selects24 LUT4
lfpga_edge_detectRise/fall/toggle pulses3 LUT4 + 1 FF
lfpga_debounceDebouncer with press/release events44 LUT4 + 25 FF
lfpga_pwmPWM, glitch-free duty updates33 LUT4 + 17 FF
lfpga_clkdiv_fracFractional-rate clock enable27 LUT4 + 16 FF
Fixed-point & neural
lfpga_fix_resizeRequantize: shift + round + saturate31 LUT4
lfpga_fix_multSigned fixed-point multiply, resized240 LUT4
lfpga_fix_addFixed-point add/sub, saturating48 LUT4
lfpga_macSigned multiply-accumulate (the NN atom)326 LUT4 + 32 FF
lfpga_reluReLU / leaky / clipped + requantize129 LUT4
lfpga_barrel_shifterSingle-cycle logical/arith shift139 LUT4
lfpga_bitreverseReverse bit order0 LUT4
Math & bus
lfpga_crcParallel CRC, any polynomial, word/clock17 LUT4 + 16 FF
lfpga_lfsrMaximal-length LFSR (XAPP052 taps)1 LUT4 + 16 FF
lfpga_grayBinary ↔ Gray converters3 LUT4
lfpga_axil_bridgeAXI4-Lite slave → simple register bus5 LUT4 + 80 FF

*Generic Yosys synth -lut 4 mapping at default parameters, the same estimate the playground's synth button gives you. All sources on GitHub, v0.5.0 release.

Roadmap

Want a module prioritized? Open an issue or drop a line in the tool request box, the roadmap is ranked by real requests.

libfpga on GitHub →

Browse this and other open cores in the FPGA core registry.

Companion example

fpga-neuron: an educational walkthrough from gradient descent to synthesized gates, a neural network that is pure combinational logic, exhaustively verified.

libfpga-myhdl: the same kind of building blocks written in MyHDL (Python), each with a pytest suite and a Verilog/VHDL conversion check. Try MyHDL in the playground.