On Tue, Apr 24, 2001 at 02:01:59PM -0400, Jaspreet Singh wrote:
> There is a comment in that file which states:
>
> loops = (r0 * 0x10c6 * 100 * loops_per_jiffie) / 2^32.
>
> Now I couldn't dissemble the above expression from the code.
Unfortunately, its overly complicated to keep the arithmetic within
acceptable precision. The code is:
mov r2, #0x6800
orr r2, r2, #0x00db
mul r1, r0, r2 r1 = r0 * 0x68db
ldr r2, LC0
ldr r2, [r2]
mov r1, r1, lsr #11 r1 = r1 >> 11
mov r2, r2, lsr #11 r2 = loops_per_jiffy >> 11
mul r0, r1, r2 r0 = r1 * r2
movs r0, r0, lsr #6 r0 = r0 >> 6
Plugging those all into each other:
r0 = (((r0 * 0x68db) >> 11) * (loops_per_jiffy >> 11)) >> 6
Now, simplify:
r0 = ((r0 * 0x68db * loops_per_jiffy) >> 11) >> 6
r0 = (r0 * 0x68db * loops_per_jiffy) >> 28
r0 = (r0 * loops_per_jiffy) * (26843 / (2 ^ 28))
r0 = (r0 * loops_per_jiffy) * (26843 / 268435456)
r0 = (r0 * loops_per_jiffy) / 10000.2
Now, taking the original expression:
loops = (r0 * 0x10c6 * 100 * loops_per_jiffy) / 2^32.
loops = r0 * 429400 * loops_per_jiffy / 2^32
loops = r0 * loops_per_jiffy / 10002.3
The code we now have is more accurate than the comment (which actually
reflects the old code).
The constant you will need to adjust is the 0x6800 and 0x00db to
something around 0x1a36c. Unfortunately you need an extra instruction
to load it, you might as well just shift right the r1 value by two.
mov r2, #0x6800
orr r2, r2, #0x00db
mul r1, r0, r2
ldr r2, LC0
ldr r2, [r2]
mov r1, r1, lsr #13 11 for 100Hz, 13 for 400Hz
mov r2, r2, lsr #11
mul r0, r1, r2
movs r0, r0, lsr #6
_____
|_____| ------------------------------------------------- ---+---+-
| | Russell King [EMAIL PROTECTED] --- ---
| | | | http://www.arm.linux.org.uk/ / / |
| +-+-+ --- -+-
/ | THE developer of ARM Linux |+| /|\
/ | | | --- |
+-+-+ ------------------------------------------------- /\\\ |
_______________________________________________
http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
Please visit the above address for information on this list.