Trenki
Member
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.
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
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.
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 (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.