LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace quotient and Remainder with Scale by power 2

An algorithm like this might be of use: http://bknpk.no-ip.biz/my_web/divide_by_constnat/divide_by_constant.html

 

He shows what you'd have to do to divide by 10:

 x * (2^31+2)/10 >> 31

Efficient Divide.png

 

The above snippet worked for me, though I didn't do elaborate testing of any kind. If you know how many digits you'll need to support, you can create a look-up table to correlate input size to the "magic" constants you'll need for the above algorithm.

You'd have to code it up and try it out to be sure it really is more efficient than the Xilinx Coregen Divide though Smiley Happy

 

EDIT: Updated for clarity

Cheers!

TJ G
0 Kudos
Message 11 of 12
(697 Views)

Ooops: The above doesn't work. I made some changes to pretty it up, and ended up breaking it. Try this one:

Efficient Divide.png

Cheers!

TJ G
0 Kudos
Message 12 of 12
(680 Views)