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.

Beginners > Which modulus being used

#49273 - ymalik - Thu Jul 28, 2005 12:26 am

When I use the % operator, is swi 6 called? If not, how is it being done, and is it slower than using the bios function?

Thanks,
Yasir

#49274 - poslundc - Thu Jul 28, 2005 12:49 am

ymalik wrote:
When I use the % operator, is swi 6 called?


No.

Quote:
If not, how is it being done


Using the GCC division algorithm.

Quote:
and is it slower than using the bios function?


Yes. But be aware that:

1. You can beat the BIOS with your own routine.

2. You can get something very near to modulus with the bitwise-AND operator where the divisor is an even power of two. Eg. (x & 31) == (x % 32) for all positive values of x (negative values will "wrap around", which they don't do with modulus, but is actually a useful functionality).

Dan.

#49275 - tepples - Thu Jul 28, 2005 12:54 am

poslundc wrote:
ymalik wrote:
When I use the % operator, is swi 6 called?


No.

Quote:
If not, how is it being done


Using the GCC division algorithm.

Doesn't the latest version of devkitARM's libgba route the / and % operators through the BIOS in many cases?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#49286 - poslundc - Thu Jul 28, 2005 6:05 am

tepples wrote:
Doesn't the latest version of devkitARM's libgba route the / and % operators through the BIOS in many cases?


I don't know... I just know that my pathetically outdated version of Devkit Advance does not. It's cool if they do, though.

Dan.

#49513 - ymalik - Sat Jul 30, 2005 7:02 pm

poslundc wrote:

1. You can beat the BIOS with your own routine.

How does the BIOS do it?

Quote:

2. You can get something very near to modulus with the bitwise-AND operator where the divisor is an even power of two. Eg. (x & 31) == (x % 32) for all positive values of x (negative values will "wrap around", which they don't do with modulus, but is actually a useful functionality).

I never thought about that. My divisor is 16.

Much thanks.

#49516 - poslundc - Sat Jul 30, 2005 7:21 pm

ymalik wrote:
poslundc wrote:

1. You can beat the BIOS with your own routine.

How does the BIOS do it?


I don't know the exact routine it uses, but this thread does some speed profiling.

Dan.