View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038248 | FPC | Compiler | public | 2020-12-23 06:33 | 2020-12-23 17:22 |
Reporter | runewalsh | Assigned To | Florian | ||
Priority | normal | Severity | minor | Reproducibility | sometimes |
Status | resolved | Resolution | fixed | ||
Platform | x86_64-win64 | ||||
Fixed in Version | 3.3.1 | ||||
Summary | 0038248: -CfAVX2 is scared of frac(single) | ||||
Description | If compiled for x86-64 with -CfAVX2, code below prints 1.25 instead of 0.25. | ||||
Steps To Reproduce | var t: single; begin t := 1.25; writeln(frac(t):0:2); end. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | 47839 | ||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
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). |
|
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. |
|
The output of the modified program from note 0038248:0127777 is "0.00" b.t.w. |
|
Thank you for fixing it :3 |
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 |