Author Topic: GCC 4.4+/libc065: SIGFPEs with various C functions & speed of doubles  (Read 1517 times)

agena@alex

  • Newbie
  • *
  • Thank You
  • -Given: 14
  • -Receive: 6
  • Posts: 36
    • View Profile
Hello,

I am currently porting an interpreter to eCS 2.2 using various GCC compilers (4.4.x, 4.5.x, 4.7.x)
kindly provided by Paul Smedley. I run eCS on Sun VirtualBox 4.3.12.

In my regression tests, I notice various SIGFPE crashes obviously issued via libc065 when trying
to call C's trunc, cosh, and sinh functions (thus far). Is this a known issue with eCS/GCC ?

The interpreter heavily relies on the use of doubles in numerical loops, etc. Although it never has
been fast on my late native OS/2 Warp 4 machine many years ago, the interpreter is running
unbearably slow now on eCS. When compiling, I use the following switches:

os2static:
   $(MAKE) all MYCFLAGS="-O2 -static-libgcc -fomit-frame-pointer -D__ST_MT_ERRNO__ (+ some Agena/Lua non-numerical switches)"

Is there an approriate switch to speed up double arithmetic ?

Thank you,

Alex
« Last Edit: September 04, 2014, 12:19:43 pm by agena@alex »



Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 7
  • -Receive: 87
  • Posts: 1095
    • View Profile
Re: GCC 4.4+/libc065: SIGFPEs with various C functions & speed of doubles
« Reply #1 on: September 04, 2014, 04:55:24 pm »
The problem is a bug somewhere in the PMSHELL where the floating point control word is not restored after the DLL enables FPU exceptions. There is a libc bug open to add a workaround to libc and hopefully it'll be fixed there.
For now something like this usually works (multi-threaded apps may need more complex solutions)
Code: [Select]
int main(int argc, char **argv)
 {
+#ifdef __i386
+    short fcr;
+    __asm__ volatile ("fstcw        %0 \n"
+                      "or      $63, %0 \n"
+                      "fldcw        %0 \n"
+                      : "=m"(fcr));
+#endif
+

agena@alex

  • Newbie
  • *
  • Thank You
  • -Given: 14
  • -Receive: 6
  • Posts: 36
    • View Profile
Re: GCC 4.4+/libc065: SIGFPEs with various C functions & speed of doubles
« Reply #2 on: September 04, 2014, 05:57:01 pm »
Dave,

gosh !  Your fix works great - no FPU exceptions any longer and the interpreter
has become super-fast now, as well.

Thank you very much,

Alex

agena@alex

  • Newbie
  • *
  • Thank You
  • -Given: 14
  • -Receive: 6
  • Posts: 36
    • View Profile
Re: GCC 4.4+/libc065: SIGFPEs with various C functions & speed of doubles
« Reply #3 on: September 05, 2014, 10:15:55 am »
Hello,

I had been wondering last night how anybody can port current OpenSource projects
to eCS with this very substantial (libc06*.dll ?) bug.

Without Dave's help, I would have surrendered.

Alex

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 7
  • -Receive: 87
  • Posts: 1095
    • View Profile
Re: GCC 4.4+/libc065: SIGFPEs with various C functions & speed of doubles
« Reply #4 on: September 05, 2014, 04:32:48 pm »
It's an OS/2/eCS bug, doesn't affect my Warp v4 install. It only affects programs that do some types of floating point which is surprisingly few and workarounds such as I posted have to be added.  Some such as Mozilla can get complex making sure that every thread doesn't sigfpe.
BTW, have you looked at exceptq http://hobbes.nmsu.edu/download/pub/os2/dev/util/exceptq71-dev.zip, catches crashes and outputs some nice debugging info.