Changeset 2640


Ignore:
Timestamp:
Nov 16, 2012, 12:20:19 PM (6 years ago)
Author:
cameron
Message:

GenerateCarryDecls?, GenerateLocalDeclare?, GenerateCarryWhileTest?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r2638 r2640  
    499499        # Add a dummy entry for any possible final block that is empty.
    500500        self.carryIndex[carryInfoSet.operation_no] = carry_counter
     501    # Helper
    501502    def CarryGroupAtt(self, attname, CarryGroupVarName=""):
    502503        if CarryGroupVarName == '': CarryGroupVarName = self.carryGroupVar
    503504        return ast.Attribute(ast.Name(CarryGroupVarName, ast.Load()), attname, ast.Load())
     505    def GenerateCarryDecls(self):
     506        carry_counter = 0
     507        adv_n_counter = 0
     508        for op_no in range(self.carryInfoSet.block_op_count[0]):
     509          if not op_no in self.carryInfoSet.advance_amount.keys(): carry_counter += 1
     510          elif self.carryInfoSet.advance_amount[op_no] == 1: carry_counter += 1
     511          else: adv_n_counter += 1
     512        return "CarryArray<%i, %i> %s;" % (carry_counter, adv_n_counter, self.carryGroupVar)
     513
    504514    def GenerateCarryInAccess(self, operation_no):
    505515        carry_index = self.carryIndex[operation_no - self.operation_offset]
     
    519529        ifIndex = self.carryIndex[self.carryInfoSet.block_first_op[block_no]]       
    520530        return [mkCallStmt(self.CarryGroupAtt('CarryDequeueEnqueue'), [ast.Num(ifIndex), ast.Num(carry_count)])]
    521     def GenerateCarryWhileTest(self, whileIndex): pass
     531    def GenerateLocalDeclare(self, block_no):
     532        local_carryvar = ast.Name("sub" + self.carryGroupVar, ast.Load())
     533        return mkCallStmt('LocalCarryDeclare', [local_carryvar, ast.Num(self.carryInfoSet.block_op_count[block_no])])
     534    def GenerateCarryWhileTest(self, block_no, testExpr):
     535        carry_count = self.carryInfoSet.block_op_count[block_no]
     536        if carry_count == 0: return testExpr
     537        carry0 = self.carryIndex[self.carryInfoSet.block_first_op[block_no]]       
     538        return ast.BoolOp(ast.Or(), [testExpr, mkCall(self.CarryGroupAtt('CarryTest'), [ast.Num(carry0), ast.Num(carry_count)])])
    522539    def EnterLocalWhileBlock(self, operation_offset): 
    523540        self.carryGroupVar = "sub" + self.carryGroupVar
     
    816833    inner_while = self.local_while_xfrm(local_carryvar, copy.deepcopy(whileNode))
    817834    self.generic_visit(whileNode)
    818     local_carry_decl = mkCallStmt('LocalCarryDeclare', [local_carryvar, ast.Num(carries)])
     835    local_carry_decl = self.ccgo.GenerateLocalDeclare(this_block)
     836    #local_carry_decl = mkCallStmt('LocalCarryDeclare', [local_carryvar, ast.Num(carries)])
    819837    inner_while.body.insert(0, local_carry_decl)
    820838    #final_combine = mkCallStmt(ast.Attribute(self.carryvar, 'CarryCombine', ast.Load()), [ast.Attribute(local_carryvar, 'cq', ast.Load()),ast.Num(carry_base), ast.Num(carries)])
     
    835853
    836854    if self.carryin == '': new_test = whileNode.test
    837     else: new_test = ast.BoolOp(ast.Or(), [whileNode.test, mkCall(ast.Attribute(self.carryvar, 'CarryTest', ast.Load()), carry_test_arglist)])
    838     else_part = [mkCallStmt(ast.Attribute(self.carryvar, 'CarryDequeueEnqueue', ast.Load()), [ast.Num(carry_base), ast.Num(carries)])]   
     855    else: new_test = self.ccgo.GenerateCarryWhileTest(this_block, whileNode.test)
     856    else_part = [self.ccgo.GenerateCarryElseFinalization(this_block)]   
    839857    newIf = ast.If(new_test, whileNode.body + while_body_extend, else_part)
    840858    self.last_stmt = newIf
     
    925943                err_stream = node.value.args[0]
    926944                err_code = node.value.args[1]
    927                 return ast.If(err_stream,
     945                return ast.If(mkCall('bitblock::any', [err_stream]),
    928946                              [ast.Expr(mkCall(self.assert_routine, [err_code, err_stream]))],
    929947                              [])
     
    10361054
    10371055class Emitter():
    1038         def __init__(self, use_C_syntax):
     1056        def __init__(self, use_C_syntax, ccgo):
    10391057                self.use_C_syntax = use_C_syntax
     1058                self.ccgo = ccgo
    10401059
    10411060        def definition(self, stream_function, icount=0):
     
    11441163                #       adv_n_decl = "\n" + self.indent(icount) + "BitBlock pending64[%s];" % adv_n_count
    11451164                #CARRY SET
    1146                 return self.indent(icount) + "CarryArray<%i, %i> %s;" % (carry_count, adv_n_count, carry_variable)
     1165                return self.indent(icount) + self.ccgo.GenerateCarryDecls()
    11471166
    11481167        def carry_test(self, carry_variable, carry_count, icount=0):
     
    12061225    self.main_carry_count = CarryCounter().count(self.main_node)
    12071226    self.main_adv_n_count = adv_nCounter().count(self.main_node)
     1227    self.main_carry_info_set = CarryInfoSetVisitor().getInfoSet(self.main_node)
     1228    self.main_ccgo = Strategic_CCGO_Factory(self.main_carry_info_set)
    12081229    assert self.main_adv_n_count == 0, "Advance32() in main not supported.\n"
    12091230    del self.stream_function_node[self.main_node_id]
     
    12151236                stream_function.init_to_one_list = CarryInitToOneList().count(node)
    12161237                stream_function.adv_n_count = adv_nCounter().count(node)
     1238                carry_info_set = CarryInfoSetVisitor().getInfoSet(node)
     1239                stream_function.ccgo = Strategic_CCGO_Factory(carry_info_set)
    12171240                stream_function.type_name = node.name[0].upper() + node.name[1:]
    12181241                stream_function.instance_name = node.name[0].lower() + node.name[1:]
     
    12261249
    12271250                StringMatchCompiler().xfrm(node)
    1228                 AssertCompiler().xfrm(node)
    12291251                AugAssignRemoval().xfrm(node)
    12301252
    1231                 carry_info_set = CarryInfoSetVisitor().getInfoSet(node)
    1232                 ccgo = Strategic_CCGO_Factory(carry_info_set)
    12331253               
    12341254                Bitwise_to_SIMD().xfrm(node)
     
    12371257                        carryQname = stream_function.instance_name + ".carryQ"
    12381258                else: carryQname = "carryQ"
    1239                 CarryIntroVisitor = CarryIntro(ccgo, carryQname)
     1259                CarryIntroVisitor = CarryIntro(stream_function.ccgo, carryQname)
    12401260                CarryIntroVisitor.xfrm_fndef(node)
    12411261                CarryIntroVisitor.xfrm_fndef_final(final_block_node)
    1242 
     1262                #
     1263                # Compile asserts after carry intro so that generated if-statements
     1264                # are ignored.
     1265                AssertCompiler().xfrm(node)
     1266                AssertCompiler().xfrm(final_block_node)
    12431267                if self.add_dump_stmts:
    12441268                        Add_SIMD_Register_Dump().xfrm(node)
     
    12511275                #if stream_function.carry_count > 0:
    12521276                #       node.body += [mkCallStmt('carryQ.CarryQ_Adjust', [ast.Num(stream_function.carry_count)])]
    1253                 node.body += ccgo.GenerateStreamFunctionFinalization()
     1277                node.body += stream_function.ccgo.GenerateStreamFunctionFinalization()
    12541278
    12551279               
     
    12631287        sys.exit()
    12641288               
    1265     self.emitter = Emitter(self.use_C_syntax)
     1289    self.emitter = Emitter(self.use_C_syntax, stream_function.ccgo)
    12661290   
    12671291  def any_carry_expr(self):
     
    12861310    self.Cglobals = StreamStructGen().gen_struct_types(self.main_module)
    12871311    for key in self.stream_functions.keys():
    1288                 self.Cglobals += Emitter(self.use_C_syntax).definition(self.stream_functions[key],2)       
     1312                sf = self.stream_functions[key]
     1313                self.Cglobals += Emitter(self.use_C_syntax, sf.ccgo).definition(sf, 2)     
    12891314                       
    12901315  def gen_declarations(self): 
Note: See TracChangeset for help on using the changeset viewer.