diff options
author | Steffen Mueller <smueller@cpan.org> | 2013-03-06 20:39:43 +0100 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2013-03-06 20:39:43 +0100 |
commit | 2439e03355dec26654acf614900c077433bc27e0 (patch) | |
tree | 9bd0e7345aad6371d1f45065e869d791fb604c0c | |
parent | 8da3792e39c8a8877091f33438f7191493dbefea (diff) | |
download | perl-2439e03355dec26654acf614900c077433bc27e0.tar.gz |
(UN)LIKELY branch prediction hints in a few strategic places
This adds branch prediction hints to a few strategic places such as
growing stack or strings, some exception handling, and a few hot
functions such as sv_upgrade.
This is not exhaustive by any means.
-rw-r--r-- | inline.h | 6 | ||||
-rw-r--r-- | perl.h | 6 | ||||
-rw-r--r-- | pp.h | 14 | ||||
-rw-r--r-- | sv.c | 8 |
4 files changed, 17 insertions, 17 deletions
@@ -46,7 +46,7 @@ S_ReANY(const REGEXP * const re) PERL_STATIC_INLINE SV * S_SvREFCNT_inc(SV *sv) { - if (sv) + if (LIKELY(sv != NULL)) SvREFCNT(sv)++; return sv; } @@ -59,13 +59,13 @@ S_SvREFCNT_inc_NN(SV *sv) PERL_STATIC_INLINE void S_SvREFCNT_inc_void(SV *sv) { - if (sv) + if (LIKELY(sv != NULL)) SvREFCNT(sv)++; } PERL_STATIC_INLINE void S_SvREFCNT_dec(pTHX_ SV *sv) { - if (sv) { + if (LIKELY(sv != NULL)) { U32 rc = SvREFCNT(sv); if (rc > 1) SvREFCNT(sv) = rc - 1; @@ -568,9 +568,9 @@ struct op *Perl_op asm(stringify(OP_IN_REGISTER)); #else # define TAINT (PL_tainted = TRUE) # define TAINT_NOT (PL_tainted = FALSE) -# define TAINT_IF(c) if (c) { PL_tainted = TRUE; } -# define TAINT_ENV() if (PL_tainting) { taint_env(); } -# define TAINT_PROPER(s) if (PL_tainting) { taint_proper(NULL, s); } +# define TAINT_IF(c) if (UNLIKELY(c)) { PL_tainted = TRUE; } +# define TAINT_ENV() if (UNLIKELY(PL_tainting)) { taint_env(); } +# define TAINT_PROPER(s) if (UNLIKELY(PL_tainting)) { taint_proper(NULL, s); } # define TAINT_set(s) (PL_tainted = (s)) # define TAINT_get (PL_tainted) # define TAINTING_get (PL_tainting) @@ -278,15 +278,15 @@ Does not use C<TARG>. See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>. =cut */ -#define EXTEND(p,n) (void)(PL_stack_max - p < (int)(n) && \ +#define EXTEND(p,n) (void)(UNLIKELY(PL_stack_max - p < (int)(n)) && \ (sp = stack_grow(sp,p, (int) (n)))) /* Same thing, but update mark register too. */ -#define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (int)(n)) { \ - const int markoff = mark - PL_stack_base; \ - sp = stack_grow(sp,p,(int) (n)); \ - mark = PL_stack_base + markoff; \ - } } STMT_END +#define MEXTEND(p,n) STMT_START {if (UNLIKELY(PL_stack_max - p < (int)(n))) {\ + const int markoff = mark - PL_stack_base; \ + sp = stack_grow(sp,p,(int) (n)); \ + mark = PL_stack_base + markoff; \ + } } STMT_END #define PUSHs(s) (*++sp = (s)) #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END @@ -388,7 +388,7 @@ Does not use C<TARG>. See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>. #define EXTEND_MORTAL(n) \ STMT_START { \ - if (PL_tmps_ix + (n) >= PL_tmps_max) \ + if (UNLIKELY(PL_tmps_ix + (n) >= PL_tmps_max)) \ tmps_grow(n); \ } STMT_END @@ -1246,12 +1246,12 @@ Perl_sv_upgrade(pTHX_ SV *const sv, svtype new_type) assert(!SvPAD_TYPED(sv)); break; default: - if (old_type_details->cant_upgrade) + if (UNLIKELY(old_type_details->cant_upgrade)) Perl_croak(aTHX_ "Can't upgrade %s (%" UVuf ") to %" UVuf, sv_reftype(sv, 0), (UV) old_type, (UV) new_type); } - if (old_type > new_type) + if (UNLIKELY(old_type > new_type)) Perl_croak(aTHX_ "sv_upgrade from type %d down to type %d", (int)old_type, (int)new_type); @@ -1386,7 +1386,7 @@ Perl_sv_upgrade(pTHX_ SV *const sv, svtype new_type) SvNV_set(sv, 0); #endif - if (new_type == SVt_PVIO) { + if (UNLIKELY(new_type == SVt_PVIO)) { IO * const io = MUTABLE_IO(sv); GV *iogv = gv_fetchpvs("IO::File::", GV_ADD, SVt_PVHV); @@ -1399,7 +1399,7 @@ Perl_sv_upgrade(pTHX_ SV *const sv, svtype new_type) SvSTASH_set(io, MUTABLE_HV(SvREFCNT_inc(GvHV(iogv)))); IoPAGE_LEN(sv) = 60; } - if (new_type == SVt_REGEXP) + if (UNLIKELY(new_type == SVt_REGEXP)) sv->sv_u.svu_rx = (regexp *)new_body; else if (old_type < SVt_PV) { /* referant will be NULL unless the old type was SVt_IV emulating |