gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Interpolating between integers

#7899 - Lupin - Fri Jun 27, 2003 8:05 pm

How could I interpolate between two Integers? I have an "time"-Value wich goes from 0-7 and 2 values wich I want to interpolate between, this has to be done fast, the basic formular for doing this in normal math would be new=src+((dest-source)*t), but now I need to do this really fast by using asm and only integer based calculations.

I think this is possible by using some and/or/shift operators, but I'm not that good at bit fiddling, so maybe someone of you has done something like this before.

I need this to create an fast lookup table for integer division wich covers the whole range of an 16bit value (maybe even an 32bit one), by using an very small lookup table

#7900 - tepples - Fri Jun 27, 2003 8:20 pm

Lupin wrote:
How could I interpolate between two Integers? I have an "time"-Value wich goes from 0-7 and 2 values wich I want to interpolate between, this has to be done fast, the basic formular for doing this in normal math would be new=src+((dest-source)*t), but now I need to do this really fast by using asm and only integer based calculations.


On the ARM7TDMI processor, multiplication by an integer less than 255 is quite fast (3 cycles or so). If you set t to range from 0 (src) to 256 (dst) and then shift the result to the right by 8 bits, you have it. Or set t to range from 0 to 8 and then shift the result to the right by 3 bits.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7908 - Lupin - Sat Jun 28, 2003 10:22 am

Ok, but why do I need to shift afetr I multiplied the value?

Do you know how many cycles an software divide takes?

#7921 - tepples - Sat Jun 28, 2003 6:10 pm

A BIOS divide is extremely slow (a couple hundred cycles last time I checked).

A right shift is equivalent (modulo rounding differences for negative numbers) to a divide by a power of 2. For example, shifting a number right by 3 divides the number by 8 (that is, 2^3).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.