Forum > FPC development

Slow if...then...else x86_64

(1/1)

lagprogramming:
Hi! I have a couple of questions regarding the following functions:


--- Code: ---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;

--- End code ---


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: ---
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;


--- End code ---

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:
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:
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.

Navigation

[0] Message Index

Go to full version