diff options
author | Daniel Dragan <bulk88@hotmail.com> | 2012-12-16 17:26:49 -0500 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-12-23 16:36:38 -0800 |
commit | 3d04513d447d337fe15b345b1c6a4cf19dfbe89c (patch) | |
tree | 4da3c8384d56bcc9871893fc8ead2fa6104d3983 | |
parent | 5b48d9bbd702cd2c0a0863c898b3d4b120daf256 (diff) | |
download | perl-3d04513d447d337fe15b345b1c6a4cf19dfbe89c.tar.gz |
uninline panic branch from POPSTACK
This commit saves machine instructions by preventing inlining, and keeps
the error handling code for an extremely rare panic out of hot code. This
should make the interp smaller and faster.
Perl_error_log is a macro that has a very large expansion on threaded
perls, 4 branches and possibly a call to Perl_PerlIO_stderr. POPSTACK
18 times, by asm, on my non DEBUGGING threaded Win32 32 bit Perl 5.17
-O1 compiled with VC 2003. POPSTACK is also used in some core XS modules,
for example List::Util and PerlIO::encoding. The .text section of
perl517.dll dropped from 0xc05ff bytes of x86 instructions to 0xc00ff
after applying this for me.
Perl_croak_popstack was made contextless to save a push/move instruction
at each caller (less instructions in the instruction cache) and for more
opportunity for the compiler to optimize. Since Perl_croak_popstack is a
noreturn, some compilers may optimize it to just a conditional jump
instruction. VC 2003 32 bit did this inside perl517.dll and from XS
modules using POPSTACK. Perl_croak_popstack measures at 0x48 bytes of
instructions under -O1 for me, so previously, those 0x48 minus the
dTHX overhead would have been sitting in the caller because of macro
expansion.
-rw-r--r-- | cop.h | 3 | ||||
-rw-r--r-- | embed.fnc | 1 | ||||
-rw-r--r-- | embed.h | 1 | ||||
-rw-r--r-- | proto.h | 3 | ||||
-rw-r--r-- | util.c | 9 |
5 files changed, 15 insertions, 2 deletions
@@ -1134,8 +1134,7 @@ typedef struct stackinfo PERL_SI; Perl_deb(aTHX_ "pop STACKINFO %d at %s:%d\n", \ i, __FILE__, __LINE__);}) \ if (!prev) { \ - PerlIO_printf(Perl_error_log, "panic: POPSTACK\n"); \ - my_exit(1); \ + Perl_croak_popstack(); \ } \ SWITCHSTACK(PL_curstack,prev->si_stack); \ /* don't free prev here, free them all at the END{} */ \ @@ -262,6 +262,7 @@ Anprd |void |croak_no_modify Anprd |void |croak_xs_usage |NN const CV *const cv \ |NN const char *const params npr |void |croak_no_mem +nprX |void |croak_popstack #if defined(WIN32) norx |void |win32_croak_not_implemented|NN const char * fname #endif @@ -1059,6 +1059,7 @@ #define coresub_op(a,b,c) Perl_coresub_op(aTHX_ a,b,c) #define create_eval_scope(a) Perl_create_eval_scope(aTHX_ a) #define croak_no_mem Perl_croak_no_mem +#define croak_popstack Perl_croak_popstack #define cv_ckproto_len_flags(a,b,c,d,e) Perl_cv_ckproto_len_flags(aTHX_ a,b,c,d,e) #define cv_clone_into(a,b) Perl_cv_clone_into(aTHX_ a,b) #define cv_forget_slab(a) Perl_cv_forget_slab(aTHX_ a) @@ -676,6 +676,9 @@ PERL_CALLCONV_NO_RET void Perl_croak_no_mem(void) PERL_CALLCONV_NO_RET void Perl_croak_no_modify(void) __attribute__noreturn__; +PERL_CALLCONV_NO_RET void Perl_croak_popstack(void) + __attribute__noreturn__; + PERL_CALLCONV_NO_RET void Perl_croak_sv(pTHX_ SV *baseex) __attribute__noreturn__ __attribute__nonnull__(pTHX_1); @@ -1634,6 +1634,15 @@ Perl_croak_no_mem() my_exit(1); } +/* does not return, used only in POPSTACK */ +void +Perl_croak_popstack(void) +{ + dTHX; + PerlIO_printf(Perl_error_log, "panic: POPSTACK\n"); + my_exit(1); +} + /* =for apidoc Am|void|warn_sv|SV *baseex |