In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/2439e03355dec26654acf614900c077433bc27e0?hp=8da3792e39c8a8877091f33438f7191493dbefea>
- Log ----------------------------------------------------------------- commit 2439e03355dec26654acf614900c077433bc27e0 Author: Steffen Mueller <[email protected]> Date: Wed Mar 6 20:39:43 2013 +0100 (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. ----------------------------------------------------------------------- Summary of changes: inline.h | 6 +++--- perl.h | 6 +++--- pp.h | 14 +++++++------- sv.c | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/inline.h b/inline.h index 6b5f93c..6cdfe9f 100644 --- a/inline.h +++ b/inline.h @@ -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; diff --git a/perl.h b/perl.h index 4b020c7..5639f1c 100644 --- a/perl.h +++ b/perl.h @@ -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) diff --git a/pp.h b/pp.h index 377d489..cb6a066 100644 --- a/pp.h +++ b/pp.h @@ -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 diff --git a/sv.c b/sv.c index f58389b..3f68d9c 100644 --- a/sv.c +++ b/sv.c @@ -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 -- Perl5 Master Repository
