lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Maybe also take a look at gcc.
x86-x64 gcc 10.2 (-O2):

f(int):
        mov     eax, 10
        ret

f(unsigned int):
        cmp     edi, -10
        sbb     eax, eax
        and     eax, 10
        ret

I would say in this case f(int) is faster.

Regards,
Xmilia

For loops:
https://godbolt.org/
x86-64 clang 11.0 (-O2):

int f(int i) { int j, k = 0; for (j = i; j < i + 10; ++j) ++k; return k; }
f(int):                                  # @f(int)
        lea     eax, [rdi + 9]
        cmp     eax, edi
        cmovl   eax, edi
        sub     eax, edi
        add     eax, 1
        ret

unsigned int f(unsigned int i) { unsigned int j, k = 0; for (j = i; j < i + 10; ++j) ++k; return k; }
f(unsigned int):                                  # @f(unsigned int)
        xor     ecx, ecx
        cmp     edi, -10
        mov     eax, 10
        cmovae  eax, ecx
        ret