News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Divide by 100

Started by Grincheux, September 29, 2006, 08:22:58 AM

Previous topic - Next topic

stanhebben

Magic divide by 100 and then multiply should work well.

Tedd

Multiply first, then divide -- you lose bits the other way :P

Simple example:

{integer maths}
(3 / 2) * 5 = 5
(3 * 5) / 2 = 7

(of course the real answer should be 7.5 in both cases, but you get truncation with intgers)
No snowflake in an avalanche feels responsible.

stanhebben

Yeah, of course. Anyway, don't worry about the extra multiplication, it should run parallel with magic multiplication.

Eddy

If you are interested in the underlying math of the 'magic numbers', read following article:
"Integer Division Using Reciprocals" by Robert Alverson:
http://tinyurl.com/qc4qr

It is very understandable and not too long.

Kind regards
Eddy
HIME - Huge Integer Math and Encryption library
www.devotechs.com

Eddy
www.devotechs.com -- HIME : Huge Integer Math and Encryption library--

MichaelW

Quote from: Stan Hebben on October 02, 2006, 07:27:01 PM
ps. what's with the timing macro's? (timers.asm) I regularly get zero cycles, and sometimes even -1.
The problem is that there is no way (that I know of) to isolate the timed instructions from the timing instructions. If you are trying to time a single relatively fast instruction and it executes in parallel with one or more of the timing instructions, then the cycle count for the timed instruction is lost in the timing overhead. And if, in addition, the presence of the timed instruction reduces the timing overhead for the timing loop, relative to the empty reference loop, then you can end up with a small negative cycle count. The newer macros in counter2.zip work better for timing single instructions, but you still cannot get reliable cycle counts for instructions that execute in less than a few cycles. The newer macros also do not require large samples (high loop counts), so the results are more repeatable, and in most cases available almost immediately.
eschew obfuscation