View Issue Details

IDProjectCategoryView StatusLast Update
0033693FPCRTLpublic2020-01-21 10:27
ReporterJ. Gareth Moreton Assigned To 
PrioritylowSeveritytweakReproducibilityN/A
Status closedResolutionfixed 
PlatformWin64OSMicrosoft Windows 
Product Version3.1.1 
Fixed in Version3.1.1 
Summary0033693: [Patch] Optimised/Fixed "Int" function
DescriptionAs initially touched upon in 0033635, the Int as well as the Frac function was faulty when it came to handling values whose magnitude was larger than 2^63 (too large for an Int64), causing a crash. The Frac function already implements an inlined and rearranged version of this proposed Int function, and this completes the set by providing robust code that is also small and very fast to execute.
Steps To ReproduceRun the supplied "inttest.pp" file to compare timings and correctness, then apply the patch to merge the new Int function into the RTL.
Additional InformationFind attached inttest.log for a sample run of the timings. If compiled under Linux, the timings are not shown or calculated.
Tags64-bit, rtl
Fixed in Revision38993
FPCOldBugId0
FPCTarget-
Attached Files

Relationships

related to 0033635 closed Broken frac function 

Activities

J. Gareth Moreton

2018-05-05 13:57

developer  

IntFix.patch (836 bytes)   
Index: rtl/x86_64/math.inc
===================================================================
--- rtl/x86_64/math.inc	(revision 38904)
+++ rtl/x86_64/math.inc	(working copy)
@@ -356,6 +356,21 @@
 
 {$else FPC_HAS_TYPE_EXTENDED}
 
+    {$ifndef FPC_SYSTEM_HAS_INT}
+    {$define FPC_SYSTEM_HAS_INT}
+    function fpc_int_real( d: ValReal) : ValReal;compilerproc; assembler; nostackframe;
+      asm
+        movq      %xmm0,  %rax
+        shr       $48,    %rax
+        and       $0x7ff0,%ax
+        cmp       $0x4330,%ax
+        jge       .L0
+        cvttsd2si %xmm0,  %rax
+        cvtsi2sd  %rax,   %xmm0
+    .L0:
+      end;
+    {$endif FPC_SYSTEM_HAS_INT}
+
     {$ifndef FPC_SYSTEM_HAS_TRUNC}
     {$define FPC_SYSTEM_HAS_TRUNC}
     function fpc_trunc_real(d : ValReal) : int64;compilerproc; assembler; nostackframe;
IntFix.patch (836 bytes)   

J. Gareth Moreton

2018-05-05 13:57

developer  

inttest.pp (6,958 bytes)

J. Gareth Moreton

2018-05-05 13:58

developer  

inttest.log (30,760 bytes)

J. Gareth Moreton

2018-05-05 14:00

developer   ~0108147

(Fixed link in description)

Sven Barth

2018-05-14 23:09

manager   ~0108299

Thank you for your contribution!

Issue History

Date Modified Username Field Change
2018-05-05 13:57 J. Gareth Moreton New Issue
2018-05-05 13:57 J. Gareth Moreton Status new => assigned
2018-05-05 13:57 J. Gareth Moreton Assigned To => Sven Barth
2018-05-05 13:57 J. Gareth Moreton File Added: IntFix.patch
2018-05-05 13:57 J. Gareth Moreton File Added: inttest.pp
2018-05-05 13:58 J. Gareth Moreton File Added: inttest.log
2018-05-05 13:58 J. Gareth Moreton Relationship added related to 0033635
2018-05-05 14:00 J. Gareth Moreton Note Added: 0108147
2018-05-05 14:00 J. Gareth Moreton Description Updated View Revisions
2018-05-05 14:31 J. Gareth Moreton Tag Attached: 64-bit
2018-05-05 14:31 J. Gareth Moreton Tag Attached: rtl
2018-05-11 02:42 J. Gareth Moreton Priority normal => low
2018-05-11 02:42 J. Gareth Moreton Severity minor => tweak
2018-05-14 23:09 Sven Barth Fixed in Revision => 38993
2018-05-14 23:09 Sven Barth Note Added: 0108299
2018-05-14 23:09 Sven Barth Status assigned => resolved
2018-05-14 23:09 Sven Barth Fixed in Version => 3.1.1
2018-05-14 23:09 Sven Barth Resolution open => fixed
2018-05-14 23:09 Sven Barth Target Version 3.1.1 =>
2020-01-21 10:27 J. Gareth Moreton Assigned To Sven Barth =>
2020-01-21 10:27 J. Gareth Moreton Status resolved => closed
2020-01-21 10:27 J. Gareth Moreton FPCTarget => -