Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

branch_result.cpp

Go to the documentation of this file.
00001 /*
00002         Copyright (C) 1997 CFU Corporation
00003 
00004         File: branch_result.cpp
00005         Description: branch result
00006         Author: Chao-yinig Fu
00007         Date: Oct. 31, 2000
00008 
00009         ^..^
00010         (00)
00011 
00012          $__$
00013         <~00~>
00014          (oo)
00015           ||
00016 
00017         ```````
00018         C ^|^ D
00019          \ O /
00020 */
00021 
00022 #include "branch_result.h"
00023 #include "my_mem_db.h"
00024 
00025 //
00026 // Parameter
00027 //      ip: ip of this mop
00028 //      correct: 1=correct, 0=not correct
00029 void Profile_Branch::record(int ip,int correct)
00030 {
00031         int index=ip>>_b;
00032         index=index%MAX_NUM_OF_BR;
00033 
00034         Branch_Result *br=&_br[index];
00035         int this_ip=br->ip();
00036 
00037         if(this_ip==-1)
00038         {
00039                 br->set_ip(ip);
00040         }
00041         else if(this_ip!=ip)    // search the bucket
00042         {
00043                 Branch_Result *prev_br=br;
00044                 Branch_Result *this_br=br->next();
00045                 for(;this_br!=NULL;this_br=this_br->next())
00046                 {
00047                         if(this_br->ip()==ip)
00048                         {
00049                                 break;
00050                         }
00051                         prev_br=this_br;
00052                 }
00053 
00054                 if(this_br!=NULL)
00055                 {
00056                         br=this_br;
00057                 }
00058                 else
00059                 {
00060                         Branch_Result *new_br=new Branch_Result();
00061                         new_br->set_ip(ip);
00062                         prev_br->set_next(new_br);
00063                         br=new_br;
00064                 }
00065         }
00066 
00067         br->inc_access();
00068         if(correct==1)
00069         {
00070                 br->inc_br_cor();
00071         }
00072         else
00073         {
00074                 br->inc_br_incor();
00075         }
00076 }
00077 
00078 void Profile_Branch::print(FILE *f,A_Proc *code_database)
00079 {
00080         for(int i=0;i<MAX_NUM_OF_BR;i++)
00081         {
00082                 Branch_Result *br=&_br[i];
00083                 int ip=br->ip();
00084 
00085                 if(ip!=-1)
00086                 {
00087                         Multi_Op *mop=code_database->find_mop_by_ip(ip);
00088                         assert(mop!=NULL);
00089                         Block_List *bb=mop->bb();
00090                         assert(bb!=NULL);
00091                         int bbid=bb->bbid();
00092                         A_Proc *proc=bb->parent();
00093                         assert(proc!=NULL);
00094 
00095                         br->print(f);
00096                         fprintf(f," [%s %d %d]\n",proc->name(),bbid,mop->has_branch());
00097 
00098                         for(Branch_Result *next_br=br->next();next_br!=NULL;next_br=next_br->next())
00099                         {
00100                                 next_br->print(f);
00101                         }
00102                 }
00103         }
00104 }

Generated on Mon Jul 21 20:24:02 2003 for TINKER LEGO DOC by doxygen 1.3.2