Vote UpVote

Integer division by constant

The Programming Works – If divisor is fixed, the division operation can be replaced by multiplication by a reciprocal; the idea is very simple: x / d = x * (1/d); since d is fixed we can precompute 1/d and use faster multiplication operation. This trick works for integer division, with some additional complications. For example, the next function is identical to division by 5 for all 32-bit dividends: function Div5(Dividend: LongWord): LongWord; const Mult = $CCCCCCCD; PostSh = 2; asm MOV EDX,Mult MUL EDX MOV EAX,EDX SHR EAX,PostSh end; It turns out that 32-bit ...
Favorite? Off-Topic? Serg @ 2016-02-01 20:45


Visits: 1190
Votes: 0
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News


Please login or register to use this functionality.
(click on this box to dismiss)