AI assisted translation of CORE-MATH to Free Pascal lazarus / 83-Pascal and AI ---------------------------------------------------------------------- MathMan · 2026-04-12 08:02 I have spawned this topic from thread 'Can /my/ AI help me with pascal coding?' as I foresee substantial exchange on this topic, deserving a separate thread. Can one of the admins please take the related posts from the original thread over to here? Regards, MathMan ---------------------------------------------------------------------- MathMan · 2026-04-12 08:22 @schuler, Regarding your request to validate 'BenchmarkFPC'. I get substantially different results (compared to the ones posted under https://github.com/joaopauloschuler/pas-core-math/tree/main#benchmark- results) on my machine. Environment: - FPC 3.2.2 - Zen 3 (AMD Ryzen 7 7730U) @ 4.5 GHz - 16 GByte - all checks and assertions disabled, debug info kept Result O1: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i === FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   15,3 Mops/s  PCM:   39,7 Mops/s  FASTER! YAY!cosf            FPC:   15,1 Mops/s  PCM:   41,8 Mops/s  FASTER! YAY!tanf            FPC:   29,4 Mops/s  PCM:   39,3 Mops/s  FASTER! YAY!asinf           FPC:  133,7 Mops/s  PCM:  206,6 Mops/s  FASTER! YAY!acosf           FPC:  110,1 Mops/s  PCM:  164,5 Mops/s  FASTER! YAY!atanf           FPC:  200,8 Mops/s  PCM:  127,2 Mops/ssinhf             FPC: 86,5 Mops/s  PCM:  182,5 Mops/s  FASTER! YAY!coshf             FPC:  158,2 Mops/s  PCM:  194,6 Mops/s  FASTER! YAY!tanhf             FPC:  193,1 Mops/s  PCM:  156,7 Mops/sasinhf            FPC:   41,1 Mops/s  PCM:   83,5 Mops/s  FASTER! YAY!acoshf            FPC:   87,0 Mops/s  PCM:  161,3 Mops/s  FASTER! YAY!atanhf            FPC:   44,6 Mops/s  PCM:  197,6 Mops/s  FASTER! YAY!expf              FPC:  196,1 Mops/s  PCM:  163,9 Mops/slogf              FPC:   69,5 Mops/s  PCM:  142,0 Mops/s  FASTER! YAY!log2f             FPC:   66,6 Mops/s  PCM:  144,9 Mops/s  FASTER! YAY!log10f            FPC:   66,7 Mops/s  PCM:  143,7 Mops/s  FASTER! YAY!atan2f            FPC:  167,8 Mops/s  PCM:   66,6 Mops/shypotf            FPC:  153,8 Mops/s  PCM:   75,5 Mops/spowf            FPC:   39,8 Mops/s  PCM:   39,2 Mops/s  TIEsincosf           FPC:   24,1 Mops/s  PCM:   37,5 Mops/s  FASTER! YAY! PCM won: 14  |  FPC won: 5  |  Ties (<5%): 1On average, PCM is 1,7x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 591609502 (prevents dead-code elimination)  Result O3: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i === FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   15,5 Mops/s  PCM:   90,9 Mops/s  FASTER! YAY!cosf            FPC:   15,3 Mops/s  PCM:   82,0 Mops/s  FASTER! YAY!tanf            FPC:   32,9 Mops/s  PCM:   84,2 Mops/s  FASTER! YAY!asinf           FPC:  151,1 Mops/s  PCM:  328,9 Mops/s  FASTER! YAY!acosf           FPC:  126,9 Mops/s  PCM:  299,4 Mops/s  FASTER! YAY!atanf           FPC:  227,3 Mops/s  PCM:  252,5 Mops/s  FASTER! YAY!sinhf           FPC:   96,2 Mops/s  PCM:  214,6 Mops/s  FASTER! YAY!coshf           FPC:  170,1 Mops/s  PCM:  247,5 Mops/s  FASTER! YAY!tanhf           FPC:  211,9 Mops/s  PCM:  266,0 Mops/s  FASTER! YAY!asinhf          FPC:   42,7 Mops/s  PCM:  173,6 Mops/s  FASTER! YAY!acoshf          FPC:  108,5 Mops/s  PCM:  290,7 Mops/s  FASTER! YAY!atanhf          FPC:   45,5 Mops/s  PCM:  285,7 Mops/s  FASTER! YAY!expf            FPC:  227,3 Mops/s  PCM:  337,8 Mops/s  FASTER! YAY!logf              FPC:   77,2 Mops/s  PCM:  285,7 Mops/s  FASTER! YAY!log2f           FPC:   72,0 Mops/s  PCM:  312,5 Mops/s  FASTER! YAY!log10f            FPC:   72,8 Mops/s  PCM:  320,5 Mops/s  FASTER! YAY!atan2f            FPC:  176,1 Mops/s  PCM:  166,1 Mops/shypotf            FPC:  290,7 Mops/s  PCM:  167,2 Mops/spowf              FPC:   42,7 Mops/s  PCM:  100,4 Mops/s  FASTER! YAY!sincosf           FPC:   24,2 Mops/s  PCM: 73,1 Mops/s  FASTER! YAY! PCM won: 18  |  FPC won: 2  |  Ties (<5%): 0On average, PCM is 2,9x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 591609502 (prevents dead-code elimination)  Result O4 + -CfAVX2 -CpCOREI -OpCOREI -dAVX2 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i === FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   15,4 Mops/s  PCM:   91,4 Mops/s  FASTER! YAY!cosf            FPC:   15,3 Mops/s  PCM:   85,8 Mops/s  FASTER! YAY!tanf            FPC:   33,1 Mops/s  PCM:   85,0 Mops/s  FASTER! YAY!asinf           FPC:  160,8 Mops/s  PCM:  331,1 Mops/s  FASTER! YAY!acosf           FPC:  128,2 Mops/s  PCM:  303,0 Mops/s  FASTER! YAY!atanf           FPC:  240,4 Mops/s  PCM:  260,4 Mops/s  FASTER! YAY!sinhf           FPC:   96,3 Mops/s  PCM:  212,8 Mops/s  FASTER! YAY!coshf           FPC:  175,4 Mops/s  PCM:  243,9 Mops/s  FASTER! YAY!tanhf           FPC:  211,0 Mops/s  PCM:  270,3 Mops/s  FASTER! YAY!asinhf          FPC:   42,7 Mops/s  PCM:  174,8 Mops/s  FASTER! YAY!acoshf          FPC:  109,6 Mops/s  PCM:  295,9 Mops/s  FASTER! YAY!atanhf          FPC:   45,4 Mops/s  PCM:  292,4 Mops/s  FASTER! YAY!expf            FPC:  245,1 Mops/s  PCM:  318,5 Mops/s  FASTER! YAY!logf              FPC:   77,2 Mops/s  PCM:  289,0 Mops/s  FASTER! YAY!log2f           FPC:   72,7 Mops/s  PCM:  316,5 Mops/s  FASTER! YAY!log10f            FPC:   72,3 Mops/s  PCM:  318,5 Mops/s  FASTER! YAY!atan2f            FPC:  197,6 Mops/s  PCM:  167,2 Mops/shypotf            FPC:  287,4 Mops/s  PCM:  162,9 Mops/spowf              FPC:   42,8 Mops/s  PCM:  100,2 Mops/s  FASTER! YAY!sincosf           FPC:   24,4 Mops/s  PCM: 69,1 Mops/s  FASTER! YAY! PCM won: 18  |  FPC won: 2  |  Ties (<5%): 0On average, PCM is 2,9x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 591609502 (prevents dead-code elimination) ---------------------------------------------------------------------- Paolo · 2026-04-12 09:39 @mathman, out of curiosity: - the test is done for different function argument ? - comparison of numerical results is done (I mean the results are the same for both the cases?) Ciao. ---------------------------------------------------------------------- marcov · 2026-04-12 11:11 Maybe benchmark with -Cfcoreavx2 or so too ?   (or 64-bit). Basically FPC has two sets of FPU implementation for x86, x87 and sse2+.   Win64 defaults to the sse2 option. ---------------------------------------------------------------------- MathMan · 2026-04-12 11:44 Quote from: Paolo on April 12, 2026, 11:39:19 am@mathman, out of curiosity: - the test is done for different function argument ? - comparison of numerical results is done (I mean the results are the same for both the cases?) Ciao. @Paolo - the function arguments are spread over the full range of Single - the results are definitly not the same for various functions and arguments, as current FPC RTL is not fully correctly rounded across functions and arguments However the majority of the FPC CORE-MATH functions (2 or 3 exceptions) has been verified against the C implementation of CORE- MATH. ---------------------------------------------------------------------- MathMan · 2026-04-12 11:53 Quote from: marcov on April 12, 2026, 01:11:04 pmMaybe benchmark with -Cfcoreavx2 or so too ?   (or 64-bit). Basically FPC has two sets of FPU implementation for x86, x87 and sse2+.   Win64 defaults to the sse2 option. Here we go FPC 3.2.2 -O4 -CfAVX2 -CpCoreAVX2 -OpCoreAVX2 -dAVX2 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i === FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   15,7 Mops/s  PCM:   73,2 Mops/s  FASTER! YAY!cosf            FPC:   15,4 Mops/s  PCM:   68,0 Mops/s  FASTER! YAY!tanf            FPC:   33,2 Mops/s  PCM:   67,3 Mops/s  FASTER! YAY!asinf           FPC:  155,8 Mops/s  PCM:  340,1 Mops/s  FASTER! YAY!acosf           FPC:  126,3 Mops/s  PCM:  335,6 Mops/s  FASTER! YAY!atanf           FPC:  243,9 Mops/s  PCM:  279,3 Mops/s  FASTER! YAY!sinhf           FPC:   96,7 Mops/s  PCM:  214,6 Mops/s  FASTER! YAY!coshf           FPC:  183,8 Mops/s  PCM:  252,5 Mops/s  FASTER! YAY!tanhf           FPC:  224,2 Mops/s  PCM:  276,2 Mops/s  FASTER! YAY!asinhf          FPC:   42,8 Mops/s  PCM:  186,6 Mops/s  FASTER! YAY!acoshf          FPC:  108,9 Mops/s  PCM:  188,0 Mops/s  FASTER! YAY!atanhf          FPC:   45,9 Mops/s  PCM:  297,6 Mops/s  FASTER! YAY!expf            FPC:  239,2 Mops/s  PCM:  340,1 Mops/s  FASTER! YAY!logf              FPC:   78,7 Mops/s  PCM:  280,9 Mops/s  FASTER! YAY!log2f           FPC:   73,4 Mops/s  PCM:  333,3 Mops/s  FASTER! YAY!log10f            FPC:   74,2 Mops/s  PCM:  303,0 Mops/s  FASTER! YAY!atan2f            FPC:  183,2 Mops/s  PCM:  163,4 Mops/shypotf            FPC:  287,4 Mops/s  PCM:  175,4 Mops/spowf              FPC:   43,8 Mops/s  PCM:  105,9 Mops/s  FASTER! YAY!sincosf           FPC:   24,0 Mops/s  PCM: 58,6 Mops/s  FASTER! YAY! PCM won: 18  |  FPC won: 2  |  Ties (<5%): 0On average, PCM is 2,7x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 591609502 (prevents dead-code elimination)  and FPC 3.3.1 -O4 -CfFMA -CpZEN3 -OpZEN3 -dAVX2 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i === FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   19,1 Mops/s  PCM:   90,1 Mops/s  FASTER! YAY!cosf            FPC:   19,3 Mops/s  PCM:   85,5 Mops/s  FASTER! YAY!tanf            FPC:   33,2 Mops/s  PCM:   82,4 Mops/s  FASTER! YAY!asinf           FPC:  191,6 Mops/s  PCM:  335,6 Mops/s  FASTER! YAY!acosf           FPC:  157,7 Mops/s  PCM:  312,5 Mops/s  FASTER! YAY!atanf           FPC:  252,5 Mops/s  PCM:  267,4 Mops/s  FASTER! YAY!sinhf           FPC:  185,2 Mops/s  PCM:  216,5 Mops/s  FASTER! YAY!coshf           FPC:  177,9 Mops/s  PCM:  251,3 Mops/s  FASTER! YAY!tanhf           FPC:  145,8 Mops/s  PCM:  282,5 Mops/s  FASTER! YAY!asinhf          FPC:   42,8 Mops/s  PCM:  177,3 Mops/s  FASTER! YAY!acoshf          FPC:  113,1 Mops/s  PCM:  264,6 Mops/s  FASTER! YAY!atanhf          FPC:   46,2 Mops/s  PCM:  289,0 Mops/s  FASTER! YAY!expf            FPC:  227,3 Mops/s  PCM:  352,1 Mops/s  FASTER! YAY!logf              FPC:   77,6 Mops/s  PCM:  285,7 Mops/s  FASTER! YAY!log2f           FPC:   73,0 Mops/s  PCM:  316,5 Mops/s  FASTER! YAY!log10f            FPC:   72,6 Mops/s  PCM:  316,5 Mops/s  FASTER! YAY!atan2f            FPC:  215,5 Mops/s  PCM:  121,4 Mops/shypotf            FPC:  318,5 Mops/s  PCM:  176,7 Mops/spowf              FPC:   45,1 Mops/s  PCM: 79,9 Mops/s  FASTER! YAY!sincosf           FPC:   24,2 Mops/s  PCM:   81,7 Mops/s  FASTER! YAY! PCM won: 18  |  FPC won: 2  |  Ties (<5%): 0On average, PCM is 2,7x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 2161696855 (prevents dead-code elimination)  Notice, that the GlobalSink is different from the previous results. As this is simply a full xor'ing of all results some computations must yield different results. ---------------------------------------------------------------------- schuler · 2026-04-12 12:27 very good morning @mathman, love your testing! ---------------------------------------------------------------------- MathMan · 2026-04-12 12:59 Good morning to you too, @schuler  Unfortunately I can not test as much as I'd like. I'm a hobbyist running Win64 and FPC only - no Linux & C compiler here. Nevertheless - I currently go through the sources in depth. Already detected several things that I would handle different - but a full report will take some more time. What's really bothering me is the double-rounding issue (e.g. in 'compundf'). I spotted it when I coarsly scanned the sources first time and thought "that is asking for trouble" - only to find, when I later read the 'tasklist.md', that there actually is trouble ... ---------------------------------------------------------------------- schuler · 2026-04-12 13:23 @mathman and everyone, to be able to compile and test in linux for free, in github, you can press the green “code” button at https://github.com/joaopauloschuler/pas-core-math/ and then create a free codespace. The repo is ready to install all dependencies. You will wait a bit to build the codespace and then you will be ready to compile with build.sh and then run the tests. ---------------------------------------------------------------------- MathMan · 2026-04-12 21:48 @schuler, Here is my first feedback. There is probably more to come, but I wanted to provide a first response today. All of the following is in light of use under FPC 3.2.2. 1. FPC 3.2.2 can not inline across units 1.1. the design of 'pascoremathtypes' and 'pascoremathhelperfuncs' should be modified accordingly 1.2. 'pascoremathtypes' should only contain type definitions - the operator overload of + and the MulWide functions should be moved 1.3. pack all functions from 'pascoremathtypes' and 'pascoremathhelperfuncs' that are marked as inline into a separate include file that is then included in the implementation section of 'pascoremath' 1.4. 'pascoremathhelperfunc' should then contain all functions that are not marked as inline - including 'pcr_poly12' 1.5. due to this there is no use in marking the 'pcr...' functions of 'pascoremath' as inline 2. FPC can not inline functions with asm - try to directly resolve this into the 'pcr...' functions. 3. FPC 3.2.2 already provides intrinsics for forward/reverse bitscan and arithmetic shift right - 'BsfDWord', 'BsrDWord', 'SarLongInt' & 'SarInt64'. Use these and replace the locally defined equivalents 'pcr_bsf32' etc. Advantage is that the intrinsics will be inlined automatically, whereas the locally defined variants use asm in some cases, which can not be inlined and generate calls to subroutine. 4. 'MulWide' should be renamed to 'Mulu64u64' I think. Beside that the pure Pascal variant can be inlined and is therefore faster than the asm variant, which can not be inlined. Finally the pure Pascal implementation is not good - it uses way to many variables. A better implementation would be Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function Mulu64u64(a, b: UInt64): TUInt128; inline;var  MulHi: UInt64;   // intermediates for double limb product calculation  MulLo: UInt64;  Temp1: UInt64;  Temp2: UInt64;begin  MulLo := Lo( a ) * Lo( b );  Temp1 := ( a shr 32 ) * Lo( b );  Temp2 := Lo( a ) * ( b shr 32 ) + Lo( Temp1 ) + ( MulLo shr 32 );  MulLo := Lo( MulLo ) + ( Temp2 shl 32 );  MulHi := ( a shr 32 ) * ( b shr 32 ) + ( Temp1 shr 32 ) + ( Temp2 shr 32 );   // these must be the last actions, as Low=Val1 or Low=Val2 is possible  Result.lo := MulLo;  Result.hi := MulHi;end; 5. I think the type system is lacking - strictly use the FPC types UInt32, UInt64, Int32 and Int64. Especially avoid casts to Integer. 6. I think the benchmark should be modified. The current approach goes through the full range of input parameter(s) on a fixed stride. However, in real live scenarios, the majority of calls (like 90%) have the parameter(s) in a sweet spot range - i.e. -10.0..10.0 for the trigonometrics, -1.0..1.0 for the hyperbolics etc. And within that sweet spot the values are distributed uniform mainly. Can the benchmark be modified in a way that the values are taken from an array, which is prefilled with random values according to the above description? 7. still open 7.1. the double rounding issue and sub-sequent failures of 'compundf' etc. 7.2. investigate why 'pcr_atan2f' and 'pcr_hypotf' are slower than the current FPC RTL equivalents. I suspect that the RTL implementation only follows a fast path and has lots of errors in the outer regions. 7.3. can you have BPSA implement a similar check of FPC RTL functions against the CORE MATH C library, like there is for the Pascal CORE MATH? 8. Constants 8.1. All tables have been converted from C hexadecimal floating point notation to decimal floating point notation for Pascal. But decimal fp notation is a can of worms - especially when getting close to +/-Inf or into the sub-normal range. As there are already compound types available 'tb32u32' and 'tb64u64' I suggest to convert the hex floats to UInt32 / UInt64 and modify the tables accordingly. 8.2. same holds for constants used in the function implementations - I would also try to use UInt32 / UInt64 throughout. Funnily some of the 'pcr..' functions already have this - i.e. 'pcr_rsqrtf' or 'pcr_tanhf' - while others don't. Cheers, MathMan ---------------------------------------------------------------------- nanobit · 2026-04-13 08:35 Quote from: MathMan on April 12, 2026, 11:48:54 pm A better implementation would be Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function Mulu64u64(a, b: UInt64): TUInt128; inline;var  MulHi: UInt64;   // intermediates for double limb product calculation  MulLo: UInt64;  Temp1: UInt64;  Temp2: UInt64;begin  MulLo := Lo( a ) * Lo( b );  Temp1 := ( a shr 32 ) * Lo( b );  Temp2 := Lo( a ) * ( b shr 32 ) + Lo( Temp1 ) + ( MulLo shr 32 );  MulLo := Lo( MulLo ) + ( Temp2 shl 32 );  MulHi := ( a shr 32 ) * ( b shr 32 ) + ( Temp1 shr 32 ) + ( Temp2 shr 32 );   // these must be the last actions, as Low=Val1 or Low=Val2 is possible  Result.lo := MulLo;  Result.hi := MulHi;end; Lo( a ) * Lo( b ) will give uint32 under cpu32. I modified your routine somewhat: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  MulLo, Temp1, Temp2: UInt64;begin  MulLo := uint64(uint32(a)) * uint64(uint32(b));  Temp1 := (a shr 32) * uint64(uint32(b)) + (MulLo shr 32);   Temp2 := uint64(uint32(a)) * (b shr 32) + uint64(uint32(Temp1));   Result.lo := (Temp2 shl 32) or (MulLo and $FFFFFFFF);  Result.hi := (a shr 32) * (b shr 32) + (Temp1 shr 32) + (Temp2 shr 32); end; ---------------------------------------------------------------------- schuler · 2026-04-13 12:21 STATUS UPDATE Out of all original 32 bits float functions, 6 functions do not produce a binary exact result according to the original C implementation. In all 6 functions that fail the binary test, the numerical error is smaller than 10^(-18).In 2 linux machines, the new functions compared to the existing FPC functions are 20x faster according to the benchmarking code BenchmarkFPC32. I would like to ask for more members of this forum to replicate this experiment as it varies from hardware to hardware. In windows, the speed gain is in the range from 2x to 3x. Given that my own Neural API is mostly run on Linux, I’m already making plans to use pas-core-math with CAI Neural API. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ lscpu | grep "Model name"Model name:                              13th Gen Intel(R) Core(TM) i7-1355U bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ uname -aLinux Ubuntu24 6.17.0-20-generic #20~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 01:28:37 UTC 2 x86_64 x86_64 x86_64 GNU/Linux bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ ./bin/BenchmarkFPC32=== FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   45.3 Mops/s  PCM:  135.1 Mops/s  FASTER! YAY!cosf              FPC:   44.0 Mops/s  PCM:  130.2 Mops/s  FASTER! YAY!tanf              FPC:   17.1 Mops/s  PCM:  132.6 Mops/s  FASTER! YAY!asinf             FPC:    8.4 Mops/s  PCM:  431.0 Mops/s  FASTER! YAY!acosf             FPC:    8.1 Mops/s  PCM:  201.6 Mops/s  FASTER! YAY!atanf             FPC:   27.8 Mops/s  PCM:  347.2 Mops/s  FASTER! YAY!sinhf             FPC:    5.3 Mops/s  PCM:  347.2 Mops/s  FASTER! YAY!coshf             FPC:    5.4 Mops/s  PCM:  409.8 Mops/s  FASTER! YAY!tanhf             FPC:   31.6 Mops/s  PCM:  294.1 Mops/s  FASTER! YAY!asinhf            FPC:   27.9 Mops/s  PCM:  238.1 Mops/s  FASTER! YAY!acoshf            FPC:    6.3 Mops/s  PCM:  187.3 Mops/s  FASTER! YAY!atanhf            FPC:    7.0 Mops/s  PCM:  431.0 Mops/s  FASTER! YAY!expf              FPC:   16.7 Mops/s  PCM:  179.2 Mops/s  FASTER! YAY!logf              FPC:   46.1 Mops/s  PCM:  233.6 Mops/s  FASTER! YAY!log2f             FPC:   43.3 Mops/s  PCM:  271.7 Mops/s  FASTER! YAY!log10f            FPC:   14.4 Mops/s  PCM:  400.0 Mops/s  FASTER! YAY!atan2f            FPC:   17.6 Mops/s  PCM:   92.1 Mops/s  FASTER! YAY!hypotf            FPC:   67.0 Mops/s  PCM:  203.3 Mops/s  FASTER! YAY!powf              FPC:    1.8 Mops/s  PCM:  106.2 Mops/s  FASTER! YAY!sincosf           FPC:   18.2 Mops/s  PCM:  108.7 Mops/s  FASTER! YAY! PCM won: 20  |  FPC won: 0  |  Ties (<5%): 0On average, PCM is 24.6x faster than FPC (arithmetic mean over 19 functions)  bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ LD_LIBRARY_PATH=/home/bpsa/app/pas-core-math/src/tests/.. /home/bpsa/app/pas-core-math/src/tests/../../bin/Benchmark32=== Benchmark: 50000000 calls per function ===acosf             C:  349.7 Mops/s  Pascal:  174.8 Mops/s  sink=MATCHacoshf            C:  127.9 Mops/s  Pascal:  176.1 Mops/s  sink=MATCH  FASTER! YAY!acospif         C:  227.3 Mops/s  Pascal:  220.3 Mops/s  sink=MATCH  TIEasinf           C:  365.0 Mops/s  Pascal:  416.7 Mops/s  sink=MATCH  FASTER! YAY!asinhf            C:  243.9 Mops/s  Pascal:  222.2 Mops/s  sink=MATCHasinpif           C:  216.5 Mops/s  Pascal:  197.6 Mops/s  sink=MATCHatanf             C:  301.2 Mops/s  Pascal:  337.8 Mops/s  sink=MATCH  FASTER! YAY!atanhf            C:  378.8 Mops/s  Pascal:  393.7 Mops/s  sink=MATCH  TIEatanpif           C:  373.1 Mops/s  Pascal:  413.2 Mops/s  sink=MATCH  FASTER! YAY!cbrtf             C:  229.4 Mops/s  Pascal:  181.8 Mops/s  sink=MATCHcosf              C:  218.3 Mops/s  Pascal:  119.3 Mops/s  sink=MISMATCHcoshf             C:  312.5 Mops/s  Pascal:  400.0 Mops/s  sink=MATCH  FASTER! YAY!cospif            C:  373.1 Mops/s  Pascal:  378.8 Mops/s  sink=MISMATCH  TIEerff              C:  326.8 Mops/s  Pascal:  183.2 Mops/s  sink=MATCHerfcf             C:  340.1 Mops/s  Pascal:  354.6 Mops/s  sink=MATCH  TIEexpf              C:  320.5 Mops/s  Pascal:  167.8 Mops/s  sink=MATCHexp10f            C:  304.9 Mops/s  Pascal:  308.6 Mops/s  sink=MATCH  TIEexp10m1f          C:  274.7 Mops/s  Pascal:  248.8 Mops/s  sink=MATCHexp2f             C:  333.3 Mops/s  Pascal:  335.6 Mops/s  sink=MATCH  TIEexp2m1f           C:  297.6 Mops/s  Pascal:  340.1 Mops/s  sink=MATCH  FASTER! YAY!expm1f          C:  299.4 Mops/s  Pascal:  340.1 Mops/s  sink=MATCH  FASTER! YAY!lgammaf           C:  138.9 Mops/s  Pascal:   35.9 Mops/s  sink=MATCHlogf              C:  367.6 Mops/s  Pascal:  314.5 Mops/s  sink=MATCHlog10f            C:  263.2 Mops/s  Pascal:  362.3 Mops/s  sink=MATCH  FASTER! YAY!log10p1f          C:  219.3 Mops/s  Pascal:  158.2 Mops/s  sink=MATCHlog1pf            C:  333.3 Mops/s  Pascal:  316.5 Mops/s  sink=MATCHlog2f             C:  335.6 Mops/s  Pascal:  337.8 Mops/s  sink=MATCH  TIElog2p1f           C:  352.1 Mops/s  Pascal:  183.2 Mops/s  sink=MATCHrsqrtf            C:  171.2 Mops/s  Pascal:  463.0 Mops/s  sink=MATCH  FASTER! YAY!sinf              C:  214.6 Mops/s  Pascal:  126.6 Mops/s  sink=MISMATCHsinhf             C:  312.5 Mops/s  Pascal:  333.3 Mops/s  sink=MATCH  FASTER! YAY!sinpif            C:  378.8 Mops/s  Pascal:  375.9 Mops/s  sink=MISMATCH  TIEtanf              C:  192.3 Mops/s  Pascal:  121.7 Mops/s  sink=MISMATCHtanhf             C:  312.5 Mops/s  Pascal:  284.1 Mops/s  sink=MATCHtanpif            C:  204.1 Mops/s  Pascal:  219.3 Mops/s  sink=MISMATCH  FASTER! YAY!tgammaf           C:  314.5 Mops/s  Pascal:  123.5 Mops/s  sink=MATCHatan2f            C:  260.4 Mops/s  Pascal:   85.5 Mops/s  sink=MATCHatan2pif          C:    6.6 Mops/s  Pascal:    3.2 Mops/s  sink=MATCHhypotf            C:  156.3 Mops/s  Pascal:  202.4 Mops/s  sink=MATCH  FASTER! YAY!powf            C:  151.1 Mops/s  Pascal:   95.4 Mops/s  sink=MISMATCHcompoundf       C:   99.4 Mops/s  Pascal:  110.9 Mops/s  sink=MISMATCH  FASTER! YAY!sincosf           C:  199.2 Mops/s  Pascal:   95.8 Mops/s  sink=MATCH Pascal won: 13  |  C won: 21  |  Ties (<5%): 8  bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ LD_LIBRARY_PATH=/home/bpsa/app/pas-core-math/src/tests/.. /home/bpsa/app/pas-core-math/src/tests/../../bin/TestHarness32=== TestHarness: comparing Pascal (pcr_*) vs C (cr_*) ===acosf           tested=4294967296  mismatches=2  FAIL max_error=0.000000000000000000acoshf            tested=4294967296  mismatches=0  PASSacospif           tested=4294967296  mismatches=0  PASSasinf             tested=4294967296  mismatches=0  PASSasinhf          tested=4294967296  mismatches=0  PASSasinpif           tested=4294967296  mismatches=0  PASSatanf             tested=4294967296  mismatches=0  PASSatanhf            tested=4294967296  mismatches=0  PASSatanpif           tested=4294967296  mismatches=0  PASScbrtf             tested=4294967296  mismatches=0  PASScosf              tested=4294967296  mismatches=0  PASScoshf             tested=4294967296  mismatches=0  PASScospif            tested=4294967296  mismatches=0  PASSerff              tested=4294967296  mismatches=0  PASSerfcf             tested=4294967296  mismatches=0  PASSexpf              tested=4294967296  mismatches=1  FAIL max_error=0.000000000000000000exp10f            tested=4294967296  mismatches=0  PASSexp10m1f          tested=4294967296  mismatches=0  PASSexp2f             tested=4294967296  mismatches=0  PASSexp2m1f         tested=4294967296  mismatches=0  PASSexpm1f            tested=4294967296  mismatches=0  PASSlgammaf           tested=4294967296  mismatches=0  PASSlogf              tested=4294967296  mismatches=0  PASSlog10f            tested=4294967296  mismatches=0  PASSlog10p1f          tested=4294967296  mismatches=0  PASSlog1pf            tested=4294967296  mismatches=0  PASSlog2f             tested=4294967296  mismatches=0  PASSlog2p1f           tested=4294967296  mismatches=1  FAIL max_error=0.000000000000000000rsqrtf            tested=4294967296  mismatches=0  PASSsinf              tested=4294967296  mismatches=0  PASSsinhf             tested=4294967296  mismatches=0  PASSsinpif          tested=4294967296  mismatches=0  PASStanf              tested=4294967296  mismatches=0  PASStanhf             tested=4294967296  mismatches=0  PASStanpif            tested=4294967296  mismatches=0  PASStgammaf           tested=4294967296  mismatches=1  FAIL max_error=0.000000000000000000atan2f            tested=  10000000  mismatches=0  PASSatan2pif          tested=  10000000  mismatches=0  PASShypotf            tested=  10000000  mismatches=0  PASSpowf            tested=  10000000  mismatches=458657  FAIL max_error=0.000000000000000000compoundf         tested=  10000000  mismatches=1903717  FAIL max_error=0.000000000000000000sincosf         tested=4294967296  mismatches=0  PASS === TOTAL: 36 PASS, 6 FAIL === ---------------------------------------------------------------------- schuler · 2026-04-13 12:25 @mathman, many thanks for spending time with a detailed code review. I’ll FUP. note: QuoteIn old versions of Free Pascal, inline code was not exported from a unit. This meant that when calling an inline procedure from another unit, a normal procedure call will be performed. Only inside units, Inline procedures are really inlined. As of version 2.0.2, inline works across units.https://www.freepascal.org/docs- html/ref/refsu77.html ---------------------------------------------------------------------- MathMan · 2026-04-13 20:02 Quote from: schuler on April 13, 2026, 02:25:26 pm@mathman, many thanks for spending time with a detailed code review. I’ll FUP. note: QuoteIn old versions of Free Pascal, inline code was not exported from a unit. This meant that when calling an inline procedure from another unit, a normal procedure call will be performed. Only inside units, Inline procedures are really inlined. As of version 2.0.2, inline works across units.https://www.freepascal.org/docs- html/ref/refsu77.html @schuler, I stand corrected - somehow this crucial info passed me by. ---------------------------------------------------------------------- schuler · 2026-04-13 20:41 @mathman, from your list: 3) Done. 4) Renaming: done. 5) Done for Int32. ---------------------------------------------------------------------- MathMan · 2026-04-14 07:09 @nanobit Well spotted, thank you. I only tested on a 64 bit machine and this escaped me. Question - you are using the 'and $ffffffff' to avoid possible range or overflow checks, correct? My intention was to embrace the function with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$push}{$R-}{$Q-}{$pop} So the anding could be skipped. ---------------------------------------------------------------------- nanobit · 2026-04-14 08:36 Quote from: MathMan on April 14, 2026, 09:09:53 amSo the anding could be skipped. Yes, ((Temp2 shl 32) or (MulLo and $FFFFFFFF)) can be safely used after check-off. Remark: I've already avoided (a and $FFFFFFFF) in the math-operations, because typecasted math-operands are faster there. But the optimization-issue occurs only in math-expressions, not in others (bitwise-or). ---------------------------------------------------------------------- Thaddy · 2026-04-14 08:45 Besides, turning R and Q off is x-platform safe. ---------------------------------------------------------------------- schuler · 2026-04-14 09:53 I will commit nanobit's solution. ---------------------------------------------------------------------- MathMan · 2026-04-14 10:13 @schuler, here is my understanding on the use of Fused Multiply Accumulate - FMA - a bit lengthy, please bear with me. TL/DR - the functions pcr_fmaf and pcr_fma have to be replaced. There seems to be no way to avoid a bit-wizardry based fallback option. 9. Pascal CORE-MATH currently uses the following implementation to make FMA3 instructions accessible under x86-64 Code: [Select]function pcr_fmaf(x, y, z: Single): Single; {$IFDEF CPUX86_64} // Pure-asm: System V AMD64 ABI passes x→xmm0, y→xmm1, z→xmm2; result in xmm0. // VFMADD213SS: xmm0 = xmm0 * xmm1 + xmm2  (correctly rounded IEEE 754 FMA). assembler; asm   vfmadd213ss xmm0, xmm1, xmm2 end; {$ELSE} begin   // 80-bit fallback: correctly rounded for singles (Extended has enough mantissa bits).   Result := Single(Extended(x) * Extended(y) + Extended(z)); end; {$ENDIF} function pcr_fma(x, y, z: Double): Double; {$IFDEF CPUX86_64} // Pure-asm: System V AMD64 ABI passes x→xmm0, y→xmm1, z→xmm2; result in xmm0. // VFMADD213SD: xmm0 = xmm0 * xmm1 + xmm2  (correctly rounded IEEE 754 FMA). assembler; asm   vfmadd213sd xmm0, xmm1, xmm2 end; {$ELSE} begin   // 80-bit fallback (double-rounding — not true FMA; may lose 1 ULP in rare cases).   Result := Double(Extended(x) * Extended(y) + Extended(z)); end; {$ENDIF} 9.1. The asm variant depends on {$IFDEF CPUX86_64}, which is false. There are x86-64 CPU that do not support FMA3 - e.g. AMD Bulldozer - where this will lead to illegal instruction exceptions. 9.1.1. On x86-64 at least all CPU that support AVX2 also support FMA3. There is a small set of CPU that support the latter without supporting the former - e.g. AMD Steamroller. 9.1.2. Afaik FPC 3.2.2. has no reliable internal detection mechanism for support of FMA on different CPU architectures (x86-64, ARM, etc.) or AVX2 on x86-64 - e.g. via a publizised run-time define from the compiler. 9.1.3. Suggestion: at least make the asm variant depend on {$IFDEF AVX2} where the define has to be provided via command line '-dAVX2'. 9.2. The fallback variant uses a double rounding approach via the Extended type - this is not going to work x-plattform not even for the target architecture x86-64. 9.2.1. Programmer’s Guide for Free Pascal, Version 3.2.2 states QuoteExtended For Intel 80x86 processors, the extended type takes up 10 bytes of memory space. For more information on the extended type, consult the Intel Programmer’s reference. For all other processors which support floating point operations, the extended type is a nickname for the type which supports the most precision, this is usually the double type. On processors which do not support co-processor operations (and which have the {$E+} switch), the extended type usually maps to the single type. On Win64 especially the type Extended is aliased with Double, leaving zero bit redundancy in the mantissa for pcr_fma. On some other plattforms this even holds for pcr_fmaf. 9.2.2. Due to the above the fallback alternative must be implemented via bit-wizardry. 9.3. Potential future option 9.3.1. The FPC 3.2.2 RTL exports intrinsics FMASingle, FMADouble together with run-time defines FPC_HAS_FAST_FMA_SINGLE and FPC_HAS_FAST_FMA_DOUBLE. The intrinsics are stated as 'Do not use' in the runtime manual. Though not reliable yet this might become available in future FPC versions. If so, the asm variant could be replaced and by that the pcr_... can be fully inlined by the compiler. 9.3.2. I could convince FPC 3.2.2 to compile the intrinsics under the following settings '-CfAVX2 -CpCOREAVX2 -OpCOREAVX2'. I replaced the pcr_... with equivalent intrinsics and checked the generated object code. A quick run of the benchmark utility yielded unchanged 'GlobalSink' value. However, I could not convince FPC 3.3.1 to do the same, even though I tried several target architecture settings. I would really like a feedback from FPC core devs if my summary above is correct, and especially if my envisioned co-operation of intrinsics and defines is the way to go. ---------------------------------------------------------------------- gidesa · 2026-04-14 10:46 I obtained these results, hope this helps. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AMD Ryzen 7Free Pascal Compiler version 3.3.1-17136-g3b7d9956ca-dirty [2024/12/27] for x86_64Optimization options: -O4   -CfFMA -CpZEN3 -OpZEN3 Windows 11 64 bit: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i === FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   11,1 Mops/s  PCM:   58,3 Mops/s  FASTER! YAY!cosf            FPC:   10,9 Mops/s  PCM:   58,3 Mops/s  FASTER! YAY!tanf            FPC:   27,5 Mops/s  PCM:   56,3 Mops/s  FASTER! YAY!asinf           FPC:  128,2 Mops/s  PCM:  253,8 Mops/s  FASTER! YAY!acosf           FPC:  104,8 Mops/s  PCM:  219,3 Mops/s  FASTER! YAY!atanf           FPC:  163,9 Mops/s  PCM:  185,9 Mops/s  FASTER! YAY!sinhf           FPC:  153,8 Mops/s  PCM:  160,8 Mops/s  TIEcoshf             FPC:  180,5 Mops/s  PCM:  188,0 Mops/s  TIEtanhf             FPC:   89,4 Mops/s  PCM:  206,6 Mops/s  FASTER! YAY!asinhf            FPC:   31,0 Mops/s  PCM:  123,8 Mops/s  FASTER! YAY!acoshf            FPC:   82,4 Mops/s  PCM:  196,1 Mops/s  FASTER! YAY!atanhf            FPC:   31,9 Mops/s  PCM:  237,0 Mops/s  FASTER! YAY!expf              FPC:  165,0 Mops/s  PCM:  257,7 Mops/s  FASTER! YAY!logf              FPC: 55,7 Mops/s  PCM:  200,8 Mops/s  FASTER! YAY!log2f             FPC: 52,8 Mops/s  PCM:  227,3 Mops/s  FASTER! YAY!log10f            FPC:   52,1 Mops/s  PCM:  223,2 Mops/s  FASTER! YAY!atan2f            FPC:  151,1 Mops/s  PCM:  104,6 Mops/shypotf            FPC:  253,8 Mops/s  PCM:  139,7 Mops/spowf              FPC:   31,5 Mops/s  PCM:   52,9 Mops/s  FASTER! YAY!sincosf           FPC:   22,0 Mops/s  PCM:   54,5 Mops/s  FASTER! YAY! PCM won: 16  |  FPC won: 2  |  Ties (<5%): 2On average, PCM is 2,8x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 2297463453 (prevents dead-code elimination)  Ubuntu 24.04 64 bit (WSL embedded into Windows): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i === FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function === sinf              FPC:   29.8 Mops/s  PCM:   48.2 Mops/s  FASTER! YAY!cosf            FPC:   47.5 Mops/s  PCM:   46.9 Mops/s  TIEtanf            FPC:   29.2 Mops/s  PCM:   46.9 Mops/s  FASTER! YAY!asinf           FPC:   19.3 Mops/s  PCM:  266.0 Mops/s  FASTER! YAY!acosf           FPC:   21.5 Mops/s  PCM:  196.9 Mops/s  FASTER! YAY!atanf             FPC:   20.0 Mops/s  PCM:  177.3 Mops/s  FASTER! YAY!sinhf             FPC:   53.5 Mops/s  PCM:  152.0 Mops/s  FASTER! YAY!coshf             FPC:   49.0 Mops/s  PCM:  176.1 Mops/s  FASTER! YAY!tanhf             FPC:   31.3 Mops/s  PCM:  180.5 Mops/s  FASTER! YAY!asinhf            FPC:   16.2 Mops/s  PCM:  104.4 Mops/s  FASTER! YAY!acoshf            FPC:   27.4 Mops/s  PCM:  211.9 Mops/s  FASTER! YAY!atanhf            FPC:   13.1 Mops/s  PCM:  241.5 Mops/s  FASTER! YAY!expf              FPC:   42.1 Mops/s  PCM:  151.1 Mops/s  FASTER! YAY!logf              FPC:   50.0 Mops/s  PCM:  154.3 Mops/s  FASTER! YAY!log2f           FPC:   35.0 Mops/s  PCM:  204.1 Mops/s  FASTER! YAY!log10f            FPC:   33.2 Mops/s  PCM:  207.5 Mops/s  FASTER! YAY!atan2f            FPC:   17.0 Mops/s  PCM:   97.5 Mops/s  FASTER! YAY!hypotf            FPC:   33.1 Mops/s  PCM:  114.2 Mops/s  FASTER! YAY!powf              FPC:   11.9 Mops/s  PCM:   37.4 Mops/s  FASTER! YAY!sincosf         FPC:   21.6 Mops/s  PCM:   48.6 Mops/s  FASTER! YAY! PCM won: 19  |  FPC won: 0  |  Ties (<5%): 1On average, PCM is 5.9x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 2862567869 (prevents dead-code elimination) ---------------------------------------------------------------------- Thaddy · 2026-04-14 11:27 Small question: is logf the same as ln? I have patch code to patch the operators sin, cos, exp and ln in system, but not for math (that does not work yet) ---------------------------------------------------------------------- MathMan · 2026-04-14 11:54 Quote from: Thaddy on April 14, 2026, 01:27:37 pmSmall question: is logf the same as ln? I have patch code to patch the operators sin, cos, exp and ln in system, but not for math (that does not work yet) It is - single precision is indicated by the trailing 'f'. ---------------------------------------------------------------------- Thaddy · 2026-04-14 16:06 I can only patch those against extended. Have to to run tests if it is still faster. ---------------------------------------------------------------------- marcov · 2026-04-14 16:15 Retry win64 with {$excessprecision off}. Though that might not help for RTL routines, just common arithmetic. ---------------------------------------------------------------------- schuler · 2026-04-14 18:31 @mathman, Quote9.1.3. Suggestion: at least make the asm variant depend on {$IFDEF AVX2} where the define has to be provided via command line '-dAVX2'. I've just pushed this change to git. ---------------------------------------------------------------------- MathMan · 2026-04-14 19:19 @schuler, I'm looking into bug B from 'tasklist.md' - a bit at odds with the analysis. First it states QuoteRoot cause (suspected): pcr_fma is a double-rounding approximation (Double(Extended(x)*Extended(y)+Extended(z))), not a true IEEE FMA. When FPC inlines it, the Double(...) cast may not force a spill to memory, leaving intermediate values at 80-bit extended precision. This excess precision in z_pf (the reduced argument) or h_pf propagates through the exponential polynomial and shifts rr_pf to the wrong side of the float32 midpoint. But in your environment the asm path is taken in pcr_fma. That one uses correctly rounded FMA3 while the error persist (at least as mentioned (at least as per info from 'tasklist.md'). Then there is QuoteOption 2: Force intermediate variables to be stored to memory (defeating x87 register caching) by adding volatile-style stores — but FPC has no standard mechanism for this. This is incorrect - a spill to memory can be provoked in FPC like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i pTypeOfResult( @Result )^ := function( whatever ); Imho the error is introduced somewhere else - do you agree? Before I continue my analysis - did you do further investigation on your side, that has not been publicised yet? ---------------------------------------------------------------------- schuler · 2026-04-15 00:17 @mathman, I agree with you. At least a portion of the compoundf problem is unrelated to fma. I was able to fix the "powf" and made progress in the "compoundf" in the branch "a3" that stands for attempt 3: https://github.com/joaopauloschuler/pas-core-math/tree/a3 ---------------------------------------------------------------------- nanobit · 2026-04-15 04:14 Quote from: schuler on April 14, 2026, 11:53:28 amI will commit nanobit's solution. Minor optimization: It's safe to remove one mask. I've updated my first post. (Reason: the anticipated maximal native size (64) will not exceed the size (64) of temp2 and target). ---------------------------------------------------------------------- Thaddy · 2026-04-15 04:54 I did my own interface to the C lib. Maybe the way I solved the generics  part by using overloads is of interest, so I attach it. It is recommended to compile the coremath library yourself, because there were some linker issues with the standard binary (coff related). Of course I understand that a full native Pascal version is preferred. It is just about the generic part. ---------------------------------------------------------------------- schuler · 2026-04-15 16:00 STATUS UPDATE Only 1 function now fails for the full harness test as per below logs. On average, pas-core-math is ~2.4× faster than FPC builtins in Windows. In Linux, pas-core-math is 6-20x times faster than FPC builtins. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ ./build.sh -dAVX2 -CfAVX2 -CpCOREI -OpCOREIbpsa@Ubuntu24:~/app/pas-core-math/src/tests$ LD_LIBRARY_PATH=/home/bpsa/app/pas-core-math/src/tests/.. /home/bpsa/app/pas-core-math/src/tests/../../bin/TestHarness32 --diag 10Compiled with AVX2.=== TestHarness: comparing Pascal (pcr_*) vs C (cr_*) === acosf             tested=4294967296  mismatches=0  PASSacoshf            tested=4294967296  mismatches=0  PASSacospif         tested=4294967296  mismatches=0  PASSasinf             tested=4294967296  mismatches=0  PASSasinhf            tested=4294967296  mismatches=0  PASSasinpif           tested=4294967296  mismatches=0  PASSatanf             tested=4294967296  mismatches=0  PASSatanhf            tested=4294967296  mismatches=0  PASSatanpif           tested=4294967296  mismatches=0  PASScbrtf             tested=4294967296  mismatches=0  PASScosf              tested=4294967296  mismatches=0  PASScoshf             tested=4294967296  mismatches=0  PASScospif            tested=4294967296  mismatches=0  PASSerff              tested=4294967296  mismatches=0  PASSerfcf             tested=4294967296  mismatches=0  PASSexpf              tested=4294967296  mismatches=0  PASSexp10f            tested=4294967296  mismatches=0  PASSexp10m1f          tested=4294967296  mismatches=0  PASSexp2f             tested=4294967296  mismatches=0  PASSexp2m1f           tested=4294967296  mismatches=0  PASSexpm1f            tested=4294967296  mismatches=0  PASSlgammaf           tested=4294967296  mismatches=0  PASSlogf              tested=4294967296  mismatches=0  PASSlog10f            tested=4294967296  mismatches=0  PASSlog10p1f          tested=4294967296  mismatches=0  PASSlog1pf            tested=4294967296  mismatches=0  PASSlog2f             tested=4294967296  mismatches=0  PASSlog2p1f           tested=4294967296  mismatches=0  PASSrsqrtf            tested=4294967296  mismatches=0  PASSsinf              tested=4294967296  mismatches=0  PASSsinhf             tested=4294967296  mismatches=0  PASSsinpif            tested=4294967296  mismatches=0  PASStanf              tested=4294967296  mismatches=0  PASStanhf             tested=4294967296  mismatches=0  PASStanpif            tested=4294967296  mismatches=0  PASStgammaf           tested=4294967296  mismatches=0  PASSatan2f            tested=  10000000  mismatches=0  PASSatan2pif          tested=  10000000  mismatches=0  PASShypotf            tested=  10000000  mismatches=0  PASSpowf              tested=  10000000  mismatches=0  PASS  [compoundf] x=$1464EDE1(1.15579717E-26) y=$69C66EBB(2.99862778E25)  C=$3FB50546(1.41422343)  P=$3F350546(0.707111716)  [compoundf] x=$1464EF8E(1.15583022E-26) y=$69C67069(2.99872693E25)  C=$3FB50643(1.41425359)  P=$3F350643(0.707126796)  [compoundf] x=$1464F13B(1.15586327E-26) y=$69C67217(2.99882608E25)  C=$3FB50741(1.41428387)  P=$3F350741(0.707141936)  [compoundf] x=$1464F2E8(1.15589631E-26) y=$69C673C5(2.99892523E25)  C=$3FB5083E(1.41431403)  P=$3F35083E(0.707157016)  [compoundf] x=$1464F495(1.15592936E-26) y=$69C67573(2.99902438E25)  C=$3FB5093C(1.41434431)  P=$3F35093C(0.707172155)  [compoundf] x=$1464F642(1.15596241E-26) y=$69C67721(2.99912353E25)  C=$3FB50A3A(1.41437459)  P=$3F350A3A(0.707187295)  [compoundf] x=$1464F7EF(1.15599546E-26) y=$69C678CF(2.99922268E25)  C=$3FB50B37(1.41440475)  P=$3F350B37(0.707202375)  [compoundf] x=$1464F99C(1.15602851E-26) y=$69C67A7D(2.99932184E25)  C=$3FB50C35(1.41443503)  P=$3F350C35(0.707217515)  [compoundf] x=$1464FB49(1.15606156E-26) y=$69C67C2B(2.99942099E25)  C=$3FB50D32(1.41446519)  P=$3F350D32(0.707232594)  [compoundf] x=$1464FCF6(1.15609461E-26) y=$69C67DD9(2.99952014E25)  C=$3FB50E30(1.41449547)  P=$3F350E30(0.707247734)compoundf         tested=  10000000  mismatches=314296  FAIL max_error=0.707247734069824219sincosf           tested=4294967296  mismatches=0  PASS === TOTAL: 41 PASS, 1 FAIL ===  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ LD_LIBRARY_PATH=/home/bpsa/app/pas-core-math/src/tests/.. /home/bpsa/app/pas-core-math/src/tests/../../bin/Benchmark32Compiled with AVX2.=== Benchmark: 200000000 calls per function === acosf           C:  336.1 Mops/s  Pascal:  181.0 Mops/s  sink=MATCHacoshf          C:  126.8 Mops/s  Pascal:  165.2 Mops/s  sink=MISMATCH  FASTER! YAY!acospif           C:  220.5 Mops/s  Pascal:  230.4 Mops/s  sink=MISMATCH  TIEasinf             C:  353.4 Mops/s  Pascal:  435.7 Mops/s  sink=MATCH  FASTER! YAY!asinhf            C:  239.8 Mops/s  Pascal:  216.5 Mops/s  sink=MATCHasinpif           C:  237.2 Mops/s  Pascal:  192.3 Mops/s  sink=MISMATCHatanf             C:  321.5 Mops/s  Pascal:  322.6 Mops/s  sink=MATCH  TIEatanhf            C:  283.3 Mops/s  Pascal:  382.4 Mops/s  sink=MATCH  FASTER! YAY!atanpif         C:  380.2 Mops/s  Pascal:  426.4 Mops/s  sink=MATCH  FASTER! YAY!cbrtf             C:  223.2 Mops/s  Pascal:  173.5 Mops/s  sink=MATCHcosf              C:  219.5 Mops/s  Pascal:  119.0 Mops/s  sink=MATCHcoshf             C:  351.5 Mops/s  Pascal:  390.6 Mops/s  sink=MATCH  FASTER! YAY!cospif            C:  337.3 Mops/s  Pascal:  347.8 Mops/s  sink=MATCH  TIEerff              C:  304.0 Mops/s  Pascal:  184.2 Mops/s  sink=MATCHerfcf             C:  335.0 Mops/s  Pascal:  364.3 Mops/s  sink=MATCH  FASTER! YAY!expf              C:  313.0 Mops/s  Pascal:  161.2 Mops/s  sink=MATCHexp10f            C:  292.0 Mops/s  Pascal:  289.0 Mops/s  sink=MATCH  TIEexp10m1f          C:  295.0 Mops/s  Pascal:  234.2 Mops/s  sink=MATCHexp2f             C:  339.6 Mops/s  Pascal:  351.5 Mops/s  sink=MATCH  TIEexp2m1f         C:  249.1 Mops/s  Pascal:  386.8 Mops/s  sink=MATCH  FASTER! YAY!expm1f            C:  319.5 Mops/s  Pascal:  309.1 Mops/s  sink=MATCH  TIElgammaf           C:  125.9 Mops/s  Pascal:   34.1 Mops/s  sink=MATCHlogf              C:  371.1 Mops/s  Pascal:  304.9 Mops/s  sink=MATCHlog10f            C:  232.0 Mops/s  Pascal:  316.5 Mops/s  sink=MATCH  FASTER! YAY!log10p1f          C:  192.5 Mops/s  Pascal:  135.3 Mops/s  sink=MATCHlog1pf            C:  284.9 Mops/s  Pascal:  244.2 Mops/s  sink=MATCHlog2f             C:  307.2 Mops/s  Pascal:  285.7 Mops/s  sink=MATCHlog2p1f           C:  236.7 Mops/s  Pascal:  171.4 Mops/s  sink=MATCHrsqrtf            C:  191.9 Mops/s  Pascal:  413.2 Mops/s  sink=MISMATCH  FASTER! YAY!sinf              C:  195.1 Mops/s  Pascal:  114.0 Mops/s  sink=MATCHsinhf             C:  320.0 Mops/s  Pascal:  361.0 Mops/s  sink=MATCH  FASTER! YAY!sinpif            C:  364.3 Mops/s  Pascal:  371.1 Mops/s  sink=MATCH  TIEtanf              C:  193.8 Mops/s  Pascal:  118.4 Mops/s  sink=MATCHtanhf             C:  304.4 Mops/s  Pascal:  289.9 Mops/s  sink=MATCHtanpif            C:  201.4 Mops/s  Pascal:  218.6 Mops/s  sink=MATCH  FASTER! YAY!tgammaf           C:  273.6 Mops/s  Pascal:  125.2 Mops/s  sink=MATCHatan2f            C:  256.7 Mops/s  Pascal:   89.2 Mops/s  sink=MATCHatan2pif          C:    6.9 Mops/s  Pascal:    2.0 Mops/s  sink=MATCHhypotf            C:  112.9 Mops/s  Pascal:  145.3 Mops/s  sink=MATCH  FASTER! YAY!powf              C: 73.4 Mops/s  Pascal:   78.1 Mops/s  sink=MATCH  FASTER! YAY!compoundf       C:   86.8 Mops/s  Pascal:  123.2 Mops/s  sink=MISMATCH  FASTER! YAY!sincosf           C:  211.2 Mops/s  Pascal:  109.6 Mops/s  sink=MATCH Pascal won: 14  |  C won: 21  |  Ties (<5%): 7On average, Pascal is 1.08x slower than C (arithmetic mean over 42 functions)  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i bpsa@Ubuntu24:~/app/pas-core-math/src/tests$ LD_LIBRARY_PATH=/home/bpsa/app/pas-core-math/src/tests/.. /home/bpsa/app/pas-core- math/src/tests/../../bin/BenchmarkFPC32Compiled with AVX2.=== FPC vs Pascal CORE-MATH (PCM) Benchmark: 50000000 calls per function ===sinf            FPC:   46.3 Mops/s  PCM:  130.9 Mops/s  FASTER! YAY!cosf            FPC:   43.1 Mops/s  PCM:  134.8 Mops/s  FASTER! YAY!tanf            FPC:   17.2 Mops/s  PCM:  125.6 Mops/s  FASTER! YAY!asinf           FPC:    8.4 Mops/s  PCM:  431.0 Mops/s  FASTER! YAY!acosf           FPC:    8.2 Mops/s  PCM:  211.0 Mops/s  FASTER! YAY!atanf           FPC:   28.1 Mops/s  PCM:  312.5 Mops/s  FASTER! YAY!sinhf           FPC:    5.4 Mops/s  PCM:  335.6 Mops/s  FASTER! YAY!coshf           FPC:    5.5 Mops/s  PCM:  367.6 Mops/s  FASTER! YAY!tanhf           FPC:   31.6 Mops/s  PCM:  282.5 Mops/s  FASTER! YAY!asinhf          FPC:   27.5 Mops/s  PCM:  238.1 Mops/s  FASTER! YAY!acoshf          FPC:    6.3 Mops/s  PCM:  188.0 Mops/s  FASTER! YAY!atanhf          FPC:    7.0 Mops/s  PCM:  413.2 Mops/s  FASTER! YAY!expf              FPC:   17.0 Mops/s  PCM:  174.8 Mops/s  FASTER! YAY!logf              FPC:   46.4 Mops/s  PCM:  331.1 Mops/s  FASTER! YAY!log2f           FPC:   44.2 Mops/s  PCM:  375.9 Mops/s  FASTER! YAY!log10f            FPC:   10.6 Mops/s  PCM:  357.1 Mops/s  FASTER! YAY!atan2f            FPC:   11.1 Mops/s  PCM:   51.2 Mops/s  FASTER! YAY!hypotf            FPC:   49.7 Mops/s  PCM:  170.1 Mops/s  FASTER! YAY!powf              FPC:    1.0 Mops/s  PCM:   42.1 Mops/s  FASTER! YAY!sincosf         FPC:    7.4 Mops/s  PCM:   37.3 Mops/s  FASTER! YAY! PCM won: 20  |  FPC won: 0  |  Ties (<5%): 0On average, PCM is 22.55x faster than FPC (arithmetic mean over 20 functions)  @nanobit and @thaddy, I'll FUP your messages. ---------------------------------------------------------------------- MathMan · 2026-04-15 17:10 @schuler, Great news - many thanks for your effort! I hope that this excercise provided you with the learning experience you hoped to get? What is the background of test harness passing and then in the benchmark there still is a sink mismatch announced? Beside that - I went through 'compoundf' in detail. Didn't find anything that directly sprang to mind like the issue in 'powf'. However I'm still not at easy with the use of constants (mentioned as point 8 in my first analysis) - especially after I saw the fix for 'acosf'. My gut feeling is that stronger typing of constants, or replacing decimal float with exact UIntxx, will solve the issue with 'compoundf' too. ---------------------------------------------------------------------- schuler · 2026-04-15 20:42 compoundf has just been fixed! YAY! ---------------------------------------------------------------------- MathMan · 2026-04-15 20:47 Quote from: schuler on April 15, 2026, 10:42:11 pm compoundf has just been fixed! YAY!  Yes, congrats! And I admit my gutt feeling was wrong - it was an inline issue! This might have already been fixed in FPC 3.3.1 - I remember that somebody mentioned fixes to inline there. ---------------------------------------------------------------------- schuler · 2026-04-16 14:38 @nanobit, just pushed your change: https://github.com/joaopauloschuler/pas-core- math/commit/634f027cc2c6ebf33114955274d4db6a779389fd ---------------------------------------------------------------------- nanobit · 2026-04-16 14:50 Quote from: schuler on April 16, 2026, 04:38:41 pm@nanobit, just pushed your change: https://github.com/joaopauloschuler/pas-core- math/commit/634f027cc2c6ebf33114955274d4db6a779389fd No, your version (not from me) will not suffice. My version is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  MulLo, Temp1, Temp2: UInt64;begin  MulLo := uint64(uint32(a)) * uint64(uint32(b));  Temp1 := (a shr 32) * uint64(uint32(b)) + (MulLo shr 32);   Temp2 := uint64(uint32(a)) * (b shr 32) + uint64(uint32(Temp1));   Result.lo := (Temp2 shl 32) or (MulLo and $FFFFFFFF);  Result.hi := (a shr 32) * (b shr 32) + (Temp1 shr 32) + (Temp2 shr 32); end; ---------------------------------------------------------------------- LemonParty · 2026-04-16 15:09 Hi. I don't quite undertand what this thread testing. Can anybody give short description about what is going on? Thank you. ---------------------------------------------------------------------- schuler · 2026-04-16 15:20 @nanobit, https://github.com/joaopauloschuler/pas-core- math/commit/4b2f475e2ad344c64a850bcf6dc9b085f699e598 Next time, a PR will be easier. @lemonparty, this is a test about https://github.com/joaopauloschuler/beyond-python-smolagents at coding https://github.com/joaopauloschuler/pas-core-math . Most of the coding was done by BPSA: https://github.com/joaopauloschuler/pas-core-math/pull/1 . Myself, GitHub Copilot and Claude Code did bugfixing and specs. ---------------------------------------------------------------------- MathMan · 2026-04-16 22:55 @schuler, I think we still need a fallback implementation for pcr_fmaf, pcr_fma. Based on this https://hal.science/hal-04575249/document I did an implementation for pcr_fma - the pcr_fmaf can be derived by replaceing Double by Single throughout. Please find attached. Forget the simple replacement approach I mentioned above. At least the argument split function used has to be adapted for Single. I'll continue working on a solution for Single. ---------------------------------------------------------------------- schuler · 2026-04-17 13:27 @mathman, thank you. I will FUP. ---------------------------------------------------------------------- schuler · 2026-04-18 00:44 @mathman: https://github.com/joaopauloschuler/pas-core- math/commit/68ce6e7bf085aaff1ab49fadaa034714c25b8331 ---------------------------------------------------------------------- schuler · 2026-04-18 01:07 @Thaddy, QuoteI did my own interface to the C lib. I will need a dev environment with windows to be able to test... ---------------------------------------------------------------------- schuler · 2026-04-26 00:23 64 bits is under testing: https://github.com/joaopauloschuler/pas-core-math/pull/9 ---------------------------------------------------------------------- Thaddy · 2026-04-26 06:35 Pulled. ---------------------------------------------------------------------- schuler · 2026-04-26 10:18 @Thaddy, Thank you. Later today, I will have an update with plenty of fixes. ---------------------------------------------------------------------- schuler · 2026-04-26 15:50 Just pushed major performance improvements for both 32 and 64 bits: https://github.com/joaopauloschuler/pas-core-math/pull/10 ---------------------------------------------------------------------- Thaddy · 2026-04-30 05:58 Today's atan2 (64) on Windows11 (AVX2) seems ridiculously slow. That can't be correct. Probably da77097 ?? Results on a low-end Ryzen 7020 laptop: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Compiled with AVX2.=== FPC vs Pascal CORE-MATH (PCM) Benchmark64: 50000000 calls per function === sin               FPC:   10,0 Mops/s  PCM:   18,4 Mops/s  FASTER! YAY!cos               FPC:   10,1 Mops/s  PCM:   19,3 Mops/s  FASTER! YAY!tan               FPC:   24,5 Mops/s  PCM:   17,8 Mops/sasin              FPC:  103,1 Mops/s  PCM:  195,3 Mops/s  FASTER! YAY!acos              FPC:  100,0 Mops/s  PCM:  211,9 Mops/s  FASTER! YAY!atan              FPC:  284,1 Mops/s  PCM:  260,4 Mops/ssinh              FPC:  133,0 Mops/s  PCM:  174,8 Mops/s  FASTER! YAY!cosh              FPC:  108,0 Mops/s  PCM:  118,8 Mops/s  FASTER! YAY!tanh              FPC:  112,6 Mops/s  PCM:  102,9 Mops/sasinh             FPC:   48,7 Mops/s  PCM:  105,0 Mops/s  FASTER! YAY!acosh             FPC:  116,8 Mops/s  PCM:  151,1 Mops/s  FASTER! YAY!atanh             FPC:   45,1 Mops/s  PCM:  166,7 Mops/s  FASTER! YAY!exp               FPC:  147,5 Mops/s  PCM:  158,7 Mops/s  FASTER! YAY!log               FPC:   76,5 Mops/s  PCM:   76,8 Mops/s  TIElog2              FPC:   74,5 Mops/s  PCM:  133,0 Mops/s  FASTER! YAY!log10             FPC:   67,7 Mops/s  PCM:   72,3 Mops/s  FASTER! YAY!atan2             FPC:  122,5 Mops/s  PCM:    0,4 Mops/s  // this can't be righthypot             FPC:   77,5 Mops/s  PCM:  118,8 Mops/s  FASTER! YAY!pow               FPC:   45,7 Mops/s  PCM:   12,1 Mops/ssincos            FPC:   27,1 Mops/s  PCM:   14,0 Mops/s PCM won: 13  |  FPC won: 6  |  Ties (<5%): 1On average, PCM is 1,36x faster than FPC (arithmetic mean over 20 functions)GlobalSink = 5953110881124657846 (prevents dead-code elimination) Ran the executable 5 times. ---------------------------------------------------------------------- schuler · 2026-04-30 19:51 @Thaddy, Many thanks for your testing! I'll FUP. ---------------------------------------------------------------------- Thaddy · 2026-05-01 09:00 Now it crashes in atan2.... I will wait a while. ---------------------------------------------------------------------- schuler · 2026-05-01 09:46 In my machine, it is faster than C although slower than FPC: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i atan2           C:    1.4 Mops/s  Pascal:    1.7 Mops/s  sink=MATCH  FASTER! YAY! I pushed code yesterday. Do you know in what line it crashes please? Also, in what commit are you? ---------------------------------------------------------------------- Thaddy · 2026-05-01 10:29 Code: [Select]This mornings HEAD. Compiled with -glh [code=text]EAccessViolation: Access violation   $000000010001EB93  MULTINT   $000000010004FA1E  ATAN2ACCURATE,  line 210 of inc_64/atan2_port_64.inc   $0000000100059AA1  PCR_ATAN2,  line 309 of inc_64/atan2_port_64.inc   $0000000100002882  PCM_ATAN2,  line 237 of tests/Benchmarkfpc64.pas   $0000000100001DED  BENCHBIVAR,  line 125 of tests/Benchmarkfpc64.pas   $0000000100004E67  main,  line 274 of tests/Benchmarkfpc64.pas   $0000000100005F96   $0000000100014820   $0000000100001830   $00007FFC4D4CE957   $00007FFC4F04427CAs long as it is slower, I keep it out of the test. Tests without atan2:Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i benchmarkfpc64Compiled with AVX2.=== FPC vs Pascal CORE-MATH (PCM) Benchmark64: 50000000 calls per function === sin               FPC:   10,8 Mops/s  PCM:   14,1 Mops/s  FASTER! YAY!cos               FPC:   10,4 Mops/s  PCM:   14,9 Mops/s  FASTER! YAY!tan               FPC:   25,1 Mops/s  PCM:   11,9 Mops/sasin              FPC:  104,8 Mops/s  PCM:  166,7 Mops/s  FASTER! YAY!acos              FPC:  105,0 Mops/s  PCM:  173,6 Mops/s  FASTER! YAY!atan              FPC:  211,9 Mops/s  PCM:  174,2 Mops/ssinh              FPC:  116,8 Mops/s  PCM:  196,9 Mops/s  FASTER! YAY!cosh              FPC:  108,7 Mops/s  PCM:  116,6 Mops/s  FASTER! YAY!tanh              FPC:  105,5 Mops/s  PCM:  104,6 Mops/s  TIEasinh             FPC:   43,8 Mops/s  PCM:   56,2 Mops/s  FASTER! YAY!acosh             FPC:  104,6 Mops/s  PCM:  112,4 Mops/s  FASTER! YAY!atanh             FPC:   47,8 Mops/s  PCM:  108,5 Mops/s  FASTER! YAY!exp               FPC:  137,4 Mops/s  PCM:  164,5 Mops/s  FASTER! YAY!log               FPC:   67,3 Mops/s  PCM:   49,9 Mops/slog2              FPC:   63,2 Mops/s  PCM:   70,1 Mops/s  FASTER! YAY!log10             FPC:   64,4 Mops/s  PCM:   40,9 Mops/shypot             FPC:   71,3 Mops/s  PCM:   75,2 Mops/s  FASTER! YAY!pow               FPC:   43,1 Mops/s  PCM:    9,1 Mops/ssincos            FPC:   27,9 Mops/s  PCM:   12,5 Mops/s PCM won: 12  |  FPC won: 6  |  Ties (<5%): 1On average, PCM is 1,11x faster than FPC (arithmetic mean over 19 functions)GlobalSink = 5987329527028110739 (prevents dead-code elimination)Heap dump by heaptrc unit of "C:\joao\src\tests\BenchmarkFPC64.exe"736 memory blocks allocated : 41549736 memory blocks freed : 415490 unfreed memory blocks : 0 One more remark: FPC-LLVM needs testing too, since on linux it is already 5-15% faster than the default fpc. ---------------------------------------------------------------------- schuler · 2026-05-01 14:17 @Thaddy, Thank you so much. I'll FUP. ---------------------------------------------------------------------- schuler · 2026-05-02 10:26 @Thaddy, The crash was Windows related. There is a fix ready to be tested. ---------------------------------------------------------------------- Thaddy · 2026-05-02 13:20 Will do.Done. Compilation fixed. Atan2 is now 5 times faster than the original test, but still really slow compared to FPC:Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Compiled with AVX2.=== FPC vs Pascal CORE-MATH (PCM) Benchmark64: 50000000 calls per function === sin               FPC:   10,9 Mops/s  PCM:   14,1 Mops/s  FASTER! YAY!cos               FPC:   10,8 Mops/s  PCM:   15,0 Mops/s  FASTER! YAY!tan               FPC:   25,1 Mops/s  PCM:   11,6 Mops/sasin              FPC:  105,9 Mops/s  PCM:  166,1 Mops/s  FASTER! YAY!acos              FPC:  105,0 Mops/s  PCM:  175,4 Mops/s  FASTER! YAY!atan              FPC:  209,2 Mops/s  PCM:  175,4 Mops/ssinh              FPC:  116,3 Mops/s  PCM:  196,9 Mops/s  FASTER! YAY!cosh              FPC:  105,5 Mops/s  PCM:  116,6 Mops/s  FASTER! YAY!tanh              FPC:  106,2 Mops/s  PCM:  104,2 Mops/s  TIEasinh             FPC:   44,1 Mops/s  PCM:   55,4 Mops/s  FASTER! YAY!acosh             FPC:  105,0 Mops/s  PCM:  111,4 Mops/s  FASTER! YAY!atanh             FPC:   48,3 Mops/s  PCM:  105,0 Mops/s  FASTER! YAY!exp               FPC:  137,4 Mops/s  PCM:  162,3 Mops/s  FASTER! YAY!log               FPC:   66,2 Mops/s  PCM:   49,8 Mops/slog2              FPC:   64,6 Mops/s  PCM:   70,0 Mops/s  FASTER! YAY!log10             FPC:   64,3 Mops/s  PCM:   40,4 Mops/satan2             FPC:  100,6 Mops/s  PCM:    1,6 Mops/shypot           FPC:   71,6 Mops/s  PCM:   76,0 Mops/s  FASTER! YAY!pow             FPC:   43,1 Mops/s  PCM:    9,0 Mops/ssincos            FPC: 27,8 Mops/s  PCM:   12,4 Mops/s PCM won: 12  |  FPC won: 7  |  Ties (<5%): 1On average, PCM is 1,04x faster than FPC (arithmetic mean over 20 functions)GlobalSink = 5987329527028110739 (prevents dead-code elimination) Atan2 and Pow cause a considerable gain drop, so the average speed gain goes down quite a bit more than warranted. ---------------------------------------------------------------------- schuler · 2026-05-02 15:33 My recommendation will be: given that the pascal atan2 core-math version is already faster than its C version, if you need speed, do not use atan2 from core-math. atan2 from core-math is slow. ---------------------------------------------------------------------- Thaddy · 2026-05-02 15:54 I know. Reason for testing is, of course, why? ---------------------------------------------------------------------- schuler · 2026-05-04 14:49 @Thaddy, You are correct. Thanks to the testing, we now know a lot more than few days ago. ---------------------------------------------------------------------- bytebites · 2026-05-04 16:16 Could there be more precise diffence than faster yay, which is faster and how much? ---------------------------------------------------------------------- Thaddy · 2026-05-04 16:55 You did not read the docs, nor the test results? A draw is +/- 5% so slower or faster depends on that. The results from the tests are displayed. you can divide and multiply by 100. ---------------------------------------------------------------------- schuler · 2026-05-04 20:25 Food for thought: Only seven binary64 functions are integrated into the GNU libc up from release 2.43. From: https://core-math.gitlabpages.inria.fr/ Regarding: Quoteseven binary64 functions are integrated into the GNU libc up from release 2.43 (acosh, asinh, atanh, erf, erfc, lgamma, tgamma), and the following binary32 functions are integrated into the GNU libc up from release 2.42: acosf, acoshf, asinf, asinhf, atanf, atanhf, cbrtf, coshf, erff, erfcf, expm1f, lgammaf, log10f, log1pf, sinhf, tanf, tanhf, tgammaf, acospif, asinpif, atanpif, cospif, exp10m1f, exp2m1f, log10p1f, log2p1f, sinpif, tanpif, atan2f, atan2pif. Thought: We can just use the functions that are in our interest and leave the other functions behind. ---------------------------------------------------------------------- Thaddy · 2026-05-05 14:16 I totally agree. (with the presumption that the llvm backend needs to be tested too: many of the "winners" are in llvm, not in the project you are working on and I am testing. But llvm does not work on Windows yet. To be sure: FPC-llvm does not use LLVM compilers, but compiles directly to llvm. That is a "small" difference: the llvm linker will resolve though. It might be even the case we are chasing shadows, apart from the compiler defaults, that is. Maybe contact Jonas, who wrote the llvm backend.?