lua-users home
lua-l archive

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


On Mon, Nov 16, 2020 at 12:15 PM Ranier Vilela <> wrote:
> Em seg., 16 de nov. de 2020 às 07:04, Andre Leiradella <> escreveu:
>> I suggest you thoroughly test your changes and benchmark them before
>> suggesting changes to the Lua source code, some won't give you any
>> performance gains (and are likely even slower).
> I do not agree.
> If you disagree, you could run benchmarks and prove me wrong.

As an observer, I would normally expect the burden of the proof to the
one suggesting changes.

Anyway, what I was going to send. Are you aware that many of these
micro optimizations are cargo cult from a bygone age of simpler
I mean, I just use stock debian, which does not have the more cutting
edge optmizations, and even then if I compile:
#include <string.h>

int main(int ac, char **av) {
  /* I'm not going to run it but need to avoid getting all optimized
to a constant. */
  int a = strcmp(av[1],"method");
  int b = strncmp(av[2],"method", sizeof("method"));
  return a+b;

using a plain gcc -S -O3 i get:

        .file   "kk.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
        .string "method"
        .section        .text.startup,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
        movq    %rsi, %r8
        leaq    .LC0(%rip), %rdx
        movq    8(%rsi), %rsi
        movl    $7, %ecx
        movq    %rdx, %rdi
        repz cmpsb
        movq    16(%r8), %rsi
        movq    %rdx, %rdi
        movl    $7, %ecx
        seta    %al
        sbbb    $0, %al
        repz cmpsb
        movsbl  %al, %eax
        seta    %dl
        sbbb    $0, %dl
        movsbl  %dl, %edx
        addl    %edx, %eax
        .size   main, .-main
        .ident  "GCC: (Debian 8.3.0-6) 8.3.0"
        .section        .note.GNU-stack,"",@progbits

Which seems to indicate that when comparing to constant strings every
function behaves similarly.

Francisco Olarte.