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.

Coding > DevKitAdv Division

#23462 - f(DarkAngel) - Tue Jul 13, 2004 3:55 pm

Why doesn't devkitadv uses a swi instead of inserting a custom code? Or at least a command-line option that allows to switch between gcc code and swi. Is it too much work to modify gcc such way?
_________________
death scream...

#23464 - poslundc - Tue Jul 13, 2004 4:21 pm

I know that if I had a devkit with that feature, I would be disinclined to use it on account of a lack of portability to other development environments. If I want to use a SWI, I'll state it explicitly in the code.

That's not to say it might not be a worthwhile feature, but I doubt it's very high on anyone's priority list for that reason. I imagine most devkits already focus the majority of their energy on just being standards compliant, rather than creating new standards.

Dan.

#23474 - tepples - Tue Jul 13, 2004 6:27 pm

When GCC wants to divide ('/') on ARM7, it calls a function in libgcc called __divsi3. That function takes dividend in r0 and divisor in r1 and returns the quotient, rounded toward 0, in r0. Another libgcc function is __modsi3 for '%', which takes dividend and divisor and returns the remainder in r0. The divide function in the GBA BIOS takes dividend in r0 and divisor in r1 and returns the quotient in r0 and the remainder in r1.

You can easily tell the linker to delegate __divsi3 and __modsi3 to the GBA BIOS rather than to libgcc by making a source code file called divide.s, containing code similar to the following (untested):
Code:
.THUMB
.THUMB_FUNC
.ALIGN
.GLOBL  __divsi3

__divsi3:
  swi 6
  bx lr

.THUMB
.THUMB_FUNC
.ALIGN
.GLOBL  __modsi3

__modsi3:
  swi 6
  mov r0, r1
  bx lr

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#23484 - Miked0801 - Tue Jul 13, 2004 10:34 pm

Yep - or link it to a custom are divide for even more speed :)

#23658 - f(DarkAngel) - Sat Jul 17, 2004 1:19 pm

poslundc: this'd be a platform-specific optimization, not a new standard.
tepples: i've asked this for speed maximization. a function call is not the best case. what i intended to say was an inline code, i guess that would be possible by modifying the internals of gcc.
_________________
death scream...