Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Division in verilog

Tags:

verilog

I am teaching myself verilog. The book I am following stated in the introduction chapters that to perform division we use the '/' operator or '%' operator. In later chapters it's saying that division is too complex for verilog and cannot be synthesized, so to perform division it introduces a long algorithm.

So I am confused, can't verilog handle simple division? is the / operator useless?

like image 605
StuckInPhDNoMore Avatar asked Jul 30 '12 16:07

StuckInPhDNoMore


People also ask

How do you divide in Verilog?

Division using '/' is possible in verilog. But it is not a synthesizable operator. Same is the case for multiplication using '*'. There are certain algorithms to perform these operations in verliog, and they are used if the code needs to be synthesizable.

Can you divide in VHDL?

Division in fixed point There is a simple trick that can be used if you need to divide a number by a constant. The trick is to use a multiplication instead of a division. A/B you have to simply implement A * (1/B). The division by 32.768 is simply implemented by right shift of 15 positions.


1 Answers

It all depends what type of code you're writing.

If you're writing code that you intend to be synthesised, that you intend to go into an FPGA or ASIC, then you probably don't want to use the division or modulo operators. When you put any arithmetic operator in RTL the synthesiser instances a circuit to do the job; An adder for + & -; A multiplier for *. When you write / you're asking for a divider circuit, but a divider circuit is a very complex thing. It often takes multiple clock cycles, and may use look up tables. It's asking a lot of a synthesis tool to infer what you want when you write a / b.

(Obviously dividing by powers of 2 is simple, but normally you'd use the shift operators)

If you're writing code that you don't want to be synthesised, that is part of a test bench for example, then you can use division all you want.

So to answer your question, the / operator isn't useless, but you have be concious of where and why you're using it. The same is true of *, but to a lesser degree. Multipliers are quite expensive, but most synthesisers are able to infer them.

like image 164
Paul S Avatar answered Sep 19 '22 16:09

Paul S