From: beware Date: Thu, 13 Mar 2014 07:04:57 +0000 (+0000) Subject: wrapped rdtsc and added x64 support X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/90c7057fc0ae5d85a6443e7633642ef43553ab28 wrapped rdtsc and added x64 support git-svn-id: file:///svnroot/lcore/trunk@132 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/lcorernd.pas b/lcorernd.pas index 648c87a..3a8ea0c 100644 --- a/lcorernd.pas +++ b/lcorernd.pas @@ -130,6 +130,8 @@ var implementation +{$include pgtypes.inc} + {$ifndef nolcorernd} uses {$ifdef mswindows}windows,activex,{$endif} @@ -144,6 +146,23 @@ uses {$ifdef unix}{$include unixstuff.inc}{$endif} +procedure rdtsc(buf: pointer); +asm + {$ifdef cpux86} + mov ecx, buf + db $0f; db $31 {rdtsc} + mov [ecx], edx + mov [ecx+4], eax + {$endif} + + {$ifdef cpux64} + mov rcx, buf + rdtsc + mov [rcx], edx + mov [rcx+4], eax + {$endif} +end; + type {hashtype must be array of bytes} hashtype=tmd5; @@ -178,7 +197,6 @@ var cursor:tpoint; hs:theapstatus; end absolute output; - rdtsc_0,rdtsc_1:integer; begin result := 0; if (bufsize < sizeof(l)) then exit; @@ -194,15 +212,8 @@ begin queryperformancecounter(tlargeinteger(l.qpcbuf)); {RDTSC} - {$ifdef cpu386} - asm - db $0F; db $31 - mov rdtsc_0,eax - mov rdtsc_1,edx - end; - l.rdtscbuf[0] := rdtsc_0; - l.rdtscbuf[1] := rdtsc_1; - {$endif} + rdtsc(@l.rdtscbuf); + {GETSYSTEMTIME} getsystemtime(tsystemtime(l.systemtimebuf)); @@ -253,7 +264,6 @@ var tv:ttimeval; pid:integer; end absolute output; - rdtsc_0,rdtsc_1:integer; begin result := 0; @@ -280,15 +290,7 @@ begin move(wtmpcached,l.devrnd,sizeof(l.devrnd)); end; {get more randomness in case there's no /dev/random} - {$ifdef cpu386}{$ASMMODE intel} - asm - db $0F; db $31 - mov rdtsc_0,eax - mov rdtsc_1,edx - end; - l.rdtscbuf[0] := rdtsc_0; - l.rdtscbuf[1] := rdtsc_1; - {$endif} + rdtsc(@l.rdtscbuf); gettimeofday(l.tv); l.pid := getpid; diff --git a/pgtypes.inc b/pgtypes.inc index 99fc6c0..4f8d2a8 100644 --- a/pgtypes.inc +++ b/pgtypes.inc @@ -8,6 +8,6 @@ {$endif} -{$ifdef i386}{$define ENDIAN_LITTLE}{$endif} -{$ifdef cpux64}{$define ENDIAN_LITTLE}{$endif} +{$ifdef i386}{$define ENDIAN_LITTLE}{$asmmode intel}{$endif} +{$ifdef cpux64}{$define ENDIAN_LITTLE}{$asmmode intel}{$endif}