Everything wrote:IMHO IsPowTwo1(1) should also return 0 (like in my procedure).
If you want to exclude 1 as a power of 2, you can do it like this.
Code: Select all
Procedure IsPow2(n)
; Power of 2 check
; with n=1 reporting false
!xor rax, rax
!mov rcx, [p.v_n]
!mov rdx, rcx
!sub rcx, 1
!jbe .l0; jbe / jle / jb / jl
!and rcx, rdx
!jnz .l0
!mov rax, 1
!.l0:
ProcedureReturn
EndProcedure
In it's current form
Debug IsPow2($8000000000000000)
will report true as it treats it as an unsigned value.
If you also want that to report false because PB sees it as a negative value, you have to change
jbe to
jle
If you do not want to exclude 1 as a power of two, use
jb or
jl instead of jbe / jle.