REM Using the Time Stamp Instruction
DIM code 2200
FOR pass=0 TO 2 STEP 2
P%=code
[
OPT pass
.subtime
dd 0
.time
dd 0
.var
dd 0
]
P%+=2048
[
OPT pass
.start
;L1 cache warming
cpuid
rdtsc
mov [subtime],eax
cpuid
rdtsc
sub eax,[subtime]
mov [subtime],eax
cpuid
rdtsc
mov [subtime],eax
cpuid
rdtsc
sub eax,[subtime]
mov [subtime],eax
cpuid
rdtsc
mov [subtime],eax
cpuid
rdtsc
sub eax,[subtime]
mov [subtime],eax
finit
;now test the instruction
cpuid
rdtsc
mov [time],eax
;REM the intruction being tested
fld dword [time]
cpuid
rdtsc
sub eax,[time]
mov [time],eax
sub eax,[subtime]
ret
]
NEXT
PRINT"Code Length = ";P%-code
FOR I%=1 TO 20
T%=USR(start)
PRINT T%
NEXT
END
REM Using the Time Stamp Instruction for opcode timing
DIM code 4000, L%-1
FOR pass=8 TO 10 STEP 2
P%=(code+3) AND -4
S%=P%
[
OPT pass
.subtime
dd 0
dd 0
.time
dd 0
dd 0
.var
dd 0
dd 0
]
P%+=2048
[
OPT pass
.start
;L1 cache warming
cpuid
rdtsc
mov [subtime],eax
cpuid
rdtsc
sub eax,[subtime]
mov [subtime],eax
cpuid
rdtsc
mov [subtime],eax
cpuid
rdtsc
sub eax,[subtime]
mov [subtime],eax
cpuid
rdtsc
mov [subtime],eax
cpuid
rdtsc
sub eax,[subtime]
mov [subtime],eax
.beforerem
;REM kljashdfaldskf
.afterrem
cpuid
rdtsc
mov [time],eax
;fld dword [time]
;fstp dword [var]
fld1
fstp st0
cpuid
rdtsc
sub eax,[time]
mov [time],eax
sub eax,[subtime]
ret
]
NEXT
PRINT"Code Length = ";P%-code
PRINT"Aligning to dword boundry adds: ";S%-code;" bytes."
PRINT"REM statement adds:"afterrem-beforerem
FOR I%=1 TO 20
T%=USR(start)
PRINT T%
NEXT