develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #116296] [PATCH] remove PL_patchlevel from and optimize S_minus_v

Thread Previous | Thread Next
From:
bulk88 via RT
Date:
July 6, 2013 16:10
Subject:
[perl #116296] [PATCH] remove PL_patchlevel from and optimize S_minus_v
Message ID:
rt-3.6.HEAD-2552-1373127011-1618.116296-15-0@perl.org
On Sat Jul 06 07:45:05 2013, davem wrote:
> On x86_64 platforms with the "first 6 args are in registers" calling
> convention, using newSVpvn() will likely involve no more code, since
> my_perl will already be in the relevant register; while on x86, its
> likely
> just a push of a register value.
>

On Win64 that is wrong. my_perl has to be copied every time to the 1st
callee register by the caller from the caller's non-vol register that it
saved or caller's c stack auto. There will always be an assignment to
first register (callee's my_perl) on x64 on cdecl for each perl func
call. The calling convention does not say anywhere that a callee must
keep incoming params in registers nonvolatile. What if the callee
doesn't need to every use my_perl again until it returns and calls
strlen which doesn't take a my_perl? The caller just lost their my_perl
pointer.

Keeping func params const on assembly level, to avoid copying in the
caller for each call, would require a machine code JITer and/or random
calling conventions. Random calling conventions are implemented in some
C compilers for Windows, but only for Win32, not Win64.

http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-September/025927.html 

http://nondot.org/sabre/LLVMNotes/GlobalRegisterVariables.txt

Here is the boot func from re.dll 
_______________________________________________________________
0000000010001B20  sub         rsp,48h 
0000000010001B24  mov         rax,qword ptr [rcx+70h] 
0000000010001B28  mov         rdx,qword ptr [rcx+18h] 
0000000010001B2C  mov         qword ptr [rsp+60h],rbx 
0000000010001B31  mov         rbx,qword ptr [rcx] 
0000000010001B34  mov         qword ptr [rsp+68h],rbp 
0000000010001B39  mov         qword ptr [rsp+40h],rsi <<<<<< save non vol
0000000010001B3E  mov         qword ptr [rsp+38h],rdi 
0000000010001B43  movsxd      rdi,dword ptr [rax] 
0000000010001B46  add         rax,0FFFFFFFFFFFFFFFCh 
0000000010001B4A  lea         r9,[rdx+rdi*8] 
0000000010001B4E  mov         qword ptr [rcx+70h],rax 
0000000010001B52  inc         edi  
0000000010001B54  sub         rbx,r9 
0000000010001B57  movsxd      rbp,edi 
0000000010001B5A  lea         r8,[string "v5.14.0" (1003D378h)] 
0000000010001B61  mov         rdx,qword ptr [rdx+rbp*8] 
0000000010001B65  mov         r9d,7 
0000000010001B6B  mov         rsi,rcx <<<<<<<<<<<<<<<<<<<<<<<<<<
incoming param copied to non-vol reg
0000000010001B6E  sar         rbx,3 
0000000010001B72  call        Perl_xs_apiversion_bootcheck (1000135Ah) 
0000000010001B77  lea         r9,[string "0.18" (1003D36Ch)] 
0000000010001B7E  mov         r8d,edi 
0000000010001B81  mov         edx,ebx 
0000000010001B83  mov         rcx,rsi <<<<<<<<<<<<<<<<<<<<<<<<<<
0000000010001B86  mov         qword ptr [rsp+20h],4 
0000000010001B8F  call        Perl_xs_version_bootcheck (10001348h) 
0000000010001B94  lea         r9,[string "re.c" (1003D380h)] 
0000000010001B9B  lea         r8,[XS_re_install (10001A50h)] 
0000000010001BA2  lea         rdx,[string "re::install" (1003D360h)] 
0000000010001BA9  mov         rcx,rsi <<<<<<<<<<<<<<<<<<<<<<<<<<
0000000010001BAC  call        Perl_newXS (1000134Eh) 
0000000010001BB1  lea         rax,[string "$" (1003A7DCh)] 
0000000010001BB8  lea         r9,[string "re.c" (1003D380h)] 
0000000010001BBF  lea         r8,[XS_re_regmust (10001860h)] 
0000000010001BC6  lea         rdx,[string "re::regmust" (1003D350h)] 
0000000010001BCD  mov         rcx,rsi <<<<<<<<<<<<<<<<<<<<<<<<<<
0000000010001BD0  mov         dword ptr [rsp+28h],0 
0000000010001BD8  mov         qword ptr [rsp+20h],rax 
0000000010001BDD  call        Perl_newXS_flags (10001366h) 
0000000010001BE2  mov         r8,qword ptr [rsi+5A8h] 
0000000010001BE9  mov         rdi,qword ptr [rsp+38h] 
0000000010001BEE  mov         rbx,qword ptr [rsp+60h] 
0000000010001BF3  test        r8,r8 
0000000010001BF6  je          boot_re+0E3h (10001C03h) 
0000000010001BF8  mov         edx,dword ptr [rsi+38h] 
0000000010001BFB  mov         rcx,rsi <<<<<<<<<<<<<<<<<<<<<<<<<<
0000000010001BFE  call        Perl_call_list (10001354h) 
0000000010001C03  mov         rax,qword ptr [rsi+18h] 
0000000010001C07  lea         rcx,[rsi+0BF8h] 
0000000010001C0E  mov         qword ptr [rax+rbp*8],rcx 
0000000010001C12  mov         rax,qword ptr [rsi+18h] 
0000000010001C16  lea         rcx,[rax+rbp*8] 
0000000010001C1A  mov         rbp,qword ptr [rsp+68h] 
0000000010001C1F  mov         qword ptr [rsi],rcx 
0000000010001C22  mov         rsi,qword ptr [rsp+40h] <<<<<<<<<restore
non vol
0000000010001C27  add         rsp,48h 
0000000010001C2B  ret              
____________________________________________________________


> I really don't like this part. Its just an excessive level of
> micro-optimisation for code that's only called once at most, and will
> have
> a negligible effect on the overall binary size.
................
> The downside is that the src code becomes more bloated and confusing.

And this is why people give up, switch languages, then tell all their
friends Perl [5 or Perl world] is dead. If the git repo is locked, code
will never become more confusing. The assumption that progress is for
communists and hippies is the death of Perl 5.
 
-- 
bulk88 ~ bulk88 at hotmail.com

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=116296

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About