Introduction

A C++ based Hardware Construction Library with a focus on flexibility and high reusability.

Gatery is a library for building high density integrated logic circuits i.e. computer chips. Inspired by concepts of the software development domain, it adresses many of the issues that the de-facto industry standard languages VHDL and Verilog suffer from. With Gatery and the associated tools, it is possible to design logic circuits that are much more flexible and reusable at a fraction of the usual development cost. Designs implemented in Gatery can be converted or exported to VHDL to seamlessly integrate with existing codebases, tools and workflows. Best of all, Gatery is Open Source and free for personal and commercial use.

See code on Github See tutorial

Benefits

Strong Meta Programming Focus

Meta Programming is the concept of not directly writing a computer program, but rather writing an algorithm that, given some configuration, generates a computer program for that configuration. In the software domain, it allows to achieve a much better trade-off between code reusability and code performance. Similarly, in the domain of integrated logic circuits, it is essential to improving design reusability without sacrificing speed or area. In Gatery, like in all Hardware Construction Languages/Libraries, the meta programming ability comes from the host language. Since the logic circuit design arises from the execution of Gatery design, all control flow mechanisms can be used to affect the final logic design. What templates are to C++, the entire might of C++ is to Gatery. Any input or configuration file can be read, any computation be performed, to determine how the hardware design is to be built. The freedom to control the logic design creation programatically is inherent to Gatery and its entire language stack of components. All benefits in terms of productivity and reusablity propagate from the smallest component to the biggest IP-cores.

Mutable Variable Paradigm

All signals in Gatery follow the paradigm of mutable variables, as is common in programming languages. This reduces clutter constructing a signal through a sequence of instructions, such as composing a sum one summand at a time. But it also has a strong synergy with the meta programming aspect of Gatery as the behavior of a design can easily changed by modifying an existing variable.

outStream.valid = true;

// We need input A
IF (!inStreamA.valid)
    outStream.valid = false;

// We also need input B
IF (!inStreamB.valid)
    outStream.valid = false;

// ...
BVec sum(const std::vector<BVec> &data) {
    BVec res = "10b0";
    for (const auto &v : data)
        res += v;
    return res;
}

Clean Syntax

The syntax of Gatery is much less verbose than in traditional HDLs. Reasonable defaults help prevent clutter and prevent mistakes. Clocks and resets are controlled via scopes alleviating the need to specify them for every register.

BVec histogram(BVec idx, Bit inc) {
    // All registers derive clock
    // from a global clock scope

    Memory<BVec> mem(32, 8_b);
    BVec bucket = mem[idx];

    // Automatic register retiming and
    // read modify write hazard detection
    IF (inc)
        mem[idx] = bucket + 1;

    // Register to make read synchronous
    bucket = reg(bucket);
    return bucket;
}

Full Control

Even though Gatery tries to facilitate logic circuit design with concepts and reasonable defaults that mimic in many places the mindsets of software developers, Gatery is not High-Level Synthesis. The designer retains full control over every aspect of the design, without having to wrestle with the complicated inference mechanisms of HLS. Whats more, oftentimes a first draft can be designed and then, where necessary, be refined and optimized, all without having to switch from HLS to HDL.

    // Perform some iterations of the Binary GCD
    // algorithm with some dirty bit tricks
    for (size_t i = 0; i < iterationsPerClock; ++i) {
        IF (a != b) {
            const Bit a_odd = a.lsb();
            const Bit b_odd = b.lsb();

            IF (!a_odd) a >>= 1;
            IF (!b_odd) b >>= 1;

            IF (!a_odd & !b_odd) d += 1u;

            IF (a_odd & b_odd) {
                BVec abs = cat('0', a) - cat('0', b);
                a = mux(abs.msb(), {a,b});
                b = (abs(0, b.size()) ^ abs.msb()) >> 1;
            }
        }
    }

Open License

Gatery is free software under the LGPL license. This allows anyone to freely use it, even for commercial closed source projects, as long as modifications to Gatery itself are published under LGPL. Contributions and feedback are very welcome.

See license

Industry Backed

Gatery is being developed and used by Synogate, a company specializing on highly flexible IP-core development. Synogate is comitted to Gatery, by using it for commercial development their IP-cores but also by advancing the Gatery through steady improvements to the core library and standard components library.

Synogate

Some Examples

Coming soon

Sha2 Cryptographic Hash

In this example, we will look at the Sha2 cryptographic hash function. The hash function itself is purely combinatorial, making this an excellent introduction to basic combinatorial signal operations.

Coming soon

FAST Keypoint Detector

Keypoint detectors are used in Computer Vision for 3D reconstruction, SLAM, and object tracking (amongst others). FAST is one such keypoint detector, commonly used in realtime and robotics settings due its low computational burden. In this example, we implement FAST as a digital circuit, showing how a stream of pixels can be processed.

Coming soon

Generic Tree-Reduce

This example considers the issue of reducing multiple signals into one, such as when summing together a list of summands. Tree structures significantly reduce critical path lengths, and we will show how C++ and it features in Gatery allow implementing the tree reduce concept in a generic way, such that it can be reused for all kinds of reductions.