uses
System.SysUtils,
Windows;
const
Count = 1000000;
DATA_LEN = 1024;
var
Data: array[0..DATA_LEN - 1] of Integer;
CData: array[0..DATA_LEN - 1] of Byte;
procedure TestMov;
asm
mov esi, 255
mov ecx, Count
@1: mov edi, 0
@2: mov edx, dword[Data + edi * 4]
mov eax, edx
cmp eax, 0
jle @Z
cmp eax, 255
jbe @S
mov Byte[CData + edi], 255
jmp @N
@Z: xor eax, eax
@S: mov Byte[CData + edi], al
@N: inc edi
cmp edi, DATA_LEN
jle @2
dec ecx
jne @1
end;
procedure TestCMovShort;
asm
mov esi, 255 // High Limit
mov ecx, Count
@1: mov edi, 0
@2: mov edx, dword[Data + edi * 4]
XOR eax, eax // eax is destination value filled with the lowest value
cmp edx, esi // comapare v (edx) with high value
cmovg eax, esi // if bigger then take the highest esi
cmovbe eax, edx // if below or equal we fill value v (edx)
mov Byte[CData + edi], al
inc edi
cmp edi, DATA_LEN
jl @2
dec ecx
jne @1
end;
procedure Test;
var
T: Cardinal;
i: Integer;
begin
Randomize;
for i := Low(Data) to High(Data) do
Data[i] := Random(256 * 3) - 256;
T := GetTickCount;
TestMov;
T := GetTickCount - T;
Writeln('TestMov ' + IntToStr(T));
T := GetTickCount;
TestCMovShort;
T := GetTickCount - T;
Writeln('TestCMovShort ' + IntToStr(T));
end;
begin
Test;
Readln;
end.