public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Ondrej Kubanek <kubaneko@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] fixed up fix-up functions Date: Wed, 15 Mar 2023 00:21:58 +0000 (GMT) [thread overview] Message-ID: <20230315002158.10A723858D33@sourceware.org> (raw) https://gcc.gnu.org/g:b9d5d2a699fe0ebf877abfcab3284b901f790091 commit b9d5d2a699fe0ebf877abfcab3284b901f790091 Author: kubaneko <kubanek0ondrej@gmail.com> Date: Wed Mar 15 00:21:44 2023 +0000 fixed up fix-up functions Diff: --- gcc/cfgloop.cc | 69 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/gcc/cfgloop.cc b/gcc/cfgloop.cc index f5e229e18c1..d23ee01bea7 100644 --- a/gcc/cfgloop.cc +++ b/gcc/cfgloop.cc @@ -2185,16 +2185,35 @@ loops_list::walk_loop_tree (class loop *root, unsigned flags) this->to_visit.quick_push (root->num); } +unsigned int hist_index(gcov_type_unsigned val){ + unsigned int lin_size=param_profile_histogram_size_lin; + unsigned int tot_size=param_profile_histogram_size; + if (val<lin_size){ + return val; + }else{ + gcov_type_unsigned pow2=floor_log2(val); + gcov_type_unsigned lin_pow2=floor_log2(lin_size-1); + if ((lin_pow2-lin_size)+tot_size>pow2){ + return pow2+(lin_size-lin_pow2)-1; + } else { + return tot_size-1; + } + } +} + void histogram_counters_minus_upper_bound (histogram_counters* hist_c, gcov_type_unsigned difference){ - if (hist_c==NULL || difference==0) + if (!hist_c || difference==0) return; auto hist=*(hist_c->hist); unsigned int lin_size=param_profile_histogram_size_lin; - unsigned int lin_pow2=floor_log2(lin_size-1); unsigned int tot_size=param_profile_histogram_size; - gcov_type_unsigned log_diff=floor_log2(difference); + + // next power of 2 for linear hist + unsigned int lin_size_upp=1<<ceil_log2(lin_size); + // If the last linear counter does not contain other iterations + unsigned int last_lin=(lin_size_upp==lin_size?0:1); unsigned int i=1; - for(; i<lin_size-1 && i<tot_size-1; i++){ + for(; i<lin_size-last_lin; i++){ if (i<=difference){ hist[0]+=hist[i]; } else { @@ -2202,35 +2221,25 @@ void histogram_counters_minus_upper_bound (histogram_counters* hist_c, gcov_type } hist[i]=0; } - // we try to restore some of the linear histogram - // for the last linear counter containing also lesser values then nearest pow2 - // assumption is uniform - gcov_type_unsigned upper_bound_lin=(1<<(ceil_log2(lin_size)-1)); - if (lin_size>2 && difference<upper_bound_lin && i<tot_size-1){ - gcov_type_unsigned lin_size_val=hist[lin_size-1]/((upper_bound_lin-1)-(lin_size-2)); - for (int j=int(i)-int(difference);j<gcov_type(upper_bound_lin)-gcov_type(difference)+1 - && j<int(lin_size)-1;i++) { - if (j<0) { - hist[0]+=lin_size_val; - } else { - hist[j]+=lin_size_val; - } - hist[lin_size-1]-=lin_size_val; - } - i++; - } - // Index where difference would be placed - unsigned diff_index=log_diff+(lin_size-lin_pow2)-1; - for (; i<diff_index && difference<lin_size && i<tot_size-1;i++){ + // next pow2 + gcov_type_unsigned pow2=((gcov_type_unsigned)1)<<(ceil_log2(lin_size)+i+1-lin_size); + // we null all counters that cannot transfer to non-zero counts + for (;pow2-1<difference && i<tot_size-1;++i){ hist[0]+=hist[i]; hist[i]=0; + pow2=pow2<<1; } - for (; i<tot_size-1 && (1<<(i-diff_index+2))<10000;i++){ - // We assume uniform distribution - // tot_size -1 should not be touched We know little about it - gcov_type_unsigned share=hist[i]/(1<<(i-diff_index+2)); - hist[i-1]+=share; - hist[i]-=share; + // reset to actual value + // lower half of the pow2 is added to index hald-difference, other half stays + for (;i<tot_size-1;++i){ + gcov_type_unsigned half=(pow2>>1) + (pow2 >> 2); + int64_t diff=hist[i]/2; + unsigned int ind=hist_index(half>=difference?half-difference:0); + if (ind==i) + return; + hist[ind]+=diff; + hist[i]-=diff; + pow2<<=1; } }
reply other threads:[~2023-03-15 0:21 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230315002158.10A723858D33@sourceware.org \ --to=kubaneko@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).