View Issue Details

IDProjectCategoryView StatusLast Update
0038248FPCCompilerpublic2020-12-23 17:22
Reporterrunewalsh Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilitysometimes
Status resolvedResolutionfixed 
Platformx86_64-win64 
Fixed in Version3.3.1 
Summary0038248: -CfAVX2 is scared of frac(single)
DescriptionIf compiled for x86-64 with -CfAVX2, code below prints 1.25 instead of 0.25.
Steps To Reproducevar
    t: single;
begin
    t := 1.25;
    writeln(frac(t):0:2);
end.
TagsNo tags attached.
Fixed in Revision47839
FPCOldBugId
FPCTarget-
Attached Files

Activities

Bart Broersma

2020-12-23 13:19

reporter   ~0127777

Slightly modofied code:
program Test;
{$mode objfpc}
var
    t,f: single;
begin
    t := 1.25;
    f := frac(t);
    writeln(f:0:2);
end.


produces this assembler output:
# [7] f := frac(t);
    vmovss	U_$P$TEST_$$_T(%rip),%xmm0
    vroundsd	$3,%xmm0,%xmm0,%xmm1
    vsubsd	%xmm1,%xmm0,%xmm1
    vcvtsd2ss	%xmm1,%xmm0,%xmm0
    vmovss	%xmm0,U_$P$TEST_$$_F(%rip)


Tested on an Intel Core I5 (2 years old, so it should support AVX2).

J. Gareth Moreton

2020-12-23 14:09

developer   ~0127778

Last edited: 2020-12-23 14:10

View 2 revisions

For some reason it is using the double-precision versions of the functions to obtain the fractional component (vroundsd and vsubsd rather htan vroundss and vsubss). Because of the different encodings, two Singles, 1.25 and 0, are being interpreted as a Double, and equates to an unbelievably small number, which is rounded to zero, and then zero is subtracted from this same misinterpreted Double, which of course doesn't change.

Initial analysis suggests that it's a problem in the node's second pass.

Bart Broersma

2020-12-23 16:56

reporter   ~0127780

The output of the modified program from note 0038248:0127777 is "0.00" b.t.w.

runewalsh

2020-12-23 17:22

reporter   ~0127781

Thank you for fixing it :3

Issue History

Date Modified Username Field Change
2020-12-23 06:33 runewalsh New Issue
2020-12-23 13:19 Bart Broersma Note Added: 0127777
2020-12-23 14:09 J. Gareth Moreton Note Added: 0127778
2020-12-23 14:10 J. Gareth Moreton Note Edited: 0127778 View Revisions
2020-12-23 16:56 Bart Broersma Note Added: 0127780
2020-12-23 17:10 Florian Assigned To => Florian
2020-12-23 17:10 Florian Status new => resolved
2020-12-23 17:10 Florian Resolution open => fixed
2020-12-23 17:10 Florian Fixed in Version => 3.3.1
2020-12-23 17:10 Florian Fixed in Revision => 47839
2020-12-23 17:10 Florian FPCTarget => -
2020-12-23 17:22 runewalsh Note Added: 0127781