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.

DS development > int32 & Math coprocessor

#72280 - ishraam - Fri Feb 17, 2006 9:33 am

I just went over <math.h> again, and, once again, saw the "div32(...)", "mod32(...)", "div64(...)", "mod64(...)", "sqrt32(...)" functions.

Since <jtypes.h> told me int32 is a signed int, I was wondering what was the difference between using a common
Code:

int div = 1223 / 333;

and
Code:

int32 div = div32(1223,333);


Is the second version ("div32") optimized (using the math coprocessor)? And the first version ("/") not ? (using the ARM x processor)?

#72321 - dovoto - Fri Feb 17, 2006 5:42 pm

ishraam wrote:

Is the second version ("div32") optimized (using the math coprocessor)? And the first version ("/") not ? (using the ARM x processor)?


That is correct. Wintermute has "/' tied to the bios software divide routine on the arm7 and arm9 (i believe) so the only way to get hardware divide at the moment is to do it explicitly by invoking the math coprocessor (with div32 for instance).

Why he has not altered the arm9 "/" to use the hardware I am not certain but I am sure there is a good reason (it may just be a pain to implement it one way on the arm7 and another on the arm9).
_________________
www.drunkencoders.com

#72336 - sajiimori - Fri Feb 17, 2006 7:47 pm

Invoking the coprocessor involves changing its state, so it might be a little scary to have a seemingly innocent operator like / produce subtle side-effects that can break threaded code.

#72338 - dovoto - Fri Feb 17, 2006 7:56 pm

eww...threaded code ;)
_________________
www.drunkencoders.com

#72341 - DekuTree64 - Fri Feb 17, 2006 8:13 pm

Normal interrupts too.

Just be sure you save the divider/square root regs at the start of your handler if you plan to use them, and set them back before you return.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#72386 - ishraam - Sat Feb 18, 2006 4:29 am

dovoto :
Ok, thanks :).

sajiimori :
Quote:
produce subtle side-effects that can break threaded code

Aww yeah right.

But when you talk about threads, there's one thing that pops in my mind : mutex.
They are usually together, but I can't remember having seen someone talking about mutex. Are there somewhere hidden in the dark or have I missed something ?

DekuTree64:
Quote:
save the divider/square root regs at the start of your handler if you plan to use them, and set them back before you return.

Ok thanks a lot. I will give this a try sooner or later. I'll keep focused on 3D for a little while, but will test it for sure.

It would be nice to have perf. comparison tests, between "float" and 'f32", and int's div32, etc and "normal" /, etc.
I'll try to take some time for this.

BTW : are there any time() function or something that would help me in recording perf.?