How fast is the division?

i once had to make a short assembler code to divide by numbers that have no power 2. My solution was to subtract the divisor into cycles, and the number of cycles was the actual result. Is there something faster? What is the usual way to figure this out?

+4
source share
2 answers

Repeat subtraction is a dangerously inefficient division method. In the worst case, N-bit division may take O(2**N) subtractions !!

@Johannes answer has a link that gives you algorithms that work much better.

If I was asked to implement division in assembler, I would probably conduct an extensive search for an existing library of numerical routines. This is a problem that requires a lot of experience to develop optimal code.

EDIT : in response to OP comment:

It's just that I am doing some C ++ program now, and I decide whether to use separation to solve one problem or do something else to make it faster.

I suggest you just use division and leave it to the C ++ compiler to generate the most efficient sequence of commands to achieve the desired result for your specific target platform.

+2
source

There are many named algorithms and is described in detail on Wikipedia .

+2
source

Source: https://habr.com/ru/post/1300615/


All Articles