1. Arithmetic Functions Resources

    Filters

    Filter By

  2. Basic Arithmetic Functions

    Arithmetic Functions Introduction

    Hardware design is complicated consisting of large number of mathematical computations. This is true for any vertical or application in real life. It can be used in creating designs for cryptography, to machine learning algorithms, image processing algorithms.

    These mathematical computations are made possible with the help of Arithmetic Functions and are very important for HW design. These arithmetic functions can be something simple like an addition, subtraction, multiplication, or something complicated like exponent, logarithms, and power functions. It is very important to develop efficient arithmetic functions for HLS, as unlike HW design there is a lack of detailing due to the nature of abstraction. Just like for HW design, HLS design is also bit accurate. Hence the design of Arithmetic functions should support bit accuracy as well as different datatypes supported by the high-level language.

    In this overview, we will look at some of the basic and frequently used Arithmetic functions specifically for HLS.

    Basic Arithmetic Functions

    Adders: Adders in HLS are synthesized when the high-level code has the ‘+’ symbol. The HLS tool synthesizes it using the LUT’s or DSP’s in FPGA’s and based on the basic library cells present in the technology node in ASIC. The type of adders synthesized is based on the tool and a few examples might be:

    • Half Adder
    • Full Adder
    • Carry Save Adder
    • Carry Look Ahead Adder
    • Ripple Carry Adder

    Subtractors: Subtractors in HLS are synthesized when the high level code has ‘-‘ symbol. It can be synthesized as a subtractor component or as a combination of adder with not gate, following this simple logic:

    A-B= A+~B+1

    Multipliers: Subtractors in HLS are synthesized when the high level code has ‘*‘ symbol. They are synthesized in FPGA’s mainly using DSP’s and using basic library cells in ASIC. The type of multiplier being synthesized is once again dependent on the tool.

    • Sometimes the multipliers can be synthesized into a bunch of shifters.
    • Wallace Tree Multiplier
    • Booth’s multiplication algorithm

    Multipliers can be pipelined or not based on the need of the designer.

    HLS designing needs to be area, power, and performance efficient. HLS tools synthesize the above operations/functions based on highest efficiency of PPA metrics.

    Datatypes

    HLS needs to be quite efficient in hardware and hence uses bit accurate datatypes to model their designs. These datatypes are generally modelled based on Algorithmic C or SystemC datatypes. A few of them are:

    • Int (signed or unsigned)
    • Floating Point Representation
    • Fixed Point Representation

    These datatypes need some utility functions pertaining to normalization of floating values or obtaining the sign bit of fixed values.

    Few of them are:

    • isnan: check if value is NaN
    • iszero: check if value is 0
    • isnormal: Check if floating value is normalized
    • isinf: Check if value is inf or not
    • Get the signbit of a value
    • Normalize() which would normalized a floating value

    Dividers

    Dividers in HLS are synthesized with the ‘/’ symbol in high-level code. They are generally designed for integers, floating point, fixed point as well as complex datatypes. The inputs can be signed or unsigned and they generate the quotient. Dividers can be quite heavy in terms of performance and hence pipelined dividers can be used to improve performance.

    Constant division is generally optimized to shifters and adds/subtracts to help save on delay and area. Division and Multiplication in HLS should take into mind other important aspects:

    • Divide by zero should error out while simulation
    • Overflow of bits for both multiplication and division
    • Truncation
    • Rounding
    • Normalization of floating values

    Square Roots

    Square roots take in positive values in HLS and provide the output. They can have input or fixed-point inputs and provide corresponding outputs. The precision is once again dependent on the number of bits, overflow and rounding provided by the user.

    Shifters

    Shifters can be uni or bi directional. Uni-directional shift is when the shift value is positive. Bi-directional shift is when the shift value is positive or negative. Negative shift value would mean that the values are shifted in the opposite direction. This is based on the SystemC coding standards.

    CORDIC

    CORDIC stands for coordinate rotation digital computer and is called Volder’s algorithm. CORDIC is used primarily in hardware to compute trigonometric functions, exponential, logarithmic functions, power functions. They are light on hardware usage especially in terms of multipliers and keep them to a minimum. They work with the help of Look up tables, rotations i.e. shifters, adders and subtractors. In HLS they are used for implementing the above-mentioned functions in fixed point or floating-point representation as they will help improve the area of those functions. Multiplication and division too can be done with the help of CORDIC algorithm.

    Trigonometric Functions

    Some designs would need the computation or values of trigonometric functions, which include:

    • Sin
    • Cos
    • Asin
    • Acos
    • Atan2

    These are important functions within trigonometry for HLS designing. Some HLS tools might have these functions as IP blocks designed specifically for hardware using CORDIC.

    Exponential Functions

    Exp/Exp2: The exp function evaluates the exponential of an argument x, i.e., the transcendental number 'e' raised to the power of x. The exp2 function evaluates the number 2 raised to the power of a fixed-point argument x. These could be implemented using CORDIC as well.

    Logarithmic Functions

    Log/Log 2: The 'log' function evaluates the natural logarithm of an argument x, i.e., the logarithm with transcendental number 'e' as its base. The log2 function evaluates the base 2 logarithm of argument x.These could be implemented using CORDIC as well.

    Power Function

    Pow: The power function evaluates the result of raising a number x to the power of another number y.

    Absolute Function

    Abs: The absolute value operation produces a positive result by negating values less than zero. The inputs should naturally be signed. An unsigned value will always be positive.

    Modulo and Reciprocal Function

    Modulo function provide the remainder of a divided value. Reciprocal provides 1/x where x is the input value. Both are generally implemented in HLS using dividers. Reciprocal function can be implemented using shifters as the numerator is constant.

    Conclusion

    We saw some of the arithmetic functions which are generally used in High Level Synthesis for hardware design. Since designers do not have the level of access which traditional RTL provides, the HLS tools play a major role in synthesizing of some of these functions. Designers can also improve the power, performance, and area metrics of these functions by leveraging CORDIC, shifters, adders (instead of multipliers) etc. HLS tools may also provide already designed functions which use the above-mentioned features to provide the highest efficiency in HW design.