예제 #1
0
 def add_cpght(self, cpght) :
     if type(cpght) is str :
         self.__banner_cpght.append(cpght)
     elif type(cpght) is list :
         self.__banner_cpght.extend(cpght)
     self.__banner_cpght = sub_list('<year>',self.__year,self.__banner_cpght)
     self.__banner_cpght = sub_list('^//',self.__comment,self.__banner_cpght)
     self.__banner_cpght = sub_list('@',self.__comment[0],self.__banner_cpght)
예제 #2
0
 def default(self,name,arity) :
     s =  Recover_similar_benchs.Default_bench
     new_tb_name = self.get_tb_name()
     s = sub_list("\$tb_name\$",new_tb_name,s)
     s = sub_list("\$name\$",name,s)
     s = sub_list("\$typ_"+"float"+"\$", "(RS(float,-1.0f,1.0f))"*arity,s)
     s = sub_list("\$typ_"+"double"+"\$", "(RS(double,-1.0f,1.0f))"*arity,s)
     s = sub_list("\$typ_"+"int32_t"+"\$", "(RS(int32_t,-1,1))"*arity,s)
     return s
예제 #3
0
 def replace(self):
     for f in self.get_list_cpps():
         full_f = os.path.join(self.get_unit_simd_path(), f)
         if self.ok(full_f):
             s = Rep_units_simd.Simd_unit
             s = sub_list("\$name\$", f[:-4], s)
             s = sub_list("\$tb_name\$", self.get_tb_name(), s)
             show(s)
             write(full_f, s, False)
예제 #4
0
 def make_new_bench_file(self,name,mode) :
     oldb = self.get_old_bench_text(name)
     newb = self.get_base(mode)
     newb = sub_list('\$name\$',name,newb)
     newb = sub_list('\$tb_name\$',self.get_tb_name(),newb)
     newb = newb[:14]+self.define_types(oldb,mode)+newb[14:]
     newb = newb[:-2]+sub_list(' ','',self.get_range_list(name,oldb,mode))+newb[-2:]
     #        show(newb)
     write(os.path.join(self.get_new_path(mode),name+'.cpp'),newb,False)
예제 #5
0
 def default(self,name,arity) :
     s =  Recover_similar_units.Default_unit
     new_tb_name = self.get_tb_name()
     s = sub_list("\$tb_name\$",new_tb_name,s)
     s = sub_list("\$name\$",name,s)
     def strlist(tpl,n=1,sep = ", ") :
         s = tpl % (n*(0,))
         tpl =sep+tpl
         for i in range(1,arity) :
             s += tpl % (n*(i,))
         return s
     s = sub_list("\$list\$",strlist("T",0),s)
     return s
예제 #6
0
 def create_call(self, dispatch):
     mode = self.fcti.get_fct_mode()
     test = re.search("common",mode)
     p1 = "class Extension, " if test else ""
     if test :
         p2 = ",Extension"
     elif mode == "scalar" :
         p2 = ""
     else :
         p2 = ",tag::"+self.fcti.get_fct_archi_spec()+"_"
     p3 = "" if  self.fcti.tbi.get_tb_style() == "sys" else  self.fcti.tbi.get_tb_name()+"::"
     r = [
         "",
         "  /////////////////////////////////////////////////////////////////////////////",
         "  // Implementation when type "+ (
             self.fcti.get_old_fct_dispatch_type() +
             " is " + dispatch),
         "  /////////////////////////////////////////////////////////////////////////////",
         "  template<"+p1+"class Info>",
         "  struct call<" + (p3+self.fcti.get_fct_name() +
                              "_,tag::"+ self.fcti.get_fct_archi() +
                              "_(tag::arithmetic_"+p2+")," +
                              dispatch +
                              ",Info> : callable"),
         "  {"
         ]
     r += self.fcti.get_result_txt()
     s = self.fcti.get_old_fct_call(dispatch)
     if s is not None :
         if len(s)==1 :
             s = sub_list(" *NT2_FUNCTOR_CALL_EVAL_IF\( *\d *,.*\) *{",
                      "    NT2_FUNCTOR_CALL("+str(self.fcti.get_fct_arity())+"){",s)
             s = sub_list(" *}"," }",s)
         else :   
              s = sub_list(" *NT2_FUNCTOR_CALL_EVAL_IF\( *\d *,.*\)",
                      "    NT2_FUNCTOR_CALL("+str(self.fcti.get_fct_arity())+")",s)
     else :
         s = self.fcti.get_old_fct_call(None)
     def postfix(d) :    
         c = {"float" : "f","double" : "", "long double" : "l"}
         if d in c.keys() :
             return c[dispatch]
         else :
             return ""
     s = sub_list("cephes_"+self.fcti.get_fct_name(), "cephes_"+self.fcti.get_fct_name()+postfix(dispatch),s)
     r += s
     r += [
         "  };"
         ]
     return r
예제 #7
0
 def mk_guard(self) :
     """create a file guard in two parts"""
     path = self.mk_guard_path().upper()
     path  = re.sub('[^(A-Z|0-9)]','_',path)
     path  = re.sub('__','_',path)
     if path[0]=='/' :
         path=path[1:]
     self.__guard_begin = sub_list('<path>',path,self.__guard_begin)
예제 #8
0
 def mk_replace(self,s,repls) :
     wr = False
     for target in repls.keys() :
         st ='\n'.join(s)
         if re.search(target,st) :
             s=sub_list(target, repls[target],s)
             wr=True
     return (s, wr)
예제 #9
0
 def modify_tpl_defs(self) :
     for k in self.get_dict().keys() :
         if self.get_dict()[k][1] :
            p =  os.path.join(self.get_new_def_path(),k+'.hpp')
            s = read(p)
            pattern = " *NT2_FUNCTION_IMPLEMENTATION.*"
            rep = "  NT2_CRLIBM_FUNCTION_IMPLEMENTATION_TPL("+k+")"
            s = sub_list(pattern,rep,s)
            show(s)
            write(p,s,False)
예제 #10
0
 def get_replacmt(self,target) :
     for d in self.get_list_dirs() :
         for h in self.get_list_hpps() :
             f = os.path.join(d,h)
             if exist(f) :
                 s = read(f)
                 st ='\n'.join(s)
                 if re.search(target,st) :
                    s=sub_list(target, Insert.Replacement[target],s)
                    write(f,s,False)
                    print "%s -> %s"%(target,Insert.Replacement[target])
예제 #11
0
 def adapt_similar(self,s,name,old_tb_name) :
     new_tb_name = self.get_tb_name()
     old_name = self.strip(name)
     new_name = self.decorate(name)
     print "old %s -> new %s"% (old_name,new_name)
     if old_name == name : # template case
         s = sub_list(' '+old_name+'\(',' '+new_name+'(',s)
         s = sub_list(old_tb_name,new_tb_name,s)
         s = sub_list("nt2::functors::"+old_name,"nt2::"+new_tb_name+"::"+old_name,s)
         s = sub_list(old_name+'<rn>_',old_name+'_<rn>',s)
         s = sub_list("<rn>","<nt2::rn>",s)
         s = sub_list("NT2_TIMING\(nt2::crlibm::"+old_name+"_","NT2_TIMING(nt2::crlibm::"+old_name+"_<nt2::rn>",s)
     else :
         s = sub_list("nt2::functors::","nt2::"+new_tb_name+"::",s)
         s = sub_list(old_tb_name,new_tb_name,s)
         s = sub_list(old_name,new_name,s)
     return s
예제 #12
0
 def __init__(self,
              year = None,
              banner_cpght = None,
              banner_template_begin = None,
              banner_template_end   = None,
              comment = '//') :
     self.logger = Mylogging("nt2.banner.Banner")
     self.__banner_begin = Banner.Std_begin if (banner_template_begin is None) else banner_template_begin
     self.__banner_end   = Banner.Std_end   if (banner_template_end   is None) else banner_template_end
     self.__banner_cpght = Banner.Std_cpght if (banner_cpght          is None) else banner_cpght 
     self.__year = year
     self.__comment=comment
     self.set_year()
     self.cpght = sub_list('^//',self.__comment,self.__banner_cpght)
     self.__banner_begin = sub_list('^//',self.__comment,self.__banner_begin)
     self.__banner_end = sub_list('^//',self.__comment,self.__banner_end)
     self.__banner_cpght = sub_list('<year>',self.__year,self.__banner_cpght)
     self.__banner_cpght = sub_list('^//',self.__comment,self.__banner_cpght)
     self.__banner_begin = sub_list('@',self.__comment[0],self.__banner_begin)
     self.__banner_end = sub_list('@',self.__comment[0],self.__banner_end)
     self.__banner_cpght = sub_list('@',self.__comment[0],self.__banner_cpght)
예제 #13
0
 def set_year(self) :
     if self.__year is None :
         self.__year = time.localtime().tm_year
     if type(self.__year) is not str :
         self.__year = str(self.__year)
     if len(self.__year)==1 :
         self.__year = '0'+self.__year
     if len(self.__year)==2 :
         self.__year = "20"+self.__year
     try :
         self.__year = str(int(self.__year))
     except :
         saved_year =self.__year
         self.logger.warning(
             "\nin setyear\n"+
             ("year has been given the incorrect value: %s" % self.__year)
             )
         self.__year = str(time.localtime().tm_year)
         self.logger.warning(
             "\nin Banner.setyear\n "+
             "year has been given the incorrect value: %s" % saved_year +
             "\nyear is turned to %s " % self.__year
             )
     self.__banner_cpght = sub_list('<year>',self.__year,self.__banner_cpght)
예제 #14
0
 def adapt_similar(self, s, name, old_tb_name):
     new_tb_name = self.get_tb_name()
     old_name = self.strip(name)
     new_name = self.decorate(name)
     print "old %s, new %s" % (old_name, new_name)
     if old_name == name and new_tb_name == "crlibm":  # template case
         s = sub_list(" " + old_name + "\(", " " + new_name + "(", s)
         s = sub_list(old_tb_name, new_tb_name, s)
         s = sub_list("using nt2::" + old_name, "using nt2::" + new_tb_name + "::" + old_name, s)
         s = sub_list("using nt2::functors::" + old_name, "using nt2::" + new_tb_name + "::" + old_name, s)
         s = sub_list("nt2::" + old_name, "nt2::" + new_tb_name + "::" + new_name, s)
         s = sub_list(old_name + "_\(", new_name + "_(", s)
         s = sub_list(old_name + "<rn>_", old_name + "_<rn>", s)
         s = sub_list("<rn>", "<nt2::rn>", s)
     else:
         s = sub_list(old_tb_name, new_tb_name, s)
         s = sub_list(" " + old_name + "\(", " " + new_name + "(", s)
         s = sub_list(old_name + "\.hpp", new_name + ".hpp", s)
         s = sub_list(" " + old_name + ",", " " + new_name + ",", s)
         s = sub_list("using nt2::" + old_name, "using nt2::" + new_tb_name + "::" + new_name, s)
         s = sub_list("using nt2::functors::" + old_name, "using nt2::" + new_tb_name + "::" + new_name, s)
         s = sub_list("nt2::" + old_name, "nt2::" + new_tb_name + "::" + new_name, s)
         s = sub_list(old_name + "_\(", new_name + "_(", s)
     return s
예제 #15
0
 def __read_old_fctor_txt(self) :
     p = self. get_fct_path()
     r = read(p)
     r = sub_list("^tag::sse_$","",r)
     return r
예제 #16
0
 def adapt_similar(self,s,name,old_tb_name) :
     new_tb_name = self.get_tb_name()
     old_name = self.strip(name)
     new_name = self.decorate(name)
     print "old %s, new %s"% (old_name,new_name)
     if old_name == name and new_tb_name =="crlibm" : # template case
         s = sub_list(' '+old_name+'\(',' '+new_name+'(',s)
         s = sub_list(old_tb_name,new_tb_name,s)
         s = sub_list("using nt2::"+old_name,"using nt2::"+new_tb_name+"::"+old_name,s)
         s = sub_list("using nt2::functors::"+old_name,"using nt2::"+new_tb_name+"::"+old_name,s)
         s = sub_list("nt2::"+old_name,"nt2::"+new_tb_name+"::"+new_name,s)
         s = sub_list(old_name+'_\(',new_name+'_(',s)
         s = sub_list(old_name+'<rn>_',old_name+'_<rn>',s)
         s = sub_list("<rn>","<nt2::rn>",s)
     else :
         s = sub_list(old_tb_name,new_tb_name,s)
         s = sub_list(' '+old_name+'\(',' '+new_name+'(',s)
         s = sub_list(old_name+'\.hpp',new_name+'.hpp',s)
         s = sub_list(' '+old_name+',',' '+new_name+',',s)
         s = sub_list("using nt2::"+old_name,"using nt2::"+new_tb_name+"::"+new_name,s)
         s = sub_list("using nt2::functors::"+old_name,"using nt2::"+new_tb_name+"::"+new_name,s)
         s = sub_list("nt2::"+old_name,"nt2::"+new_tb_name+"::"+new_name,s)
         s = sub_list(old_name+'_\(',new_name+'_(',s)
     return s
예제 #17
0
파일: modify_defs.py 프로젝트: Mathieu-/nt2
 def rep_unit(self,s):
     pattern = "\.unit"
     rep = ".bench"
     return sub_list(pattern,rep,s)
예제 #18
0
파일: modify_defs.py 프로젝트: Mathieu-/nt2
 def comment_simd_def(self,s):
     pattern = "^#include NT2_"+self.get_tb_name().upper()
     rep = "// "+pattern[1:]
     return sub_list(pattern,rep,s)