Jeppe already told me that floating point could be a little shaky on Cortex-M, and he was right...

I am creating examples for the Raspberry Pi Pico and the ADC example requires some floating point math.

All testing was done with trunk version of fpc from today

RTL was compiled with empty CROSSOPTS options, for details please see end of text.


The first issue smells a lot like an optimization issue, when I compile rtl with -O- then it is gone.


First issue is about mutiplication/division.

The same code run with single datatype creates (wrong) negative result for this multiplication:

  rawvalue := 887;
  value := rawvalue*3.3/(1 shl 12);


The 2nd one is a bit more strange, here I am asking myself if I forgot something:

  str(value:6:3,valuestr);

When I compile the code with double my string version of the number is prefixed by 10 or so spaces.

when I compile with single datatype output of str is fine, no spaces as prefix.

When I comment out the three codelines behind the str command and compile with double I get correct transformation without the prefixed spaces.

When I compile RTL with -O- then double shows correctly and single is prefixed with spaces.


Commandline to compile code:

fpc -Tembedded -Parm -Cparmv6m -godwarfsets -godwarfcpp -Wp-WpNUCLEOG071RB floatmult.lpr

(I compile here for NUCLEOG071RB as Raspberry Pico is not yet in trunk)

Sample Code:

program floatmult;
{$MODE OBJFPC}
{$H-}
var
  //value : single; // gives -0.715 in line 11+12
  value : double; // gives 0.715 in line 11+12
  rawvalue : longWord;
  valuestr : string;
begin
  rawvalue := 887;
  value := rawvalue*3.3/(1 shl 12);
  str(value:6:3,valuestr);
  //value := value - 0.706;
  //value := value / 0.001721;
  //value := 27 - value;
end.


Building fpc RTL for armv6m
+ make --directory=/Users/ring/devel/fpc FPCDIR=/Users/ring/devel/fpc FPCMAKE=/Users/ring/devel/fpc/utils/fpcm/fpcmake PPUMOVE=/Users/ring/fpcupdeluxe-embedded/fpc/bin/x86_64-darwin/ppumove INSTALL_PREFIX=/Users/ring/fpcupdeluxe-embedded/fpc INSTALL_BINDIR=/Users/ring/fpcupdeluxe-embedded/fpc/bin/x86_64-darwin CROSSBINDIR=/Users/ring/fpcupdeluxe-embedded/fpc/bin/x86_64-darwin FPC=/Users/ring/fpcupdeluxe-embedded/fpc/bin/x86_64-darwin/ppcarm rtl_clean rtl_all CROSSINSTALL=1 CPU_SOURCE=x86_64 OS_SOURCE=darwin OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv6m NOGDBMI=1 BINUTILSPREFIX=arm-none-eabi- 'OPT=-vw-n-h-l-d-u-t-p-c- -ap -Fl/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib' CROSSOPT= INSTALL_UNITDIR=/Users/ring/fpcupdeluxe-embedded/fpc/units/arm-embedded/armv6m/rtl
+ pv '--name=Build  ' --line-mode --size 50

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to