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 > 20 12 fixed mult - sharing registers?

#17041 - corranga - Sun Feb 29, 2004 12:55 pm

I'm working on 20 12 fixed point multiplication now (after discovering my current routine was only working out the whole number part and no fraction!

I used to use the routine below when I dabbled a little into mips asm for the sony playstation:

//multiply the numbers together
mult a0, a1
//store the low part in v0
mflo v0
//and the high in v1
mfhi v1
// shift the high part into place
srl t0,v0,12
// and the low part
sll t1,v1,20
// or them together for the answer
or v0,t0,t1

is it possible to do something similar on the gba?

Essentially i'm asking how to do, 32bit * 32bit = 64bit (in 2 32 bit registers) if it is possible

If it can't be done, can someone point me in the direction of a fixed point 20 12 routine that I can modify / use. I'm going bald having worked on this for about 3 weeks!

Chris
_________________
If virtual reality is ever on a par with reality, I want to be Bomberman! :D

#17046 - Lupin - Sun Feb 29, 2004 2:13 pm

i think the instruction is mull or smull (i think it's both the same, not sure maybe mull doesn't even exist).

Maybe someone got an explanation about how to use the instruction.

#17051 - Paul Shirley - Sun Feb 29, 2004 2:44 pm

removed

Last edited by Paul Shirley on Sun Mar 28, 2004 9:05 pm; edited 2 times in total

#17052 - Lupin - Sun Feb 29, 2004 2:59 pm

but he asked for asm :)

#17053 - Large Metal Teeth - Sun Feb 29, 2004 3:06 pm

No need for 16-bit partials. There is a 32 * 32 = 64 bit instruction like Lupin said. It is an ARM mode only instruction

SMULL is signed multiply long.
UMULL is unsigned multiply long.

It takes four register operands (some of which can overlap): 2 dests and 2 sources.

#17072 - tepples - Sun Feb 29, 2004 6:10 pm

Paul Shirley wrote:
Easiest way: use long long variables and let the compiler sort it out for you.

Are you sure that GCC will generate proper 'smull' instructions for s32xs32=s64 multiplies rather than sign-extending the s32s to s64 and then doing s64xs64=s64 using a library call? If it varies by version, which version are you using?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#17142 - corranga - Tue Mar 02, 2004 9:59 am

Thanks very much to all you guys. I knew about the long long, and therefore presumed there was some form of asm instruction to do something with 64 bits.

I used smull and (I think) it works fine

Chris
_________________
If virtual reality is ever on a par with reality, I want to be Bomberman! :D