lua-users home
lua-l archive

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

Em dom., 6 de dez. de 2020 às 12:16, Kyle Evans <> escreveu:
On Sun, Dec 6, 2020 at 8:17 AM Ranier Vilela <> wrote:
> Em dom., 6 de dez. de 2020 às 11:04, Jasper Klein <> escreveu:
>> Op Sun, 06 Dec 2020 13:28:46 +0100 schreef Ranier Vilela <>:
>> > Em sáb., 5 de dez. de 2020 às 23:18, Andrew Gierth <
>> >> escreveu:
>> >> Using unsigned rather than signed integers is sometimes detrimental to
>> >> performance and essentially never beneficial; the reason is that the
>> >> compiler is allowed to do some optimizations with signed values that are
>> >> not allowed on unsigned ones.
>> >>
>> >
>> > This contradicts everything I've studied about optimizations.
>> > For loops, the quickest option, are variables with the natural size of the
>> > machine.
>> > What in 64 bits means 8 bytes, int in 64 bits is 32 bits.
>> > Which leads the compiler to make implicit conversions to use the variables
>> > that index the arrays in Lua,
>> > that today, all are 32 bits.
>> > In addition, it is not possible to create the largest possible table that
>> > fits in "unsigned int".
>> >
>> > Ranier Vilela
>> >
>> Maybe this part of a talk by Chandler Carruth is interesting for you.
> No. I do not care.
> I have always used unsigned types in my loops, without any error.
> By the way I always use sizet_t, which represents the machine's natural word,
> which in 64 bits makes my arrays able to have the size of [0, +18,446,744,073,709,551,615] range.


This is yet another demonstration where you're trying to out-run
compiler optimizations and likely to end up penalized in the process.
I would encourage you to play around with godbolt[0] and observe the
measurable effect these have or don't have. I've killed off the
inlining of various functions here and extern'd the bounds to make it
a little easier to see, but also try replacing upper bounds with a low
literal and observe the differences between the four variants (note
this example is specifically x86-64).
I didn't really understand what you meant when you mixed the types.
But you are telling me that code that uses int (32 bits) to go through a loop,
has the same performance as an unsigned int (32 bits). OK.
You want to tell me that an int (32-bit) type can do the same job as a size_t (64-bit) type in a 64-bit environment?
I will throw away my static analysis tools, which suggest using memsise types (size_t) to index arrays, because you are all right .... :)

But I didn't question any performance of the code in Lua.
I questioned the limits.
I asked why luaH_resize uses "unsigned int" when all other API functions use "int"?

Ranier Vilela