I was looking at the assembly of a code snippet I wrote and noticed that the indicated movsxd
op only appears if the ret
variable is 32-bit. If ret
is 64-bit, it is used directly: mov BYTE PTR [rdi+rbp+86], al
.
; 861 : _BitScanForward(&depth, subject);
movsx edx, dx
; 862 : qry_args->lo_refs[++ret] = (BYTE)depth;
inc ebp // ret is in ebp
bsf ecx, edx
movsxd rax, ebp // convert 32-bit ebp to 64-bit rax
; 865 : subject ^= (1 << depth);
; 866 : nulls_mask.lo |= (1 << depth);
movsx r9d, r9w
btc edx, ecx
bts r9d, ecx
mov BYTE PTR [rax+rbx+86], cl // 64-bit rax used by mov
Since the mov
op requires 64-bit registers in 64-bit mode, it makes sense to me that any variables used to reference memory (such as array referencers) should ideally be in 64-bit.
However, I know it's common to simply use int
in a loop that is not going to exceed 2^^31 iterations. Should we in fact be using long long
(int64
) as a best practice for 64-bit code? Any comments on this?
I haven't gone to the trouble of testing this beyond what is shown here.
Ps. This isn't a micro-optimization question. It's a question of form. To me, it makes sense to use the type used by the compiler.
Info: I'm compiling with VS 2016 with max optimizations on.