GP2X Floating Point And Linking


Trenki

Member
Joined
Jun 15, 2006
Messages
114
Age
41
Location
South Tyrol, Italy
Website
www.trenki.net
Edit: If you don't want to read the whole post please just read the questions at the end.

Hello fellow coders! Just recently I got my gp2x and started out coding some test applications. To compile my apps i use the newly release official GP2XSDK from GPH for windows (edit: added this link: http://dev.gp2x.com/sdk/gp2xsdk_windows.zip) which comes with GCC 3.4.6 and all the necessary libs for development. The first few apps compiled and worked flawlessly and I found out
that the compiler links the libraries (SDL etc.) dynamically which is fine because it keeps compilation time and executable size down.

I also did some little floating point vs. fixed point benchmark programs using my vector and matrix math library i developed some time ago and found out that using fixed point is way faster.

I went a step further and wanted to try out pearyn's hardware accelerated SDL and that's where I first ran into problems. I downloaded the tar archive which contains the precompiled libSDL.a file. I figured that I would have to replace the SDL libraries which came with the GPH GP2XSDK and then link this one
statically (since .a files are meant for static linking; right?). I simply renamed the old files, so the compiler would not find them, and placed the libSDL.a file in the lib folder.

Now trying to compile (tried with and without the -static flag) yielded numerous errors stating that the other libs (even libgcc and libstdc++) where compiled with HW FP whereas my own test app was beeing compiled with SW FP. All this regardless of whether I used -msoft-float or not. I tried out various other things and combinations possibly resulting in different errors like the linker complaining about not finding floating point support routings (__addsf3 etc.).

After all this I was a bit confused about this HW FP/SW FP stuff since the gp2x does not have a FPU and this should only be using SW FP. So I looked into the various post about floating point on the gp2x but they still didn't make everything clear to me.
I then took the compiler and compiled the following test function with the -S flag to produce the ARM asm output.

Code:
float test(float a, float b)
{
	return a + b;
}

Without the -msoft-float flag the compiler actually produced floating point instructions like ldfs or adfs as you can see below! AFAIK the gp2x is still able to execute such code since the Linux OS handles these instructions via the illegal instruction interrupt and a FPU emulator. The boot log from http://wiki.gp2x.org/wiki/USB_Host seems to confirm this, as there is: NetWinder Floating Point Emulator V0.97 (double precision)

arm-gp2x-linux-gcc f.c -O3 -S

Code:
	.file	"f.c"
	.text
	.align	2
	.global	test
	.type	test, %function
test:
	@ args = 0, pretend = 0, frame = 0
	@ frame_needed = 0, uses_anonymous_args = 0
	@ link register save eliminated.
	str	r0, [sp, #-4]!
	ldfs	f1, [sp], #4
	str	r1, [sp, #-4]!
	ldfs	f2, [sp], #4
	adfs	f0, f1, f2
	@ lr needed for prologue
	mov	pc, lr
	.size	test, .-test
	.ident	"GCC: (GNU) 3.4.6"

Using the -msoft-float flag procuced the following code, which contains a call to the __addsf3 fp function. The problem with this is that linking a program which uses -msoft-float is not possible because the compiler complains about not finding -lfloat (libfloat), which actually isn't present in the GPH GP2XSDK.

Code:
arm-gp2x-linux-gcc f.c -O3 -S -msoft-float

	.file	"f.c"
	.global	__addsf3
	.text
	.align	2
	.global	test
	.type	test, %function
test:
	@ args = 0, pretend = 0, frame = 0
	@ frame_needed = 0, uses_anonymous_args = 0
	str	lr, [sp, #-4]!
	bl	__addsf3
	ldr	pc, [sp], #4
	.size	test, .-test
	.ident	"GCC: (GNU) 3.4.6"


Now to the actual questions:

1.) Since the gp2x doesn't have a FPU i assume using -msoft-float would result in considerably better performance since the kernel would not have to employ the FPU emulator. Is this assumption correct?

2.) Is it correct, that when using -msoft-float I'm unable to dynamically link to the .so's in the /lib/ directory on the gp2x because they seem to use HW FP? May it even be impossible to link to libs that don't use floats (e.g libz)?

3.) While I was trying things out i found out that using the -static flag it is possible to link statically instead of dynamically. The catch is that all libraries now where linked statically. Is is somehow possible to specify on a per library basis whether to link statically or dynamically?

I will probably also try out some other SDKs like the devkitGP2X which seem to support -msoft-float and probably also come with a newer GCC. But using a newer version of GCC (e.g. 4.0 or 4.1) would also make me unable to link to the .so libraries on the gp2x because of the binary interface not beeing compatible
anymore.

I would really appreciate any feedback clarifying the issue with floats, linking and the other problems i pointed out.
 
Hello fellow coders! Just recently I got my gp2x and started out coding some test applications. To compile my apps i use the newly release official GP2XSDK from GPH for windows which comes with GCC 3.4.6 and all the necessary libs for development.

Are you sure about the gcc version? I've got the sdk from the archives and "gcc --version" reports 4.0.2 When GPH release thier sdk I grabbed it to see if its got a higher gcc version and that also reported 4.0.2 (assuming I checked it correctly ;) )
 
Last edited by a moderator:
I use the windows version of the GP2XSDK (http://dev.gp2x.com/sdk/gp2xsdk_windows.zip) which comes only with gcc version 3.4.6. I looked into the tar file of the linux version and there seems to be gcc 3.4.6 and also 4.0.3. Is this the sdk your are using?

I don't know why there is only 3.4.6 on windows but given the fact, that the linux sdk also contains the 4.0.3 version which presumably is able to link dynamically with the gp2x shared libraries from C/C++ is there actually a compatibility problem with linking to libraries between different gcc versions?
 
1.) Since the gp2x doesn't have a FPU i assume using -msoft-float would result in considerably better performance since the kernel would not have to employ the FPU emulator. Is this assumption correct?

2.) Is it correct, that when using -msoft-float I'm unable to dynamically link to the .so's in the /lib/ directory on the gp2x because they seem to use HW FP? May it even be impossible to link to libs that don't use floats (e.g libz)?
1) It could make a large difference

2) You can't link a hardware floating point object to a software floating point one. I had this problem with the official SDK so I switched to another one.
 
Last edited by a moderator:
3.) While I was trying things out i found out that using the -static flag it is possible to link statically instead of dynamically. The catch is that all libraries now where linked statically. Is is somehow possible to specify on a per library basis whether to link statically or dynamically?

I haven't tested this myself, but i heard that it's possible to link to a static library (.a) if you pass it to the compiler as if it was a object (.o) file. Like this:
Code:
gcc myprog.o /lib/libSDL.a -o myprog
 
I use the windows version of the GP2XSDK (http://dev.gp2x.com/sdk/gp2xsdk_windows.zip) which comes only with gcc version 3.4.6. I looked into the tar file of the linux version and there seems to be gcc 3.4.6 and also 4.0.3. Is this the sdk your are using?

I don't know why there is only 3.4.6 on windows but given the fact, that the linux sdk also contains the 4.0.3 version which presumably is able to link dynamically with the gp2x shared libraries from C/C++ is there actually a compatibility problem with linking to libraries between different gcc versions?

(Sorry for slow reply)

I'm using the windows version, i've downloaded the one of GPH as well as the one from the gp32x archives. I'm using the latter, but both for me report 4.0.2 Doing a search there is only one gcc.exe in my devkitgp2x dir. ( located C:\devkitGP2X\arm-linux\bin )

Also in c:\devkitGP2x\bin there is arm-linux-gcc.exe, this also reports 4.0.2 Very odd, a while ago I did try every dev enviroment under the sun so maybe I some how upgraded my gcc tool chain by mistake. Be funny if I did and did not know it.
 
Last edited by a moderator:
I'm using the windows version, i've downloaded the one of GPH as well as the one from the gp32x archives. I'm using the latter, but both for me report 4.0.2 Doing a search there is only one gcc.exe in my devkitgp2x dir. ( located C:\devkitGP2X\arm-linux\bin )

Also in c:\devkitGP2x\bin there is arm-linux-gcc.exe, this also reports 4.0.2 Very odd, a while ago I did try every dev enviroment under the sun so maybe I some how upgraded my gcc tool chain by mistake. Be funny if I did and did not know it.
Thanks for your reply! Though, I think we may be talking about different things, since in the "official" SDK from GPH (this one comes with the Dev-C++ IDE) I do not have an arm-linux-gcc.exe but an arm-gp2x-linux-gcc.exe.

But never mind, I will go and try the devkitGP2X from the archives.
 
Yay! I now downloaded and installed the devkitGP2X from the archive and tested what the speed difference between this one and the "official" SDK from GPH is when using floats.

The gcc 4.0.2 compiler from the devkitGP2X seems to be preconfigured to always generate software-fp code since even without specifying -msoft-float the compiler generates calls to the software-fp library instead of emitting hardware-fp instructions as the GPH SDK does.

The speed difference is huge! My test program which generates 10000 random 3d vectors and then transforms them using a transformation matrix run 20 times faster with the devkitGP2X SDK compared to the GPH GP2XSDK!!!
 
Back
Top