Recent

Author Topic: FPU 80 bit extended precision  (Read 2601 times)

mav

  • Jr. Member
  • **
  • Posts: 83
FPU 80 bit extended precision
« on: February 06, 2023, 07:26:25 pm »
Hello:
Hello, lately every time I update the trunk (I use a stable version and a trunk normally) with fpcup, I see the message: "Adding -dFPC_SOFT_FPUX80
to compiler option to enable 80bit (soft)  float support (trunk only) "...and I ask myself the following questions:
How do you use that "-dFPC_SOFT_FPUX80", is there an example somewhere?
Can it be used in 64 bit applications, in Windows ? (...I am a Windows user).
I usually start by writing code and then when it works,
I do the design of the program... this time I'm doing it backwards.
 Greetings to all!

It takes time and work to learn...!! :D :D ;D ;D    :o

Thaddy

  • Hero Member
  • *****
  • Posts: 16653
  • Kallstadt seems a good place to evict Trump to.
Re: FPU 80 bit extended precision
« Reply #1 on: February 06, 2023, 08:34:17 pm »
The windows 64 ABI by itself does not support this (extended is double) but FPC supports this anyway, but not as standard and requires recompilation. NOT recommended. If you are really and I mean really experienced, I can give you a clue.
Otherwise it is pointless.
« Last Edit: February 06, 2023, 08:39:19 pm by Thaddy »
But I am sure they don't want the Trumps back...

PascalDragon

  • Hero Member
  • *****
  • Posts: 5904
  • Compiler Developer
Re: FPU 80 bit extended precision
« Reply #2 on: February 06, 2023, 10:17:24 pm »
Hello, lately every time I update the trunk (I use a stable version and a trunk normally) with fpcup, I see the message: "Adding -dFPC_SOFT_FPUX80
to compiler option to enable 80bit (soft)  float support (trunk only) "...and I ask myself the following questions:
How do you use that "-dFPC_SOFT_FPUX80", is there an example somewhere?

This is a define that is only respected by the compiler itself and controls whether it uses a software based 80-bit floating point type for cross compiling from a target that does not support 80-bit floating point types (e.g. Win64 on x86_64 or any non-x86 target) to a target that does (e.g. any x86 target that is not x86_64-win64). This define will not enable Extended support on x86_64-win64 and it's also not yet recommended to use that define anyway, because generated binaries will differ from one done with a compiler that has native 80-bit floating point support.

If you want to use 80-bit floating point in your own program then use the sfpux80 and ufloatx80 units. However these are compiled by default only on 3.3.1, not yet on 3.2.2, so you need to compile them yourself.

mav

  • Jr. Member
  • **
  • Posts: 83
Re: FPU 80 bit extended precision
« Reply #3 on: February 07, 2023, 01:01:25 am »
Thanks for answering me.
  Thaddy, I'm not really experienced...but I'll try, I'll post the code I'm doing...I've been looking at the units
  sfpux80 and ufloatx80 and I already started to do something... let's see what comes out... :) :)

photor

  • Jr. Member
  • **
  • Posts: 80
Re: FPU 80 bit extended precision
« Reply #4 on: February 11, 2025, 04:01:44 pm »
Hello, lately every time I update the trunk (I use a stable version and a trunk normally) with fpcup, I see the message: "Adding -dFPC_SOFT_FPUX80
to compiler option to enable 80bit (soft)  float support (trunk only) "...and I ask myself the following questions:
How do you use that "-dFPC_SOFT_FPUX80", is there an example somewhere?

This is a define that is only respected by the compiler itself and controls whether it uses a software based 80-bit floating point type for cross compiling from a target that does not support 80-bit floating point types (e.g. Win64 on x86_64 or any non-x86 target) to a target that does (e.g. any x86 target that is not x86_64-win64). This define will not enable Extended support on x86_64-win64 and it's also not yet recommended to use that define anyway, because generated binaries will differ from one done with a compiler that has native 80-bit floating point support.

If you want to use 80-bit floating point in your own program then use the sfpux80 and ufloatx80 units. However these are compiled by default only on 3.3.1, not yet on 3.2.2, so you need to compile them yourself.
So where can I get these units for 3.2.2? And are there any docs about how to use these units? Thanks.

DragoRosso

  • Guest
Re: FPU 80 bit extended precision
« Reply #5 on: February 11, 2025, 06:08:36 pm »
So where can I get these units for 3.2.2? And are there any docs about how to use these units? Thanks.

You asked in other thread for extended use on 64 bit application, but since is not a standard why you don't use other libraries ?

One very famous lib about big numbers is Rudy Velthuis Big Numbers; this is the link of the new maintainer (he passed aways some years ago): https://github.com/TurboPack/RudysBigNumbers

They don't speak about FPC compatibility, but may be it is.

Take a look.

srvaldez

  • Full Member
  • ***
  • Posts: 127
Re: FPU 80 bit extended precision
« Reply #6 on: February 11, 2025, 11:04:40 pm »
I tried RudysBigNumbers with FPC, no luck
but depending on mav's needs a big number library may be overkill
if all you need is 80 or 128-bit floats then with some tedious work on the bindings you could use softfloat http://www.jhauser.us/arithmetic/SoftFloat.html
« Last Edit: February 11, 2025, 11:07:52 pm by srvaldez »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5904
  • Compiler Developer
Re: FPU 80 bit extended precision
« Reply #7 on: February 13, 2025, 08:59:43 pm »
If you want to use 80-bit floating point in your own program then use the sfpux80 and ufloatx80 units. However these are compiled by default only on 3.3.1, not yet on 3.2.2, so you need to compile them yourself.
So where can I get these units for 3.2.2? And are there any docs about how to use these units? Thanks.

Download the source for 3.2.2 and compile them manually. Regarding use simply add the ufloatx80 unit to your uses-clause and instead of Extended use floatx80. Some additional functions are available in unit sfpux80, but some others are missing (like ln or conversion to string) which is the main reason why 80-bit software floating point can't yet be fully implemented in the compiler.

LV

  • Full Member
  • ***
  • Posts: 239
Re: FPU 80 bit extended precision
« Reply #8 on: February 13, 2025, 09:16:44 pm »
Arbitrary float point precision (80, 128, 256 bits...)
https://github.com/VadimAnIsaev/GNU-MP-for-FreePascal  ;)

srvaldez

  • Full Member
  • ***
  • Posts: 127
Re: FPU 80 bit extended precision
« Reply #9 on: February 15, 2025, 10:46:33 pm »
on Windows you can use libmingwex from the mingw package
libmingwex comes as a static library but it's tricky to link with FPC due to dependencies, so I created a dll which you can get from https://u.pcloud.link/publink/show?code=XZQUNR5ZWS6dIkjFsOVOxDmtYUgd3XaeFwy7
for the basic arithmetic functions you use inline asm and although the FPU has trig and other functions I would choose to use the ones from the libmingwex, because I don't trust that FPU will handle value range ok
Code: Pascal  [Select][+][-]
  1.         {$MODE OBJFPC}{$H+}
  2.         {$MINFPCONSTPREC 64}
  3.         {$MODESWITCH ADVANCEDRECORDS}
  4.         //{$LINKLIB libmingwex}
  5.        
  6.         program libmingwex-test1;
  7.         uses sysutils, windows, math;
  8.        
  9.         type extfloat = record
  10.                 ext_number : array[0..15] of uint8;
  11.         end;
  12.        
  13.         type extfloatp = ^extfloat;
  14.        
  15.         function snprintf ( s:pchar; n:uint32; format:pchar;args: extfloatp):longint;cdecl; external 'libmingwex' name '__mingw_snprintf';
  16.         function strtold (s:pchar;var nd:pchar):extfloat;cdecl; external 'libmingwex' name '__mingw_strtold';
  17.         function scanfld (s:pchar;frmt:pchar;x:extfloatp):int32;cdecl; external 'libmingwex' name '__mingw_sscanf';
  18.        
  19.         function sinl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'sinl';
  20.         function asinl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'asinl';
  21.         function cosl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'cosl';
  22.         function acosl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'acosl';
  23.         function tanl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'tanl';
  24.         function atanl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'atanl';
  25.         function logl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'logl';
  26.         function expl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'expl';
  27.        
  28.         function extsqrt(x: extfloat):extfloat;
  29.         var
  30.           y:extfloat;
  31.         begin
  32.           {$ASMMODE att}
  33.                 asm
  34.                   fldt     x
  35.                   fsqrt
  36.                   fstpt y
  37.                 end;
  38.                 extsqrt:=y;
  39.         end;
  40.  
  41.         function extadd(a: extfloat; b: extfloat):extfloat;
  42.  
  43.         var
  44.           y:extfloat;
  45.         begin
  46.           {$ASMMODE att}
  47.                 asm
  48.                   fldt     a
  49.                   fldt     b
  50.                   faddp   %st, %st(1)
  51.                   fstpt y
  52.                 end;
  53.                 extadd:=y;
  54.         end;
  55.        
  56.         function extsub(a: extfloat; b: extfloat):extfloat;
  57.  
  58.         var
  59.           y:extfloat;
  60.         begin
  61.           {$ASMMODE att}
  62.                 asm
  63.                   fldt     a
  64.                   fldt     b
  65.                   fsubrp   %st, %st(1)
  66.                   fstpt y
  67.                 end;
  68.                 extsub:=y;
  69.         end;
  70.  
  71.         function extmul(a: extfloat; b: extfloat):extfloat;
  72.  
  73.         var
  74.           y:extfloat;
  75.         begin
  76.           {$ASMMODE att}
  77.                 asm
  78.                   fldt     a
  79.                   fldt     b
  80.                   fmulp   %st, %st(1)
  81.                   fstpt y
  82.                 end;
  83.                 extmul:=y;
  84.         end;
  85.        
  86.         function extdiv(a: extfloat; b: extfloat):extfloat;
  87.  
  88.         var
  89.           y:extfloat;
  90.         begin
  91.           {$ASMMODE att}
  92.                 asm
  93.                   fldt     a
  94.                   fldt     b
  95.                   fdivrp   %st, %st(1)
  96.                   fstpt y
  97.                 end;
  98.                 extdiv:=y;
  99.         end;
  100.  
  101.         function extval( s:ansistring):extfloat;
  102.         var
  103.                 pc, frmt:pchar;
  104.                 y:extfloat;
  105.         begin
  106.                 pc:=pchar(s+#0);
  107.                 frmt:='%Lf'+#0;
  108.                 scanfld(pc, frmt, @y);
  109.                 extval:=y;
  110.         end;
  111.  
  112.         function extstr( x:extfloat; frmt:ansistring):ansistring;
  113.         var
  114.                 s, frm:pchar;
  115.                 res:ansistring;
  116.         begin
  117.                 frm:=pchar(frmt+#0);
  118.                 res:='                                                                        ';
  119.                 s:=pchar(res+#0);
  120.                 snprintf(s, 64, frm, @x);
  121.                 extstr:=s;
  122.         end;
  123.        
  124.         const frmt=' %.20Lg';
  125.         var x, y, z:extfloat;
  126.  
  127.         begin
  128.                 x:=extval('2');
  129.                 y:=extval('3');
  130.                 z:=extadd(x, y);
  131.                 writeln(extstr(z, ' %.20Lg'));
  132.                
  133.                 z:=extsub(x, y);
  134.                 writeln(extstr(z, ' %.20Lg'));
  135.                
  136.                 z:=extmul(x, y);
  137.                 writeln(extstr(z, ' %.20Lg'));
  138.                
  139.                 z:=extdiv(x, y);
  140.                 writeln(extstr(z, ' %.20Lg'));
  141.                
  142.                 z:=extsqrt(x);
  143.                 writeln(extstr(z, ' %.20Lg'));
  144.         end.
  145.  

Quote
5
 -1
 6
 0.66666666666666666668
 1.4142135623730950488

srvaldez

  • Full Member
  • ***
  • Posts: 127
Re: FPU 80 bit extended precision
« Reply #10 on: February 15, 2025, 10:56:26 pm »
by the way, I found that I had to add #0 to the strings for the functions in libmingwex otherwise it would crash

photor

  • Jr. Member
  • **
  • Posts: 80
Re: FPU 80 bit extended precision
« Reply #11 on: February 18, 2025, 09:54:26 am »
on Windows you can use libmingwex from the mingw package
libmingwex comes as a static library but it's tricky to link with FPC due to dependencies, so I created a dll which you can get from https://u.pcloud.link/publink/show?code=XZQUNR5ZWS6dIkjFsOVOxDmtYUgd3XaeFwy7
for the basic arithmetic functions you use inline asm and although the FPU has trig and other functions I would choose to use the ones from the libmingwex, because I don't trust that FPU will handle value range ok
Code: Pascal  [Select][+][-]
  1.         {$MODE OBJFPC}{$H+}
  2.         {$MINFPCONSTPREC 64}
  3.         {$MODESWITCH ADVANCEDRECORDS}
  4.         //{$LINKLIB libmingwex}
  5.        
  6.         program libmingwex-test1;
  7.         uses sysutils, windows, math;
  8.        
  9.         type extfloat = record
  10.                 ext_number : array[0..15] of uint8;
  11.         end;
  12.        
  13.         type extfloatp = ^extfloat;
  14.        
  15.         function snprintf ( s:pchar; n:uint32; format:pchar;args: extfloatp):longint;cdecl; external 'libmingwex' name '__mingw_snprintf';
  16.         function strtold (s:pchar;var nd:pchar):extfloat;cdecl; external 'libmingwex' name '__mingw_strtold';
  17.         function scanfld (s:pchar;frmt:pchar;x:extfloatp):int32;cdecl; external 'libmingwex' name '__mingw_sscanf';
  18.        
  19.         function sinl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'sinl';
  20.         function asinl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'asinl';
  21.         function cosl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'cosl';
  22.         function acosl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'acosl';
  23.         function tanl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'tanl';
  24.         function atanl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'atanl';
  25.         function logl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'logl';
  26.         function expl (x:extfloatp):extfloat;cdecl; external 'libmingwex' name 'expl';
  27.        
  28.         function extsqrt(x: extfloat):extfloat;
  29.         var
  30.           y:extfloat;
  31.         begin
  32.           {$ASMMODE att}
  33.                 asm
  34.                   fldt     x
  35.                   fsqrt
  36.                   fstpt y
  37.                 end;
  38.                 extsqrt:=y;
  39.         end;
  40.  
  41.         function extadd(a: extfloat; b: extfloat):extfloat;
  42.  
  43.         var
  44.           y:extfloat;
  45.         begin
  46.           {$ASMMODE att}
  47.                 asm
  48.                   fldt     a
  49.                   fldt     b
  50.                   faddp   %st, %st(1)
  51.                   fstpt y
  52.                 end;
  53.                 extadd:=y;
  54.         end;
  55.        
  56.         function extsub(a: extfloat; b: extfloat):extfloat;
  57.  
  58.         var
  59.           y:extfloat;
  60.         begin
  61.           {$ASMMODE att}
  62.                 asm
  63.                   fldt     a
  64.                   fldt     b
  65.                   fsubrp   %st, %st(1)
  66.                   fstpt y
  67.                 end;
  68.                 extsub:=y;
  69.         end;
  70.  
  71.         function extmul(a: extfloat; b: extfloat):extfloat;
  72.  
  73.         var
  74.           y:extfloat;
  75.         begin
  76.           {$ASMMODE att}
  77.                 asm
  78.                   fldt     a
  79.                   fldt     b
  80.                   fmulp   %st, %st(1)
  81.                   fstpt y
  82.                 end;
  83.                 extmul:=y;
  84.         end;
  85.        
  86.         function extdiv(a: extfloat; b: extfloat):extfloat;
  87.  
  88.         var
  89.           y:extfloat;
  90.         begin
  91.           {$ASMMODE att}
  92.                 asm
  93.                   fldt     a
  94.                   fldt     b
  95.                   fdivrp   %st, %st(1)
  96.                   fstpt y
  97.                 end;
  98.                 extdiv:=y;
  99.         end;
  100.  
  101.         function extval( s:ansistring):extfloat;
  102.         var
  103.                 pc, frmt:pchar;
  104.                 y:extfloat;
  105.         begin
  106.                 pc:=pchar(s+#0);
  107.                 frmt:='%Lf'+#0;
  108.                 scanfld(pc, frmt, @y);
  109.                 extval:=y;
  110.         end;
  111.  
  112.         function extstr( x:extfloat; frmt:ansistring):ansistring;
  113.         var
  114.                 s, frm:pchar;
  115.                 res:ansistring;
  116.         begin
  117.                 frm:=pchar(frmt+#0);
  118.                 res:='                                                                        ';
  119.                 s:=pchar(res+#0);
  120.                 snprintf(s, 64, frm, @x);
  121.                 extstr:=s;
  122.         end;
  123.        
  124.         const frmt=' %.20Lg';
  125.         var x, y, z:extfloat;
  126.  
  127.         begin
  128.                 x:=extval('2');
  129.                 y:=extval('3');
  130.                 z:=extadd(x, y);
  131.                 writeln(extstr(z, ' %.20Lg'));
  132.                
  133.                 z:=extsub(x, y);
  134.                 writeln(extstr(z, ' %.20Lg'));
  135.                
  136.                 z:=extmul(x, y);
  137.                 writeln(extstr(z, ' %.20Lg'));
  138.                
  139.                 z:=extdiv(x, y);
  140.                 writeln(extstr(z, ' %.20Lg'));
  141.                
  142.                 z:=extsqrt(x);
  143.                 writeln(extstr(z, ' %.20Lg'));
  144.         end.
  145.  

Sorry, what is this for? Hardware F80 with FPU for Free Pascal on Win64 or just software simulation?
« Last Edit: February 23, 2025, 12:02:56 pm by photor »

 

TinyPortal © 2005-2018