Testing only MOVSX and MOV with 1, 4, and 8-byte memory operands and running a 64-bit app compiled with Version 1.02.0 (03-23-2015) under Windows 8.1 on my 2-year old laptop, which is the most recent system I have, I cannot get meaningful cycle counts for any small number of instructions. The results for a larger number of instructions are not representative of the way a boolean would typically be used, but it's the best I can do ATM. After the initial pass, for a larger number of instructions there is no significant difference between the operand sizes. Below is my test code, and counter64.bas is available here.marcov wrote:I don't know that any more for current CPUs. The old rule (till core2) was that Intel favoured simple, aligned code, and AMD tightly packed everything. Is a movzbl really slower than a plain mov nowadays?MichaelW wrote: Considering only code efficiency, using a byte as a logic element in 32/64-bit code makes little sense.
Code: Select all
#include "windows.bi"
#include "counter64.bas"
dim shared as byte i1
dim shared as long i4
dim shared as integer i8
'' Restrict process to a single core.
SetProcessAffinityMask( GetCurrentProcess(), 1)
sleep 5000
for i as integer = 1 to 3
counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)
asm
".intel_syntax noprefix"
".rept 10"
"movsx rax, BYTE PTR I1$"
"movsx rcx, BYTE PTR I1$"
"movsx rdx, BYTE PTR I1$"
".endr"
".att_syntax prefix"
end asm
counter_end
print counter_cycles;" cycles"
counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)
asm
".intel_syntax noprefix"
".rept 10"
"movsx rax, DWORD PTR I4$"
"movsx rcx, DWORD PTR I4$"
"movsx rdx, DWORD PTR I4$"
".endr"
".att_syntax prefix"
end asm
counter_end
print counter_cycles;" cycles"
counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)
asm
".intel_syntax noprefix"
".rept 10"
"mov rax, QWORD PTR I8$"
"mov rcx, QWORD PTR I8$"
"mov rdx, QWORD PTR I8$"
".endr"
".att_syntax prefix"
end asm
counter_end
print counter_cycles;" cycles"
print
next
sleep
Code: Select all
71 cycles
24 cycles
23 cycles
22 cycles
22 cycles
22 cycles
22 cycles
22 cycles
22 cycles