PPaste!

NPoT ASM

Home - All the pastes - Authored by Thooms

Raw version

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    .globl npot
    .type npot, @function
    # First parameter = value to elevate to the next power of two
    # Return value = the given value elevated to the NPoT
npot:
    xor %rax, %rax
    bsr %rdi, %rcx
    jz npot_end
    movq $1, %rax
    shl %cl, %rax
    cmp %rax, %rdi
    je npot_end
    shl $1, %rax
npot_end:
    ret