VHDL and Division vs Shifting

This is a short post.  Tools like XST do support division by powers of two for numeric types in VHDL.  However, VHDL defines division in a mathematically consistent way, which is not the same as C.  

 \frac{-x}{y} = -(\frac{x}{y})

This is the issue — the above infers a round toward zero behavior.  After all,  \frac{1}{2} rounds to  0 , so -(\frac{1}{2}) should be the same as  -(0) .  At the same time, \frac{-1}{2} should be the same algebraically.  However, in C programming, \frac{-1}{2} would round down to -1.

Notice that the schematic from a simple division by constant 8 infers some logic to perform the round toward zero that is implied by VHDL.

Many users will expect the C-style truncation, or round toward negative infinity, as this is a simple renaming of bits and infers no physical logic.

This entry was posted in VHDL. Bookmark the permalink.

Comments are closed.