GP2X Floating Points?


sweetfish

Still Fresh
Joined
Sep 19, 2005
Messages
46
Location
Gothenburg, Sweden
Website
md5.se
Hi!

I have been watching some threads on the forum, and for what I can tell apperently the GP2X doesn't support float-variabels? Since the positions of objects in my game currently depends on float-variabels this is gonna be a problem. :) So, first of all, is it true? And if so, is there any tips and tricks on how I should go from floats to ONLY integers?

Yours,
Sven, Sweden
 
sweetfish posted on Sep 29 2005 at 09:18 PM said:
Hi!

I have been watching some threads on the forum, and for what I can tell apperently the GP2X doesn't support float-variabels? Since the positions of objects in my game currently depends on float-variabels this is gonna be a problem. :) So, first of all, is it true? And if so, is there any tips and tricks on how I should go from floats to ONLY integers?

Yours,
Sven, Sweden
ofcourse floating points are supported, the problem is it hasn't got a floating point unit, so floating points have to be calculated the hard way, very heavy for the processor.
if your game isn't cpu intensive, floating points shouldn't be too much of an issue, but if you'll be pushing the gp2x to it's limits using fp's is a bad thing i think...

i don't know what the best solution is to overcome that problem, but you'll soon have some replies from the devvers here i think ^^

yours
Sven, Belgium (no kidding :D)
 
Last edited by a moderator:
Racemaniac posted on Sep 29 2005 at 09:29 PM said:
ofcourse floating points are supported, the problem is it hasn't got a floating point unit, so floating points have to be calculated the hard way, very heavy for the processor.
if your game isn't cpu intensive, floating points shouldn't be too much of an issue, but if you'll be pushing the gp2x to it's limits using fp's is a bad thing i think...

i don't know what the best solution is to overcome that problem, but you'll soon have some replies from the devvers here i think ^^

yours
Sven, Belgium (no kidding :D)

Aha, so thats it! Well, I guess I will try to keep the floats to the minimun then just going all integers then. :)

Thanks, Sven! ;)
 
Last edited by a moderator:
And for those times when you HAVE to use large quantities of floats (e.g. trigonometric functions) use a lookup table. Quite how you use a lookup table, I'm not sure, but I do know it's a LOT faster than calculating fresh each time.

There's also some tricks you can pull with bitwise operator shifts for multiplication and division to speed them up a lot, but I can't remember them, and I have a suspicion they're fixed point only (could be wrong - not a programmer, just been around a while).
 
All correct, good stuff Tobriand :)

Floating point operations are done in software (no dedicated hardware) so are very slow.

Fixed point math is a method of using an integer (32 bits) and setting a portion as the part before the decimal point, and a portion as the part after the decimal point (the fraction). Usually the split is 16 bits each, for 16.16 fixed point.

If you use this type of math, the range of your number is limited (16 bits rather than 32 bits) to around -32768 to 32767, and you lose a bit of accuracy in the decimal portion too. For example (this is just made up), the number 7.0067 might not be able to be represented exactly by a fixed point number, and is stored as 7.0065. This means that a few multiplications and other operations later, your final solution may be out by a bit.

A lookup table is a pre-calculated table of results. For example, sine - it can be a table of all the values of sin between 0 and 359 degrees. Then when you need to calculate sin(200) you just look it up in the table instead for a massive speed increase. If you need a value between 200 and 201 you look up both sin(200) and sin(201) and interpolate between them to get an approx answer. This uses some math, but is usually much less of a hit than calculating the value directly.

Shifts can be used for multiplying and dividing by factors of 2 (so multi/divide by 2,4, 8, 16 etc) by shifting the number left or right one bit for each factor of 2. As tobriand said - can only be done for fixed point. Example:
num>>1; // divide by 2
num<<1; // multiply by 2
num>>2; // divide by 4
num<<3; // multiply by 8
Shifts are very fast an inexpensive. Infact, in most instances they are FREE. Because ARM has whats calleda barrel shifter that can shift the number as well as doing another operation. For example (a+2)>>2 - the processor will do an ADD instruction and then shift the result at the same time for free :).

Something like that anyway.
 
don't forget: for now you don't have to change anything in your code. gcc munches through your code to add software operations for floating point calculations.

and it should be fast enough for most things.

i guess.

unless you want to port quake.

//warning: the speed thingy is entirely based on speculations//
 
no_skill posted on Oct 1 2005 at 12:21 AM said:
unless you want to port quake.


I thought quake was mostly fixed-point?

Also, any compiler worth its salt will convert multiplies/divides by powers of two to shift operations.
 
Last edited by a moderator:
Back
Top