tomverbeure / math

SpinalHDL Hardware Math Library
BSD 2-Clause "Simplified" License
77 stars 14 forks source link

Introduction

This project contains a library of math-related hardware units.

Right now, it contains only "Fpxx" units: floating point with a user-programmable number of exponent and mantissa.

Table of Contents

Getting Started

This library is using SpinalHDL.

If you want to run some of the code here, you first need to install that.

Installation instructions can be found here.

Once one, run ./run.sh to generate whichever unit you want to test. Edit this file if you want to run a different test. (All of this could be streamlined with a better Makefile...)

Then run make sim to run a test.

Fpxx

The Fpxx library is one that supports floating point operations for which the exponent and mantissa can be specified at compile time.

The primary use of this library is for FPGA projects that need floating point, but don't necessarily need all the features and precision of 32-bit standard floating point operations. By reducing the size of the mantissa and exponent, the hardware of some floating point operations can be made to map directly onto the hardware multipliers of the DSPs that are often present in today's FPGAs, and the maximum clock speed can be increased significantly.

For example, many FPGAs support 18x18 bit multiplications. By restricting the size of the mantissa, a single hardware multiplier may be sufficient to implement the core operation of the a floating point multiplier.

Goals:

Non-goals:

FpxxAdd

FpxxMul

FpxxDiv

FpxxSqrt

FpxxRSqrt

Math Related Literature

Reduced Precision Floating Point

Articles on two-complement floating point

Division

Square Root and Reciprocal Square Root

Leading Zero Counter (LZC) and Leading Zero Anticipor (LZA)

Sin/Cos Calculation