How Flux works

Hardware functions become circuits. Everything else stays C++.

Architecture

Source fileC++ with __fpga functions
Language frontendBuilt on Clang
Host codeOrdinary C++, compiled through LLVM for a processor
Flux Hardware IRTarget-neutral, verified, printable
Circuit loweringFlattening and optimization
  • SimulationGenerates a C++ model you drive from a testbench
  • Logic and mappingBit netlist, optimization, hard blocks, look-up tables
  • Netlist exportVerilog; other formats through Yosys
  • Device backendsPacking, placement, routing and image encoding for Gowin, Lattice and AMD parts

Not built. Intended to share the same understanding of a design:

  • Editor and static analysis
  • Waveform viewer
  • Analog (SPICE) simulation
Solid outlines are implemented in the current source tree, to differing depths. Dashed outlines are planned and have no implementation.

One design, stage by stage

A counter that blinks an LED.

blink.flux
__fpga void blink(clock clk, bits<1>& led) {
    bits<25> divider = 0;
    bits<1> ledState = 1;
    __onRise(clk) {
        if (divider == 13500000) {
            divider = 0;
            ledState = ledState ^ 1;
        } else {
            divider = divider + 1;
        }
    }
    led = ledState;
}

What the compiler understood.

flux --emit=hardware blink.flux
module @blink [sequential] {
    clock %clk
    output %led : u1
    state %divider : u25 [init=u25 0]
    state %ledState : u1 [init=u1 1]
    on_rise %clk {
        if equal<bit> %divider, i32 13500000 {
            next %divider = u25 0
            next %ledState = xor<i32> %ledState, i32 1
        }
        else {
            next %divider = add<i32> %divider, i32 1
        }
    }
    drive %led = %ledState
}

Mapped to look-up tables (shortened).

flux --emit=lut --stats blink.flux
stats @blink: cells 16 -> 13
    Boolean gates 323 -> 147
    Boolean depth 52 -> 9
    LUTs 55 -> 50
    LUT levels 7 -> 3
    optimize_for=speed
    candidate 1/1

lutnet @blink [k=6, luts=50, depth=3] {
    %s26 = lut<4, 0x0001> %s0 %s1 %s2 %s3
    %s27 = lut<4, 0x0040> %s4 %s5 %s6 %s7
    %s28 = lut<4, 0x4000> %s8 %s9 %s10 %s11
    %s29 = lut<4, 0x8000> %s12 %s13 %s14 %s23
    %s30 = lut<4, 0x8000> %s26 %s27 %s28 %s29
    %s31 = lut<4, 0x4000> %s17 %s18 %s19 %s22
    %s32 = lut<6, 0x0000000800000000> %s15 %s16 %s20 %s21 %s24 %s31
    %s33 = lut<3, 0x15> %s0 %s30 %s32
    ...
}

Ports bound to board pins.

blink_board.flux
#include "blink.flux"
#include "src/flux/boards.hpp"

int main() {
    flux::boards::TangNano20K board;
    auto clk = board.onBoardClock();
    auto led = board.leds(0, 1);

    auto design = blink(clk, led);
    board.instantiate(design);
    return 0;
}

Placed, routed and written by Flux.

flux --emit=fs --board=tang-nano-20k --top=blink blink_board.flux
native-fs @blink [GW2AR-18C]:
    67 LUTs,
    26 storage elements,
    carry_blocks=0,
    dsp_blocks=0,
    bsram_blocks=0,
    1 outputs,
    1 clocks,
    8147 configuration fuses;
    validated .fs image at blink.fs
Real output from Flux 0.1.0.

Every stage can be printed

  1. Flux sourceC++ with __fpga functions.flux
  2. Hardware IRRegisters, wires and clocked updates--emit=hardware
  3. Circuit and logicFlattened and optimized netlist--emit=optimized-circuit
  4. LUT mappingBoolean logic as look-up tables--emit=lut
  5. Place and routeCells assigned to a device--emit=routed
  6. Configuration imageSupported boards only--emit=fs

One shared representation

Simulation and implementation start from the same Hardware IR. That is not proof of correct behavior on silicon; timing and wiring need their own checks.

Architecture in the docs