Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21611 Discussions

how to perform large number(128bit) division

Altera_Forum
Honored Contributor II
2,346 Views

Hi all, 

 

I'm designing a system using simple LPM divider, it works fine below 64 bits number, but when the number is larger than 64 bits, it gives me an error stating that LPM cannot support more than 64 bits.  

 

My system requires at least 128-bit number, I wonder how can this be done. 

 

Thanks and Regards, 

ty6
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
1,366 Views

You can write your own function using a serial approach for 'long divide'. It will take up to 128 clocks (and a few) to calculate the result. It will use reasonably few rersources compared to a direct combinatorial approach. 

If you need speed that you have to pipeline every stage which will be a lot more work.
0 Kudos
Altera_Forum
Honored Contributor II
1,366 Views

You may take this as a starting-point: 

 

http://www.edaboard.com/thread116890.html (post# 7!) 

 

Thomas
0 Kudos
Altera_Forum
Honored Contributor II
1,366 Views

You can use Newton method for computation of 1/a and then, use it for division computation. 

 

In case if you computed x=1/a with 64 bit precision, you can improve it to 128 bit precision with simple formula: y=2*x-x*x*a. 

 

You can generally start with 4 bit 1/a approximation and apply this formula 5 times, then you can implement everything from the scratch without megawizards on integer arithmetic (do not forget to scale your intermediate data!!) and then convert to floating point. 

 

Sure you can make it fast enough with pipelining. I did it once for my Stratix III project and achieve about 250 MHz, probably it can be faster but it was enough for me.
0 Kudos
Reply