#1 2018-04-27 12:56:39

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,547
Website

[issue] NowUTC on FPC Win64 truncate time to ~5 minutes resolution

program project1;
uses
  {$I SynDprUses.inc}
  SynCommons,
  SysUtils;
begin
  WriteLn(DateTimeMSToString(NowUTC()));
  sleep(1000);
  WriteLn(DateTimeMSToString(NowUTC()));
  readln;
end.
 

Both writeLn will output the same time truncated to nearest 5-minutes interval.
Seems problem is on line

result := (nano100-DateFileTimeDelta)/(10000000.0*SecsPerDay); 

but I don't understand asm generated by FPC..  Can anybody help, please?

Offline

#2 2018-04-27 13:59:15

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,547
Website

Re: [issue] NowUTC on FPC Win64 truncate time to ~5 minutes resolution

Ok, if I split a statement

result := (nano100-DateFileTimeDelta)/(10000000.0*SecsPerDay);

into two part

function NowUTC: TDateTime;
{$ifdef MSWINDOWS}
var ft: TFileTime;
    {$ifdef CPU64}nano100: Int64; d: double;{$endif}
begin
  GetSystemTimeAsFileTime(ft); // very fast, with 100 ns unit
  {$ifdef CPU64}
  FileTimeToInt64(ft,nano100);
  // prev. result := (nano100-DateFileTimeDelta)/(10000000.0*SecsPerDay); 
  d := (nano100-DateFileTimeDelta) / 10000000;
  result := d/SecsPerDay;
  {$else} // use PInt64 to avoid URW699 with Delphi 6 / Kylix
  dec(PInt64(@ft)^,DateFileTimeDelta);
  result := PInt64(@ft)^/(10000000.0*SecsPerDay);
  {$endif}
end;      

all work as expected. But IMHO this is not a good solution. Still need a advice...

Offline

#3 2018-04-27 15:55:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,258
Website

Re: [issue] NowUTC on FPC Win64 truncate time to ~5 minutes resolution

Sounds like a weird precision issue: FPC generates a conversion into single, which precision is not enough for the later division.
Whereas Delphi uses double precision for the computation.

Perhaps this commit sounds stable and fast enough: https://synopse.info/fossil/info/bb2e164423
(tested with FPC and Delphi)

Offline

#4 2018-04-28 08:03:11

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,547
Website

Re: [issue] NowUTC on FPC Win64 truncate time to ~5 minutes resolution

Since it's a critical function I add the test case for this - [c4ca0170af]. It's failed before fix and passed after.

Offline

#5 2018-10-09 10:12:24

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,547
Website

Re: [issue] NowUTC on FPC Win64 truncate time to ~5 minutes resolution

This PITA raise again. Current implementation shift time to ~ -70sec on FPC x64.
Having
  d: double
inside procedure fix the problem.

Please, see pull request #140 with corresponding regression test

Offline

Board footer

Powered by FluxBB