program rdtsc ; { RDTSC instruction needs Pentium or better, returns count of CPU clock cycles ; those not tested here may be un-tested by me; only for certain processors. Consider for use in generating a RandSeed. } {$I VERSION.PAS} {$IFDEF PASCAL} {$N+,Q-} uses Crt ; {$ENDIF} {$IFDEF DELPHI} uses Windows ; {$ENDIF} function FrdtscW : word ; assembler ; asm dw $310F {Clock to edx:eax} end {FrdtscW} ; {$IFDEF PASCAL} function FrdtscL : longint ; assembler {TP/BP} ; asm dw $310F {Clock to edx:eax} db $66 ; mov dx,ax ; db $66 ; shr dx,16 end {FrdtscL} ; (* JRS: function FrdtscC : comp {TP/BP ?} ; var X : record A, B : longint end ; begin asm dw $310F {Clock to edx:eax} db $66 ; mov word ptr X.A, ax ; db $66 ; mov word ptr X.B, dx end ; FrdtscC := comp(X) end {FrdtscC} ; *) const HexRDTSC = $310F ; function FrdtscC : comp ; assembler ; (* RAHP *) asm dw HexRDTSC {Clock to edx:eax} mov bx, sp db $66 ; push dx db $66 ; push ax db $36, $DF, $6F, $F8 {fild qword ptr ss:[bx-8]} add sp, 8 end {FrdtscC} ; {$ENDIF PASCAL} {$IFDEF DELPHI} function FrdtscL : longint ; assembler ; asm dw $310F {Clock to edx:eax} end {FrtdscL} ; procedure GetCycleCount(var Lo, Hi : integer) { tested in longcalc.pas } ; asm push ebx ; mov ecx,eax ; mov ebx,edx DB 0FH ; DB 031H mov dword ptr[ecx], eax ; mov dword ptr[ebx], edx pop ebx end {Bob Lee} ; (* from Robert Lee - needs Delphi 4 or higher : function GetCycleCount : int64 ; {This is minimally invasive and accurate down to about 40 cycles.} asm DB 0FH ; DB 031H end ; *) var R : record L, H : integer end {no Int64 in D3} ; {$ENDIF DELPHI} var T : longint ; Ch : char ; BEGIN ; Writeln('RTDSC : www.merlyn.demon.co.uk >= 2002-02-19') ; repeat Write(' For approx CPU speed : ') ; T := FrdtscL ; {$IFDEF PASCAL} Delay(1000) ; {$ENDIF} {$IFDEF DELPHI} Sleep(1000) ; {$ENDIF} Writeln(FrdtscL-T, ' Hz') ; Writeln('W: ', FrdtscW:25, FrdtscW:25, FrdtscW:25 ) ; Writeln('L: ', FrdtscL:25, FrdtscL:25, FrdtscL:25 ) ; {$IFDEF PASCAL} Writeln('C: ', FrdtscC:25:0, FrdtscC:25:0, FrdtscC:25:0) ; {$ENDIF} {$IFDEF DELPHI} with R do begin GetCycleCount(L, H) ; Writeln('G: ', H, ':', L, ' => ', comp(R):1:0) ; end ; {$ENDIF} Write(' Loop/Quit? ') ; Readln(Ch) ; until UpCase(Ch)='Q' ; end.