• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language Verilog
  • License
    GNU Lesser Genera...
  • Created over 10 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fixed Point Math Library for Verilog
Verilog Fixed point math library 

Original work by Sam Skalicky, originally found here:
http://opencores.org/project,fixed_point_arithmetic_parameterized

Extended, updated, and heavily commented by Tom Burke ([email protected])

This library includes the basic math functions for the Verilog Language, 
for implementation on FPGAs.

All units have been simulated and synthesized for Xilinx Spartan 3E devices 
using the Xilinx ISE WebPack tools v14.7

These math routines use a signed magnitude Q,N format, where N is the total 
number of bits used, and Q is the number of fractional bits used.  For 
instance, 15,32 would represent a 32-bit number with 15 fractional bits, 
16 integer bits, and 1 sign bit as shown below:

|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

This library contains the following modules:
qadd.v      - Addition module; adds 2 numbers of any sign.
qdiv.v      - Division module; divides two numbers using a right-shift and 
                subtract algorithm - requires an input clock
qmult.v     - Multiplication module; purely combinational for systems that 
                will support it
qmults.v    - Multiplication module; uses a left-shift and add algorithm - 
                requires an input clock (for systems that cannot support 
				the synthesis of a combinational multiplier)
Test_add.v  - Test fixture for the qadd.v module
Test_mult.v - Test fixture for the qmult.v module
TestDiv.v   - Test fixture for the qdiv.v module
TestMultS.v - Test fixture for the qmults.v module

These math routines default to a (Q,N) of (15,32), but are easily customizable 
to your application by changing their input parameters.  For instance, an 
unmodified use of (15,32) would look something like this:

     qadd my_adder(
          .a(addend_a),
          .b(addend_b),
          .c(result)
	  );

To change this to an (8,23) notation, for instance, the same module would be 
instantiated thusly:

     qadd #(8,23) my_adder(
          .a(addend_a),
          .b(addend_b),
          .c(result)
	  );
		  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following is a description of each module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qadd.v - A simple combinational addition module.  

sum = addend + addend

Input format: 
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Inputs:
     a - addend 1
     b - addend 2

Output format:
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Output:
     c - result
	 
NOTE:  There is no error detection for an overflow.  It is up to the designer 
         to ensure that an overflow cannot occur!!

Example usage:
     qadd #(Q,N) my_adder(
          .a(addend_a),
          .b(addend_b),
          .c(result)
	  );
	 
For subtraction, set the sign bit for the negative number. (subtraction is 
the addition of a negative, right?)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qmult.v - A simple combinational multiplication module.  

Input format: 
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Inputs:
     i_multiplicand - multiplicand
	 i_multiplier   - multiplier

Output format:
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Output:
     o_result - result
	 ovr      - overflow flag
	 
NOTE:  This module assumes a system that supports the synthesis of 
       combinational multipliers.  If your device/synthesizer does not 
       support this for your particular application, then use the 
       "qmults.v" module.

NOTE:  Notice that the output format is identical to the input format!  To 
       properly use this module, you need to either ensure that you maximum 
	   result never exceeds the format, or incorporate the overflow flag 
	   into your design

Example usage:
     qmult #(Q,N) my_multiplier(
          .i_multiplicand(multiplicand),
          .i_multiplier(multiplier),
          .o_result(result),
	  .ovr(overflow_flag)
	  );
	 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qmults.v - A multi-clock multiplication module that uses a left-shift 
           and add algorithm.
		   
result = multiplicand x multiplier

Input format: 
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Inputs:
     i_multiplicand - multiplicand
	 i_multiplier   - multiplier
	 i_start        - Start flag; set this bit high ("1") to start the
                          operation when the last operation is completed.  This 
                          bit is ignored until o_complete is asserted.
	 i_clk          - input clock; internal workings occur on the rising edge

Output format:
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Output:
     o_result_out - result
	 o_complete   - computation complete flag; asserted ("1") when the 
	                operation is completed
	 o_overflow   - overflow flag; asserted ("1") to indicate that an 
	                overflow has occurred.
	 
NOTE:  This module is "time deterministic ." - that is, it should always 
       take the same number of clock cycles to complete an operation, 
       regardless of the inputs (N+1 clocks)

NOTE:  Notice that the output format is identical to the input format!  To 
       properly use this module, you need to either ensure that you maximum 
       result never exceeds the format, or incorporate the overflow flag 
       into your design

Example usage:
     qmults #(Q,N) my_multiplier(
          .i_multiplicand(multiplicand),
          .i_multiplier(multiplier),
	  .i_start(start),
	  .i_clk(clock),
          .o_result(result),
	  .o_complete(done),
	  .o_overflow(overflow_flag)
	  );
	 
The qmults.v module begins computation when the start conditions are met: 
     o_complete == 1'b1;
     i_start == 1'b1;


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qdiv.v - A multi-clock division module that uses a right-shift 
           and add algorithm.

quotient = dividend / divisor

Input format: 
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Inputs:
     i_dividend  - dividend
	 i_divisor   - divisor
	 i_start     - Start flag; set this bit high ("1") to start the
                       operation when the last operation is completed.  This 
                       bit is ignored until o_complete is asserted.
	 i_clk       - input clock; internal workings occur on the rising edge

Output format:
|1|<- N-Q-1 bits ->|<--- Q bits -->|
|S|IIIIIIIIIIIIIIII|FFFFFFFFFFFFFFF|

Output:
     o_quotient_out - result
     o_complete     - computation complete flag; asserted ("1") when the 
                      operation is completed
     o_overflow     - overflow flag; asserted ("1") to indicate that an 
                      overflow has occurred.
	 
NOTE:  This module is "time deterministic ." - that is, it should always 
       take the same number of clock cycles to complete an operation, 
       regardless of the inputs (N+Q+1 clocks)

NOTE:  Notice that the output format is identical to the input format!  To 
       properly use this module, you need to either ensure that you maximum 
       result never exceeds the format, or incorporate the overflow flag 
       into your design

Example usage:
     qdiv #(Q,N) my_divider(
          .i_dividend(dividend),
          .i_divisor(divisor),
	  .i_start(start),
	  .i_clk(clock),
          .o_quotient_out(result),
	  .o_complete(done),
	  .o_overflow(overflow_flag)
	  );
	 
The qdiv.v module begins computation when the start conditions are met: 
     o_complete == 1'b1;
     i_start == 1'b1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suggestions, Kudos, or Complaints?  Feel free to contact me - but remember, 
this stuff is free!



More Repositories

1

8051

8051 core
Verilog
75
star
2

dma_axi

AXI DMA 32 / 64 bits
Verilog
69
star
3

ethmac

Ethernet MAC 10/100 Mbps
Verilog
67
star
4

round_robin_arbiter

round robin arbiter
Verilog
58
star
5

jpegencode

JPEG Encoder Verilog
Verilog
51
star
6

sparc64soc

OpenSPARC-based SoC
Verilog
42
star
7

xge_mac

Ethernet 10GE MAC
Verilog
39
star
8

dma_ahb

AHB DMA 32 / 64 bits
Verilog
36
star
9

can

CAN Protocol Controller
Verilog
35
star
10

video_stream_scaler

Video Stream Scaler
Verilog
33
star
11

apbi2c

APB to I2C
Verilog
33
star
12

arm4u

ARM4U
VHDL
32
star
13

verilog_cordic_core

configurable cordic core in verilog
Verilog
32
star
14

turbo8051

turbo 8051
Verilog
29
star
15

i2c

I2C controller core
Verilog
27
star
16

mcs-4

4004 CPU and MCS-4 family chips
Verilog
25
star
17

jtag

JTAG Test Access Port (TAP)
Verilog
23
star
18

dvb_s2_ldpc_decoder

DVB-S2 LDPC Decoder
Verilog
23
star
19

embedded_risc

Embedded 32-bit RISC uProcessor with SDRAM Controller
Verilog
21
star
20

uart16550

UART 16550 core
Verilog
20
star
21

ha1588

Hardware Assisted IEEE 1588 IP Core
Verilog
20
star
22

freecores.github.io

Freecores website
CSS
18
star
23

y80e

Y80e - Z80/Z180 compatible processor extended by eZ80 instructions
Verilog
17
star
24

axi_master

Generic AXI master stub
Verilog
17
star
25

video_systems

Video compression systems
Verilog
16
star
26

mips_16

Educational 16-bit MIPS Processor
Verilog
16
star
27

theia_gpu

Theia: ray graphic processing unit
Verilog
16
star
28

ddr3_sdram

DDR3 SDRAM controller
Verilog
15
star
29

mmu180

MMU for Z80 and eZ80
Verilog
15
star
30

ps2

PS2 interface
Verilog
15
star
31

zpu

ZPU - the worlds smallest 32 bit CPU with GCC toolchain
VHDL
15
star
32

zx_ula

ULA chip for ZX Spectrum
Verilog
15
star
33

zet86

Zet - The x86 (IA-32) open implementation
C
15
star
34

wb_dma

WISHBONE DMA/Bridge IP Core
Verilog
14
star
35

uart2spi

UART To SPI
Verilog
14
star
36

1000base-x

1000BASE-X IEEE 802.3-2008 Clause 36 - Physical Coding Sublayer (PCS)
Verilog
14
star
37

usbhostslave

USB 1.1 Host and Function IP core
Verilog
13
star
38

wb_builder

WISHBONE Builder
Perl
13
star
39

ofdm

OFDM modem
VHDL
13
star
40

pci

PCI bridge
Verilog
13
star
41

double_fpu

double_fpu_verilog
Verilog
13
star
42

sha3

SHA3 (KECCAK)
Verilog
12
star
43

nova

H.264/AVC Baseline Decoder
Verilog
12
star
44

robust_axi2ahb

Generic AXI to AHB bridge
Verilog
12
star
45

mmuart

Simple RS232 UART
Verilog
12
star
46

udp_ip__core

UDP/IP Core
VHDL
12
star
47

fpga-median

FPGA-based Median Filter
Verilog
12
star
48

reed_solomon_decoder

Reed Solomon Decoder (204,188)
Verilog
12
star
49

tiny_aes

AES
Verilog
12
star
50

mac_layer_switch

100 MB/s Ethernet MAC Layer Switch
Verilog
11
star
51

ahb_master

Generic AHB master stub
Verilog
11
star
52

wb_z80

Wishbone High Performance Z80
Verilog
10
star
53

z80soc

Z80 System on Chip
VHDL
10
star
54

robust_axi_fabric

Generic AXI interconnect fabric
Verilog
10
star
55

xge_ll_mac

Ethernet 10GE Low Latency MAC
Objective-C
10
star
56

an-fpga-implementation-of-low-latency-noc-based-mpsoc

NoC based MPSoC
Verilog
10
star
57

simple_spi

SPI core
Verilog
10
star
58

usb11_phy_translation

USB 1.1 PHY (VHDL)
VHDL
10
star
59

avr_core

AVR Core
10
star
60

rtf8088

rtf8088
Verilog
9
star
61

spartan6_pcie

Spartan 6 PCIexpress card
9
star
62

pipelined_fft_64

Pipelined FFT/IFFT 64 points processor
Verilog
9
star
63

bluespec-reedsolomon

Bluespec SystemVerilog Reed Solomon Decoder
Bluespec
9
star
64

aes_decrypt_fpga

AES Decryption Core for FPGA
SystemVerilog
9
star
65

fpu_double

FPU Double VHDL
VHDL
9
star
66

bluespec-h264

Bluespec H.264 Decoder
Bluespec
9
star
67

bluespec-80211atransmitter

Bluespec 802.11a Transmitter
Bluespec
9
star
68

usb_phy

USB 1.1 PHY
Verilog
8
star
69

sdram_controller

Scratch DDR SDRAM Controller
VHDL
8
star
70

fpu

Floating Point Unit
Verilog
8
star
71

sgmii

SGMII
Verilog
8
star
72

8b10b_encdec

8b10b Encoder/Decoder
VHDL
8
star
73

pwm

PWM
Verilog
8
star
74

openjtag-project

Open JTAG project
VHDL
8
star
75

pid_controller

PID controller
Verilog
8
star
76

udp_ip_stack

1G eth UDP / IP Stack
VHDL
8
star
77

aes-128_pipelined_encryption

AES-128 Encryption
Verilog
8
star
78

wdsp

DSP WishBone Compatible Cores
Verilog
8
star
79

reed_solomon_codec_generator

Reed-Solomon Codec Generator
C++
8
star
80

spacewire

SpaceWire
Verilog
7
star
81

yac

YAC - Yet Another CORDIC Core
VHDL
7
star
82

ws2812

WS2812 RGB LED string driver
VHDL
7
star
83

amber

Amber ARM-compatible core
Verilog
7
star
84

cheap_ethernet

Cheap Ethernet interface
Verilog
7
star
85

6809_6309_compatible_core

6809 and 6309 Compatible core
Verilog
7
star
86

robust_axi2apb

Generic AXI to APB bridge
Verilog
7
star
87

divider

Hardware Division Units
Verilog
7
star
88

plasma

Plasma - most MIPS I(TM) opcodes
C
7
star
89

rtc

No description
Verilog
7
star
90

i2c_master_slave_core

I2C master/slave Core
SystemVerilog
7
star
91

async_8b10b_encoder_decoder

Async 8b/10b enc/dec
VHDL
7
star
92

ethernet_tri_mode

10_100_1000 Mbps tri-mode ethernet MAC
Verilog
7
star
93

ag_6502

ag_6502 soft core with phase-level accuracy
Verilog
7
star
94

ata

OCIDEC (OpenCores IDE Controller)
VHDL
7
star
95

i2cslave

I2C Slave
Verilog
7
star
96

ahb_slave

Generic AHB slave stub
Verilog
7
star
97

openmsp430

openMSP430
Verilog
7
star
98

spacewire_light

SpaceWire Light
VHDL
6
star
99

yadmc

Asynchronous WISHBONE-compatible SDRAM controller
Verilog
6
star
100

genesys_ddr2

DDR2 mem controller for Digilent Genesys Board
Verilog
6
star