----- Reply to message ----- Subject: Re: [fpc-devel] x86_64 Optimizer Overhaul Date: 2018. gada 12. decembris 17:02:02 From: J. Gareth Moreton <gar...@moreton-family.com> To: FPC developers' list <fpc-devel@lists.freepascal.org> > By the way, what generates that set of > operations? I'm curious because I want to > see what's going on in the compiler. You > see, "incq" and that "mov, add, mov" set > aren't equivalent; anything over > $100000000 gets truncated with the set, > but not with "incq", although it's not a > concern if only the lower 32 bits are > used.
Have to agree, it's not equivalent. I added example program for you to examine this situation. It might and might not be an error. note: i use compiler parameter -O4 > If both combinations run at about the same > speed, then "incq" is better just on > account of code size. I spent some time to examine "incq mem" and "mov add mov" On my particular cpu if "incq" is independent instruction, then actual performance is 1 clock cycle. Combination of "mov add mov" ended up like 1 - 1.2 clock cycles. Chain of "mov add mov" was always few clocks more than the same length chain of "incq". But in case if "incq" fall into sever dependency chain then "incq" executes 25% worse than "mov add mov". "incq" 4,5 clock cycles "mov add mov" 3,8 clock cycles I vote for shorter code and prefer "incq" margers
program overhaul_incq; var globalQ : longint; function dummycall(a,b: longint):longint; begin dummycall:=a+b; end; procedure fuu; var k : longint; { rbx for loop counter } a,b,c,m,z,q : longint; {no real use, just to occupie r12-r15} sk : longint; {no free real registers - so to be temp on stack} begin sk:=0; q:=0; a:=0; for k:=0 to 100 do { k takes rbx } begin { dummy math to keep busy registers r12 - r15 } c:=q+a; m:=k+1; { call discards r8 - r11, rax, rdx, rcx, rdi, rsi - no use of them} z:=dummycall(k,c); q:=c+z; { as fpc don't use rbp for variable, } { we don't have left any usable register } { incq [mem] } inc(sk); {writeln(k,' ',q);} end; globalQ:=q; end; begin fuu; writeln(globalQ); end.
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel