Slow if...then...else x86_64 lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2014-09-11 10:29 Hi! I have a couple of questions regarding the following functions: Code: [Select]function q_const(const x,c:INTEGER):INTEGER; begin if c=x then  Result:=1 else  result:=0; end; function q_var(var x,c:INTEGER):INTEGER; begin if c=x then  Result:=1 else  result:=0; end; The first thing I'd like to know is: Both "var" and "const" imply by reference. Should the produced assembly code differ between the two functions? The second thing I'd like to know is: Code: [Select] function q_var_jne(var x,c:integer):integer;assembler;register; asm movl (%rsi),%eax cmpl (%rdi),%eax jne .Lj6 .Ll2: movl $1,%eax //RUNS SLOWER jmp .Lj9 .Lj6: movl $0,%eax .Lj9: end; function q_var_je(var x,c:integer):integer;assembler;register; asm movl (%rsi),%eax cmpl (%rdi),%eax je .Lj6 .Ll2: movl $0,%eax //RUNS SLOWER jmp .Lj9 .Lj6: movl $1,%eax .Lj9: end; function q_const_jne(const x,c:integer):integer;assembler;register; asm cmpl %edi,%esi jne .Lj6 .Ll2: movl $1,%eax //RUNS SLOWER jmp .Lj9 .Lj6: movl $0,%eax .Lj9: end; function q_const_je(const x,c:integer):integer;assembler;register; asm  cmpl %edi,%esi  je .Lj6 .Ll2:  movl $0,%eax //RUNS SLOWER  jmp .Lj9 .Lj6:  movl $1,%eax .Lj9: end; Is this the correct behavior when using je/jne? It appears like the code starting the label je/jne points to starts to be executed faster. ---------------------------------------------------------------------- marcov · 2014-09-11 10:48 Afaik what CONST does is architecture dependent. On x86_64 it is not by REF, afaik on x86 it is. Guaranteed by ref is CONSTREF See also http://bugs.freepascal.org/view.php?id=26089 ---------------------------------------------------------------------- lagprogramming · 2014-09-11 11:07 I am the reporter of that. I've opened this discussion here because that report will become harder to be read if I add too much useless informations. Thank you for the "CONSTREF" tip.