Shop OBEX P1 Docs P2 Docs Learn Events
Floating Point troubles in RPi 1.9.0-Alpha-gcc4 — Parallax Forums

Floating Point troubles in RPi 1.9.0-Alpha-gcc4

If I include simpletools in my library path, I get conflicts between libsimpletools.a(fpucog.o) and libgcc.a(_loadfloat.o) for all of my float functions (___addsf3, ___subsf3, etc.). So... I comment out the line that includes simpletools in my library path, and it is able to compile. The only Simple Library functions I use are terminal output for debugging, which still works with only libsimpletext.a and not libsimpletools.a.

However, during run-time, it seems that the float functions do not work; I seem to get valid floating point numbers, but they are way off. For example, I get 278 when it should be 5760, 283 for 57600, 290 for 576000, etc. I pared it down to the following code:
parseVolts(57.60, LEDmbx.displayString);

...

void parseVolts(float fnum, char *string) {

    int     inum;

    inum = (int) (fnum * 100.0);
//   inum = 5760;
  ...
}
If I inject "inum = 5760" (commented out in the above code), it displays correctly, but if I ask it to multiply a floating point immediate by 100 and convert it to an integer (the original code was of course a bit more involved before I pared it down), I get the values I stated above, not what they should be.

The last time this code was working (for sure) was when I was compiling it on linux-x64; I don't think anything has changed since then, but unfortunately, my main linux machine is temporarily out of commission, so I can't verify that. If I go back to Rpi gcc 0.9.46, I get a segfault in gas (after changing .pasm to .cog_ram; ugh !) on the first file, so I did not pursue that further.


As an aside, the current propeller-load in 1.9.0-Alpha-gcc4 (downloaded 17 Dec 2015) doesn't recognize ttyAMA0; I have to use an older version.

Any ideas ?

Comments

  • Where did you go to download it?
  • Hi David, I of course downloaded it from your site; thank you ! If my i7 were working, I could think about downloading the source and compiling, but it's pretty slow on the Pi, even with 4 cores.
  • Sorry to hear there is a bug. I'm headed out of town tonight and won't be back for a while, so I'm afraid I won't be able to test anything on my own Raspberry Pi for quite some time. I'll still be on the forums though so if it turns out to be an issue with the configuration of the build server, I'll get it fixed.
  • Are there any warnings in the code, particularly if you compile with -Os -Wall? Are you using 32 or 64 bit doubles? I ask because one possible source of error would be if a 64 bit double is being passed to the parseVolts function which is expecting a 32 bit float.
  • altosackaltosack Posts: 132
    edited 2015-12-18 18:27
    There are no warnings, and I am using 32-bit doubles, specified for both the compiler and the linker. And I know that at one point I was passing what was for sure a 32-bit float because it was from my pasm cog. Curiously, if I include -lm in the link step, it adds 3k to the object size, but has no effect on the output (I didn't use it before when it was working with x64)

    Sorry I didn't post the whole project, but I thought that would obfuscate more than clarify. The snippet I have has no prior inputs, and the outputs go to a 7-segment display. When I put in the integer assignment statement as above, it works fine.

    Maybe we could start at the top. Do you know why I'm getting the conflict between libsimpletools.a and libgcc.a ?

    I'm using SimpleLib from the SimpleIDE release (I guess it's 0.9.46); I assume there's no newer version of this that needs to go with propgcc-1.9.0 ? It was working before with x64, but I guess that might have been 1.0.

  • For what it's worth, the last successful build of the RPi GCC 4 build was 18 Apr 15 05:57
    The build log can be seen here: http://david.zemon.name:8111/viewType.html?buildTypeId=PropGCC5_Gcc4rpi&guest=1
  • David, I'm not sure what you mean. Is that the version that's on the link on your page ? If not, is it available somewhere ? Also, on your page, you recommend gcc4. Is that still accurate, or should I try gcc5, since I noticed that gcc5 has current successful builds (today ! by David Betz) ? I'm reluctant to download it just to see, since I have limited bandwidth, but if that's the answer, I certainly will.

    BTW, I'm David, so getting Mr. Betz in here too could be quite confusing. "Altosack" is good.

  • altosack wrote: »
    David, I'm not sure what you mean. Is that the version that's on the link on your page ? If not, is it available somewhere ? Also, on your page, you recommend gcc4. Is that still accurate, or should I try gcc5, since I noticed that gcc5 has current successful builds (today ! by David Betz) ? I'm reluctant to download it just to see, since I have limited bandwidth, but if that's the answer, I certainly will.

    BTW, I'm David, so getting Mr. Betz in here too could be quite confusing. "Altosack" is good.
    We're working on a new release of SimpleIDE and I wanted to try using the gcc5 repository. The propeller-gcc wrapper project in my github account now builds gcc5 by default. You can still build gcc4 by giving a command line argument to make.

  • altosack wrote: »
    David, I'm not sure what you mean. Is that the version that's on the link on your page ? If not, is it available somewhere ?

    Assuming you clicked a link from the "propgcc now on github" page or from PropWare's homepage or something like that (aka, anything other than directly visiting the build server), what you actually downloaded was "last successful". The words "..../lastSuccessful/..." are actually in the URL, and the TeamCity automagically finds the latest build that finished successfully. Unfortunately in the case of GCC 4 for RPi, that was back in April.

    Mr. Betz, since you have access to the build server, you should be able to not only read the full build log, but also view the environment and configuration parameters for each build. Maybe you can see something there that is configured incorrectly: http://david.zemon.name:8111/viewLog.html?buildId=641&tab=buildResultsDiv&buildTypeId=PropGCC5_Gcc4rpi
  • Well, I do realize that most of the time we think there's an error in system code, it's usually user error, even though I made it so simple that I don't see how it could be. I was hoping someone would chime in and say that it's working for them, which would tell us it's on my side of the fence.

    There certainly is a problem with propeller-load, which doesn't recognize ttyAMA0. This console serial port is necessary to use on an embedded system, because the single USB port on the smaller boards will be used for either WiFi or for kb/mouse during development; also, any prop HAT will have it connected, anyway. I have a propeller-load that does recognize ttyAMA0; at this point, I'm not sure if I got it from Heater or a previous version of propgcc.

    If no one has a ready answer, I will try the gcc5 build, and report how it goes.
  • altosack wrote: »
    Well, I do realize that most of the time we think there's an error in system code, it's usually user error, even though I made it so simple that I don't see how it could be. I was hoping someone would chime in and say that it's working for them, which would tell us it's on my side of the fence.

    There certainly is a problem with propeller-load, which doesn't recognize ttyAMA0. This console serial port is necessary to use on an embedded system, because the single USB port on the smaller boards will be used for either WiFi or for kb/mouse during development; also, any prop HAT will have it connected, anyway. I have a propeller-load that does recognize ttyAMA0; at this point, I'm not sure if I got it from Heater or a previous version of propgcc.

    If no one has a ready answer, I will try the gcc5 build, and report how it goes.
    You should be able to just specify "-p /dev/ttyAMA0" on the propeller-load command line.

  • David Betz wrote: »
    You should be able to just specify "-p /dev/ttyAMA0" on the propeller-load command line.

    You're right; it works. On the previous version I had, it would automatically find it; when that didn't work on this one, I used "-P" to find the available serial ports and it didn't find any. Curiously, I just tried it again and it did find ttyAMA0. Hmm... I suspect a permission problem that is now fixed. Sorry about that.

    For info, I downloaded propgcc5-1.9.0-rpi from the link on David Zemon's page, and all of the binary files say "cannot execute binary file: exec format error" for both a Pi1 and a Pi2.
  • maccamacca Posts: 783
    edited 2015-12-19 08:36
    DavidZemon wrote: »
    For what it's worth, the last successful build of the RPi GCC 4 build was 18 Apr 15 05:57
    The build log can be seen here: http://david.zemon.name:8111/viewType.html?buildTypeId=PropGCC5_Gcc4rpi&guest=1

    Maybe you should force a build because I believe it doesn't include, at least, the latest fixes to the assembler: I tried to compile some of my sources on the RPi and the compiler seems to not support the underscores in the number constants (like %1_0000_111).
    altosack wrote: »
    However, during run-time, it seems that the float functions do not work; I seem to get valid floating point numbers, but they are way off. For example, I get 278 when it should be 5760, 283 for 57600, 290 for 576000, etc.

    I tried to reproduce the error on my Ubuntu Linux 64bit system which uses the latest gcc build and looks like an error when using -m32bit-doubles, without that flag the results are correct, when using the flag the results are wrong like you say (I get 278 when I should get 57.60 * 100). I tried to force casts without success, sizeof float and double seems correct, so I'm not sure what may be wrong, but since I don't use any external library, it looks like an error in the compiler itself and independent from the host system.

    You can also reproduce the error without using -m32bit-doubles by using 100.0f in the code above (note the f that should force the float constant). Maybe something is not cast to the correct size internally.
  • macca wrote: »
    DavidZemon wrote: »
    For what it's worth, the last successful build of the RPi GCC 4 build was 18 Apr 15 05:57
    The build log can be seen here: http://david.zemon.name:8111/viewType.html?buildTypeId=PropGCC5_Gcc4rpi&guest=1

    Maybe you should force a build because I believe it doesn't include, at least, the latest fixes to the assembler: I tried to compile some of my sources on the RPi and the compiler seems to not support the underscores in the number constants (like %1_0000_111).

    It's been building every time a commit is made. They've just been failing. Something with libexpat
  • altosackaltosack Posts: 132
    edited 2015-12-19 19:15
    Thanks, macca, when I take out -m32bit-doubles, everything works (well, except that now I can't use Simple Libs; if I include that, it errors out with a message saying that 32bit-doubles is required). I had always used 32bit-doubles because I think C promotes all floats to doubles for internal calculations; since my code size is now ~2k larger, this is probably the case.

    In any case, it works for now (and I can get back to fixing all my code bugs), because most of my speed-sensitive floating point is done by "my" (derived from Cam Thomson's, of course) routines inside of a cog, and in the future, I most likely will be bringing a lot of the higher level stuff out to the RPi, anyway.

    I must say, it's very addictive to be able to ssh into my prop/pi controller from my tablet, edit the code, compile it, run it, and see the results on the tablet (yep, I replaced the "print" from SimpleText with my own already). I could even do this from town if I wanted to. Not that it makes much sense to edit code from my tablet, but I love it that I can !

    A big thanks to all of you that made this possible.
  • altosack: you've actually uncovered a bug in the 32 bit float to integer conversion routine (__fixsfsi). The register conventions for the 32 bit float functions were changed a while back to match the 64 bit functions, but unfortunately we didn't update that conversion routine, so some scratch registers were incorrect (leading to the wrong output). I've pushed a fix for this.

    Thanks for catching the error and giving such a simple reproducer!
  • maccamacca Posts: 783
    edited 2015-12-22 13:19
    ersmith wrote: »
    altosack: you've actually uncovered a bug in the 32 bit float to integer conversion routine (__fixsfsi). The register conventions for the 32 bit float functions were changed a while back to match the 64 bit functions, but unfortunately we didn't update that conversion routine, so some scratch registers were incorrect (leading to the wrong output). I've pushed a fix for this.

    I see the fix is for gcc5, any hint about a fix for gcc4 ?

    Edit:

    Nevermind, the same patch can be applied to the gcc4 tree, I was confused by the different directory layout.
    Works fine with the code above, results are now correct in all cases.
Sign In or Register to comment.