lua-users home
lua-l archive

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


Em seg., 7 de dez. de 2020 às 09:15, Ranier Vilela <ranier.vf@gmail.com> escreveu:
Em seg., 7 de dez. de 2020 às 09:07, Xmilia Hermit <xmilia.hermit@gmail.com> escreveu:

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.

It seems to me that someone forgot to apply the same optimization for "unsigned int", into gcc code.
What leads to the conclusion, where are these modern compilers really?
Clang 11.0 is not a modern compiler?
We can continue this discussion forever.
But the more I "study wrong" I come to the conclusion that for me unsigned int is better than "signed int".

"few points in favor of unsigned int.
  • The overflow of unsigned int is fully defined by the c standard community but not defined for the signed int.
  • When we will shift the signed negative value then its results depend on the implementation.
  • The range of unsigned int is larger than the range of the signed int.
  • The modulus operation is almost defined for the unsigned int.
  • Generally in the embedded system port and register deal with unsigned int because the value of the register and port treated as unsigned entities.
  • Using the unsigned int we can reduce some conditional statements.
 Ranier Vilela