Unable to run application with hard floats

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
robu
Posts: 25
Joined: Sat Nov 24, 2012 3:39 pm

Unable to run application with hard floats

Post by robu »

Hi,
I wanted to test the running speed between the hard float and soft float, so I made a simple example:

Code: Select all

        unsigned long i, j;

   unsigned long start = chTimeNow();
   float * data;
   float * data2;
   data = (float *) calloc(100000, sizeof(float));
   data2 = (float *) calloc(100000, sizeof(float));
   chprintf((BaseSequentialStream *) &SD1, "Main (SD1 started)\r\n");
   chprintf((BaseSequentialStream *) &SD1, "Here\r\n");
   chprintf((BaseSequentialStream *) &SD1, "%d\r\n", (int) data[1]);
   for (i = 0; i < 100000; i++) {
      data[i] = 12;
      data2[i] = 22;
   }
   chprintf((BaseSequentialStream *) &SD1, "%d\r\n", (int) data[1]);
   data[1] *= data[2];
   for (j = 0; j < 1000; j++) {
      for (i = 0; i < 100000; i++)
         data[i] *= data2[i];
   }
   free(data);
   free(data2);
   chprintf((BaseSequentialStream *) &SD1, "Ticks:%d\r\n", chTimeNow() - start);
   chprintf((BaseSequentialStream *) &SD1, "End\r\n");


When I compile with the following flags:

Code: Select all

USE_OPT = -O2 -ggdb -fomit-frame-pointer 

Everything is working fine

Code: Select all

[2012-12-04 19:23:48.757] Main (SD1 started)
[2012-12-04 19:23:48.762] Here
[2012-12-04 19:23:48.762] 0
[2012-12-04 19:23:48.775] 12
[2012-12-04 19:24:57.492] Ticks:68771
[2012-12-04 19:24:57.492] End


According the Raspberry FAQ I have to use the following flags

Code: Select all

USE_OPT = -march=armv6 -mfpu=vfp -mfloat-abi=hard

to compile the code with hardware float support, but in this case I'm receiving the following message through UART

Code: Select all

[2012-12-04 19:30:33.910] Main (SD1 

It seams that the system stops, what can be the problem with the hardware floating point?

Robert
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Unable to run application with hard floats

Post by Giovanni »

Hi,

The ARM7/9 port used by the RPI port does not support the hard FPU so probably the problem is that the coprocessor is uninitialized.

Giovanni
robu
Posts: 25
Joined: Sat Nov 24, 2012 3:39 pm

Re: Unable to run application with hard floats

Post by robu »

Hi
Thanks for your help, now it's working, a bit faster than before, from 2.4ms to 1.9ms.
I'm making some matrix operation which include dynamic memory allocation and also I'm using memory management function like memcpy, memset etc.

I also installed Arch Linux on the RPI where the runtime was 0.4ms. I thought that the RTOS has to be faster, because on the Arch Linux are running a lot of stuff like networking ssh server etc.

Is that possible that I made some error in the ChibiOS setup and that cause the slow runtime?

Thanks,
Robert
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Unable to run application with hard floats

Post by Giovanni »

Hi,

The OS kind should not affect that kind of benchmark, note that the time returned by chTimeNow() has a 1mS resolution so you cannot measure such small intervals, 1.9 or 2.4 is within the measurement jitter. Try creating a benchmark lasting at least a second.

Giovanni
robu
Posts: 25
Joined: Sat Nov 24, 2012 3:39 pm

Re: Unable to run application with hard floats

Post by robu »

Hi,

Yes I did, I made the same calculation 5000 times and I measured this time interval.

Robert
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Unable to run application with hard floats

Post by Giovanni »

There are two possible explanations I can think of:
1) Differences in compiler or libraries (very possible, probably it is newlib for the embedded compiler and gnu clib for linux)
2) RPI port not initializing the HW in an optimal way (wait states or other details like that)

Giovanni
Post Reply