In this post I talk about what is generic hardware, and how to make hardware designs generic.
What is generic hardware?
If you have experience in hardware design, you already know what I'm talking about. A generic hardware design is a design that is written so that it can be customized or specialized to match the user's needs. In fact, a generic design must be specialized before it can be synthesized and implemented.
A good comparison is C++ templates: C++ code that defines templates (like
list which can be used with different types, like
list<int>) is generic, and the compiler transforms this generic code into specialized instructions, so in our example there is one piece of code that is a specialized list of booleans implementation, and another one that is a specialized list of integers implementation.
Uses of generic hardware
Genericity is mostly used for flavors of an algorithm or characteristics of an implementation. The flavor of an algorithm: for example with cryptography you can have variants of SHA like SHA-256, SHA-384, SHA-512; or variants of AES with AES-128, AES-192, AES-256. Characteristics of an implementation: if you use a serial port it can have 7, 8, or 9-bit bytes, parity or not, one or two stop bits; if you implement a video decoder, it can support 8-bit pixels or 10-bit pixels; if you design a processor it can have 32-bit or 64-bit datapath and registers, etc.
Note that genericity is not the same as runtime configuration: you can create a piece of hardware (generic or not!) that supports different configurations, for example our Ethernet stack supports speeds of 10, 100, 1000Mbit/s at runtime.
Making hardware designs generic
Existing hardware description languages (like VHDL and Verilog) allow you to make hardware designs that are generic. To declare a generic entity in VHDL, the entity must begin with a
generic clause listing variables that are allowed to be configured. In Verilog, an entity is generic if it declares
parameters either in the module signature or in the module's body.