Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] refactor pp_list #13856

Closed
p5pRT opened this issue May 18, 2014 · 7 comments
Closed

[PATCH] refactor pp_list #13856

p5pRT opened this issue May 18, 2014 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented May 18, 2014

Migrated from rt.perl.org#121906 (status was 'resolved')

Searchable as RT121906$

@p5pRT
Copy link
Author

p5pRT commented May 18, 2014

From @bulk88

Created by @bulk88

See attached patch.

Main point of the patch is to move read and writes that happened
global/all branches, into the branch were they are required, and
therefore less asm ops execute if "GIMME == G_ARRAY". This was the 8th
hottest opcode in a personal script I ran.

I tried to do some profiling with a script that calls pp_list ~70000
times per process then dumps the average at the end but any difference
below Win32's QueryPerformanceCounter's precision. If anyone is
interested I can attach the patches used to generate the numbers below.

how to read, float is time in us, 2nd number is CPU ticks for calling
pp_list, 3rd number is overhead of QPC, 2 calls to QPC 1 after another
then subtracted, 2nd number HAS NOT been subtracted from 3rd

before
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 2.666667 8 5
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 3.333333 10 4
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.333333 10 4
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 2.666667 8 5
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.666667 11 4
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.000000 9 4

after
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 3.666667 11 5
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 4.666667 14 7
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 5
avg is 3.333333 10 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 2.666667 8 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 2.666667 8 5
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 4
avg is 3.000000 9 5
avg is 3.000000 9 4
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 3.000000 9 5
avg is 2.666667 8 5
avg is 2.666667 8 4
avg is 2.666667 8 5
avg is 3.000000 9 4
avg is 2.666667 8 5
avg is 3.000000 9 4

Perl Info

Flags:
                category=core
                severity=low

Site configuration information for perl 5.19.7:

Configured by Owner at Thu Nov 28 02:32:44 2013.

Summary of my perl5 (revision 5 version 19 subversion 7) configuration:
              Derived from: 8f47723e28b75530b743941cdd8b07f849ec48e2
              Ancestor: 1061065f7a09399eefb50e9a035502621722bcc0
              Platform:
                osname=MSWin32, osvers=5.1, 
archname=MSWin32-x86-multi-thread
                uname=''
                config_args='undef'
                hint=recommended, useposix=true, d_sigaction=undef
                useithreads=define, usemultiplicity=define
                useperlio=define, d_sfio=undef, uselargefiles=define,
usesocks=undef
                use64bitint=undef, use64bitall=undef, uselongdouble=undef
                usemymalloc=n, bincompat5005=undef
              Compiler:
                cc='cl', ccflags ='-nologo -GF -W3 -O1 -MD -Zi -DNDEBUG
-G7 -GL
-DWIN32 -D_CONSOLE -DNO_STRICT  -DPERL_TEXTMODE_SCRIPTS
-DPERL_HASH_FUNC_ONE_AT_A_TIME -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T',
                optimize='-O1 -MD -Zi -DNDEBUG -G7 -GL',
                cppflags='-DWIN32'
                ccversion='13.10.6030', gccversion='', gccosandvers=''
                intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234
                d_longlong=undef, longlongsize=8, d_longdbl=define,
longdblsize=8
                ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='__int64',
lseeksize=8
                alignbytes=8, prototype=define
              Linker and Libraries:
                ld='link', ldflags ='-nologo -nodefaultlib -debug
-opt:ref,icf
-ltcg  -libpath:"c:\perl519\lib\CORE"  -machine:x86'
                libpth="C:\Program Files\Microsoft Visual Studio .NET
2003\VC7\lib"
                libs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
                perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
                libc=msvcrt.lib, so=dll, useshrplib=true, 
libperl=perl519.lib
                gnulibc_version=''
              Dynamic Linking:
                dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
                cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf -ltcg  -libpath:"c:\perl519\lib\CORE"  -machine:x86'

Locally applied patches:
                uncommitted-changes
                8f47723e28b75530b743941cdd8b07f849ec48e2


@INC for perl 5.19.7:
                C:/perl519/site/lib
                C:/perl519/lib
                .


Environment for perl 5.19.7:
                HOME (unset)
                LANG (unset)
                LANGUAGE (unset)
                LD_LIBRARY_PATH (unset)
                LOGDIR (unset)
                PATH=C:\perl519\bin;C:\Program Files\Microsoft Visual Studio
.NET
2003\Common7\IDE;C:\Program Files\Microsoft Visual Studio .NET
2003\VC7\BIN;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools\bin\prerelease;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;
                PERL_BADLANG (unset)
                SHELL (unset)














@p5pRT
Copy link
Author

p5pRT commented May 18, 2014

From @bulk88

0001-refactor-pp_list.patch
From 5b1fb5914dd2ffb35ae3286bcf8e8ee236940710 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Sat, 17 May 2014 22:10:01 -0400
Subject: [PATCH] refactor pp_list

-move PL_stack_sp and PL_stack_base reads into the branch in which they
 are used, this also removes 1 var from being saved across the function
 call in GIMME, which removes saving and restoring 1 non-vol register
-write SP to PL_stack_sp (PUTBACK) only if it was changed
-POPMARK is mutable, it must execute on all branches

this reduced pp_list's machine code size of the function from 0x58 to
0x53 bytes on VC 2003 -01 32 bits
---
 pp.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/pp.c b/pp.c
index 4ec6887..662756e 100644
--- a/pp.c
+++ b/pp.c
@@ -4847,15 +4847,19 @@ PP(pp_kvhslice)
 
 PP(pp_list)
 {
-    dVAR; dSP; dMARK;
+    dVAR;
+    I32 markidx = POPMARK;
     if (GIMME != G_ARRAY) {
+	SV **mark = PL_stack_base + markidx;
+	dSP;
 	if (++MARK <= SP)
 	    *MARK = *SP;		/* unwanted list, return last item */
 	else
 	    *MARK = &PL_sv_undef;
 	SP = MARK;
+	PUTBACK;
     }
-    RETURN;
+    return NORMAL;
 }
 
 PP(pp_lslice)
-- 
1.7.9.msysgit.0

@p5pRT
Copy link
Author

p5pRT commented May 19, 2014

From @tonycoz

On Sat May 17 19​:44​:14 2014, bulk88 wrote​:

See attached patch.

Main point of the patch is to move read and writes that happened
global/all branches, into the branch were they are required, and
therefore less asm ops execute if "GIMME == G_ARRAY". This was the 8th
hottest opcode in a personal script I ran.

Added to 5.21.1 blockers.

Tony

@p5pRT
Copy link
Author

p5pRT commented May 19, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 28, 2014

From @tsee

Thanks, applied locally, tests running. Will push to blead shortly.

@p5pRT p5pRT closed this as completed May 28, 2014
@p5pRT
Copy link
Author

p5pRT commented May 28, 2014

@tsee - Status changed from 'open' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented May 28, 2014

From @tsee

On Wed May 28 01​:09​:55 2014, smueller@​cpan.org wrote​:

Thanks, applied locally, tests running. Will push to blead shortly.

Applied as 4fa715f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant