You can decompose a larger division into several pieces, which are divided into fewer bits. As another poster has already been mentioned, the algorithm can be found in Knuth's TAOCP.
However, no need to buy a book!
The hackers delight website has code that implements the algorithm in C. It is written for 64-bit unsigned sections using only 32-bit arithmetic, so you cannot directly cut the code. To get from 64 to 128 bits, you need to expand all types, masks and constants by two, for example. short becomes int, a 0xffff becomes 0xffffffffll ect.
After this simple easy change, you can do 128-bit divisions.
The code is here: http://www.hackersdelight.org/HDcode/divlu.c (it can get much worse in the web browser due to the end of the line. Code and open it with notepad or so).
Since your largest values ββonly require 96 bits, one of the 64-bit divs will always return zero, so you can even simplify the code a bit.
Oh - and before I forget this: The code only works with unsigned values. To convert from signed to unsigned separation, you can do something like this (pseudo-code style):
fixpoint Divide (fixpoint a, fixpoint b) {
The site itself deserves attention: http://www.hackersdelight.org/
Hope this helps.
Btw is a good task you are working on. Do you mind telling us what you need for a fixed-point library?
Btw - The usual shift and subtraction algorithm for division will work.
If you are targeting x86, you can implement it using MMX or SSE. The algorithm relies only on primitive operations, so it can execute pretty quickly.
Nils pipenbrinck
source share