Fpu Replacement/integer Math


twixn

Still Fresh
Joined
Jul 20, 2006
Messages
43
Age
39
Location
Melbourne, Australia
Website
Visit site
Hey all

Just got my GP2X in the mail yesterday :D And i've spent quite
a while today serching the forums for some answers without success
(although i probably missed something) so i thought id just ask.

I've been having troubles getting floating point math working. I know
the ARM920T has no FPU, but since i got it so recently shouldn't
the dev kit be compiled with -msoft-float to at least emulate it?
I have also compiled all of my code with -msoft-float, but the same thing
always happends.

Eg, this code compiles fine, but when its executed the GP2X just
hangs:

Code:
int running=100;

float test;
	
test=2.0f*2.0f;
	
running=(int)(test)*running;

If i cant get it working, is there anywhere i can get fixed point libraries
for cos, sin, tan and sqrt?

Im attempting to make a 3D rasterizer for a game on the GP2X, i have a simple
rasterizer going but i need to use these functions to calculate the proj and
view matricies, as well as some vector math (like normalization).

Can anyone help?

-Twixn-
 
It should work fine whether you use -msoft-float or not, but the code is a lot faster with -msoft-float

What toolkit are you using? How are you running it? In what way does it hang?
 
are you sure its hanging? keep in mind that printf's arent shown on the screen and that you have to restart the menu yourself.
 
Parkydr posted on Jul 20 2006 at 10:37 PM said:
It should work fine whether you use -msoft-float or not, but the code is a lot faster with -msoft-float

What toolkit are you using? How are you running it? In what way does it hang?

Im using the devkitGP2X from the GP2x wiki (the one that contains all of the libs, like SDL etc).
Im using it with DevCpp on WindowsXP, and i set that up using the instructions from the wiki.
I copy the created *.gpe file to a SD disk and put it into the gp2x, then i boot it
up and try it.

I'll go on about how it hangs next.

Vimacs posted on Jul 20 2006 at 10:38 PM said:
are you sure its hanging? keep in mind that printf's arent shown on the screen and that you have to restart the menu yourself.

I already have the program displaying rasterized triangles on the screen, and i have:


Code:
chdir("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);

At the end of my code to go to the menu. I have the code snippit in my last
post just before i draw to the screen. With the code commented out the triangle
is drawn, and it goes through an odd and simple little animation before exiting
to the menu.

When the code is uncommented, the screen just stays black. If i move the code
to after the triangle is drawn for the first time it just stops, showing the inanimate
triangle.

And if it matters, im using SDL and i think its just the static lib form as i havent
had to copy the shared lib to the gp2x.

Thanks for the replies btw :D

-Twixn-
 
Last edited by a moderator:
It sounds like your program is crashing before it gets to the bit that returns to the menu and the last thing displayed is still on the screen

Try running it from the command line in telnet
 
int running=100;

float test;

test=2.0f*2.0f;

running=(int)(test)*running;

really basic and lame suggestion, but have you tried commenting the lines out one by one to see which , if any, is causing the hang ?

also i'm 100% sure it won't make any difference but try

running=(int)(test)*running;

running=(int)test*running;
 
Parkydr posted on Jul 20 2006 at 11:21 PM said:
It sounds like your program is crashing before it gets to the bit that returns to the menu and the last thing displayed is still on the screen

Try running it from the command line in telnet

Im not sure thats the case. If that happens then the triangle should be displayed and
animated anyway, but the last frame of the animation would hang.

However, from testing i know that the program simply stops when it reaches floating point
code. It hangs on a black screen if the floating point code is before the first triangle is
drawn. It hangs with the first frame of the triangle on the screen if the floating point code
is immediately after it. And it hangs on the last frame of animation if the floating point code
is after it.

Considering i have a fairly 'stock' dev setup i thought maybe there was something that
could fix this problem. A flag or something.


critical posted on Jul 21 2006 at 02:18 AM said:
There are fixed-point routines for sin and cos here:

http://www.gp32.co.nz/snippet_view.php?snippet_id=20

or you could pinch them (and tan, etc) from allegro:

http://srnet.cz/~stepan/allegro/srcs/alleg...th.c.html#line1

You'd have to find your own sqrt function from elsewhere, however.

Thanks! :D In case i have to go all fixed point that will be very helpful. Im sure i can go hunting
for the sqrt function. Or better yet something else thats good at approximating the length of
a vector.


TheMinder posted on Jul 21 2006 at 02:28 AM said:
int running=100;

float test;

test=2.0f*2.0f;

running=(int)(test)*running;

really basic and lame suggestion, but have you tried commenting the lines out one by one to see which , if any, is causing the hang ?

also i'm 100% sure it won't make any difference but try

running=(int)(test)*running;

running=(int)test*running;

I tried commenting out 'test=2.0f*2.0f;' and the same thing still happened. However when commenting
out 'running=(int)(test)*running;' it worked! But i think that was because GCC was taking out the
'test' variable altogether as it was not used as anything, so i added 'printf("%f",test);' right at the end of
my code to force the compiler to compile the 'test' variable. It went back to hanging at 'test=2.0f*2.0f;'.

Thanks again for all your help and suggestions so far.

-Twixn-
 
Last edited by a moderator:
Twixn posted on Jul 20 2006 at 05:17 AM said:
If i cant get it working, is there anywhere i can get fixed point libraries
for cos, sin, tan and sqrt?
Fixed point sin, cos, tan are easy, they're table lookups. The ones linked to could be slightly more efficient (don't need the full table), and if you can arrange for angles to be in 1/1024ths of a revolution even better (bitwise and instead of modulus).

Fixed point sqrt is the same as integer sqrt but with a fixup by half the number of fractional bits. This meshes perfectly with the squaring in finding a vector magnitude: sqrt(x*x+y*y+z*z) should give you a proper fractional magnitude using only regular integer math. (Assuming you don't overflow your integer type.)
 
Last edited by a moderator:
rabidcow posted on Jul 21 2006 at 11:02 AM said:
Fixed point sqrt is the same as integer sqrt but with a fixup by half the number of fractional bits. This meshes perfectly with the squaring in finding a vector magnitude: sqrt(x*x+y*y+z*z) should give you a proper fractional magnitude using only regular integer math. (Assuming you don't overflow your integer type.)

Unfortunately it does overflow the integer type (16.16), so i have to do fixed point multiplications
for each component in the sqrt. But thanks, i wasn't sure how different fixed point sqrt was from integer
sqrt. Now i know it just needs '>>8' on the end.

Anyway, thanks everyone for your help. I have a full 16.16 fixed point 3D pipeline
working now. Only does triangles in solid 16bit colours though, so i still have some work ahead of
me, but at least i have a system to work from now.

-Twixn-
 
Last edited by a moderator:
Back
Top