Floating point trouble

Samyukta Ramnath
Hello,
In our codes we are performing a few simple arithmetic operations on float
value. It works fine when compiled with gcc but when we compile with
arm-linux-gc-4.3.2 (no errors while compiling) and run it on the board, we
get a runtime error : 'illegal instruction'. All instructions and print
statements before this particular operation work fine.

The operation we are doing is :
   
    float value;
    int a = 307;

    value = a * 3.3 / 1023.0;

Also, in another code, we have the following operation 

   float a,b;
   scanf("%f",&a);
   b = 1- a;
This works fine when the value of a is less than 0.5, but gives an illegal
instruction when a > 0.5.

Is there anyone who gets the same problem?

We tried fixed point arithmetic as well, to no avail. (still getting
illegal instruction).

Thanks and regards

Samyukta Ramnath
I tried enabling all the Floating point emulations in the kernel during the
step 'make menuconfig', recompiled the kernel and reloaded the zImage.

The following 3 floating point emulators were available(I enabled all):
NWFPE math emulation
Support extended precision
FastFPE math emulation(EXPERIMENTAL)

Then I tried compiling the program with following options:

-msoft-float -D__GCC_NOT_NEEDED -march=armv4 -mtune=920t

-msfloat-abi=soft -D__GCC_NOT_NEEDED -march=armv4 -mtune=920t

I am still getting illegal instruction while executing.

Juergen
Did you build your whole root file system with this compiler? If not, and
you mix applications built with different compiler this kind of failure can
happen.
Another source of trouble can be the pre-configured optimization of the
compiler. Four your Mini2440 you must ensure your compiler (and all its
libryries) must be build for:

$ readelf -A <your-self-compiled-file>
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "4T"
  Tag_CPU_arch: v4T
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int

Compare this output with the output of a file from your root filesystem on
the Mini2440. They should be the same.

Samyukta Ramnath
Thanks for the reply Juergen.
The readelf command on the PC kernel gives the following output for a file
compiled by me:

$ readelf -A <your-self-compiled-file>
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "ARM10TDMI"
  Tag_CPU_arch: v5TE
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: Yes
  Tag_ABI_align_preserved: Yes, except leaf SP
  Tag_ABI_enum_size: int

However, on the mini2440 terminal, it says : '/bin/sh:readelf:not found' So
I was not able to compare both the outputs.
Also, I did not build the root filesystem on my own. I had an image
'rootfs_qtopia_qt4.img' which I dumped onto the board using supervivi
transfer tool.

Should I try building a new root filesystem now?
Thanks a lot!

Juergen
As you can see in the output of the "readelf" command your own software is
made for an ARMv5 CPU. But the CPU on the Mini2440 is of type ARMv4. Your
code must crash, and it is not a problem of the floating point
instructions!

> However, on the mini2440 terminal, it says : '/bin/sh:readelf:not found'

Sure. You must copy one file from its root file system to your host to be
able to run the check.

> Also, I did not build the root filesystem on my own.

Then you must know how this root file system was built. To add your own
software to this existing root filesystem you must use the same toolchain
to make everything consistent.

> Should I try building a new root filesystem now?

If you rely on it, you should do so. Otherwise you will get many funny
error messages if you mix binaries from different sources.

julio menezes
dear all,

1- has Nanopi (1) a HW float point unit ?
2- wich cflags must i use for float point ?

thx,

julio
PS: 
running  nanopi 4.1.2-FriendlyARM  

uname -a shows armv5tejl

cat /proc/cpuinfo shows:
ARM926EJ-S rev 5
arch: 5TEJ
hw: MINI2451

readelf compiled_application -a shows:
Tag_CPU_name: "4T"
Tag_CPU_arch: v4T

from ARM manual:
The ARM926EJ-S processor provides support for external coprocessors
enabling floating-point or other application-specific hardware acceleration
to be added. The ARM926EJ-S processor implements ARM architecture version
5TEJ.