Changeset 1211 for proto


Ignore:
Timestamp:
Jul 6, 2011, 2:49:20 PM (8 years ago)
Author:
cameron
Message:

bitutil.Advance32() support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r1198 r1211  
    194194    return self.carry_count
    195195
     196class Adv32Counter(ast.NodeVisitor):
     197  def visit_Call(self, callnode):
     198    self.generic_visit(callnode)
     199    if is_BuiltIn_Call(callnode,'Advance32', 1):       
     200      self.adv32_count += 1
     201  def count(self, nodeToVisit):
     202    self.adv32_count = 0
     203    self.generic_visit(nodeToVisit)
     204    return self.adv32_count
     205
    196206class CarryIntro(ast.NodeTransformer):
    197207  def __init__(self, carryvar="carryQ", carryin = "_ci", carryout = "_co"):
     
    201211  def xfrm_fndef(self, fndef):
    202212    self.current_carry = 0
     213    self.current_adv32 = 0
    203214    carry_count = CarryCounter().count(fndef)
    204215    if carry_count == 0: return fndef
     
    209220  def generic_xfrm(self, node):
    210221    self.current_carry = 0
     222    self.current_adv32 = 0
    211223    carry_count = CarryCounter().count(node)
    212     if carry_count == 0: return node
     224    adv32_count = Adv32Counter().count(node)
     225    if carry_count == 0 and adv32_count == 0: return node
    213226    self.generic_visit(node)
    214227    return node
    215228  def visit_Call(self, callnode):
    216229    self.generic_visit(callnode)
    217     if self.carryin == '' and self.carryout == '': carry_args = []
    218     else: carry_args = [self.carryvar, ast.Num(self.current_carry)]
     230    if self.carryin == '' and self.carryout == '':
     231        carry_args = []
     232        adv32_args = []
     233    else:
     234        carry_args = [self.carryvar, ast.Num(self.current_carry)]
     235        adv32_args = [ast.Subscript(ast.Name('pending32', ast.Load()), ast.Num(self.current_adv32), ast.Load())]
    219236    if is_BuiltIn_Call(callnode, 'Advance', 1):         
    220237      rtn = "BitBlock_advance%s%s" % (self.carryin, self.carryout)
    221238      c = mkCall(rtn, callnode.args + carry_args)
    222239      self.current_carry += 1
     240      return c
     241    elif is_BuiltIn_Call(callnode, 'Advance32', 1):     
     242      rtn = "BitBlock_advance32%s%s" % (self.carryin, self.carryout)
     243      c = mkCall(rtn, callnode.args + adv32_args)
     244      self.current_adv32 += 1
    223245      return c
    224246    elif is_BuiltIn_Call(callnode, 'ScanThru', 2):
     
    264286    carry_base = self.current_carry
    265287    carries = CarryCounter().count(ifNode)
     288    assert Adv32Counter().count(ifNode) == 0, "Advance32() within if: illegal\n"
    266289    self.generic_visit(ifNode)
    267290    if carries == 0 or self.carryin == "": return ifNode
     
    274297      whileNode.test.args[0] = mkCall("simd_and", [whileNode.test.args[0], ast.Name('EOF_mask', ast.Load())])
    275298    carry_base = self.current_carry
     299    assert Adv32Counter().count(whileNode) == 0, "Advance32() within while: illegal\n"
    276300    carries = CarryCounter().count(whileNode)
    277301    if carries == 0: return whileNode
     
    310334    BitBlock a2;
    311335    BitBlock a3;
    312   }
     336  }    self.current_adv32 = 0
     337
    313338 
    314339  struct S2 {
     
    423448        def __init__(self):
    424449                self.carry_count = 0
     450                self.adv32_count = 0
    425451                self.type_name = ""
    426452                self.instance_name = ""
     
    451477                self.type_name = stream_function.type_name
    452478               
    453                 if stream_function.carry_count > 0:
    454                         constructor = self.constructor(stream_function.type_name, stream_function.carry_count)
    455                         carry_declaration = self.carry_declare(stream_function.carry_count)
     479                if stream_function.carry_count > 0 or stream_function.adv32_count > 0:
     480                        constructor = self.constructor(stream_function.type_name, stream_function.carry_count, stream_function.adv32_count)
     481                        carry_declaration = self.carry_declare(stream_function.carry_count, stream_function.adv32_count)
    456482
    457483                do_block_function = self.do_block(self.do_block_parameters(stream_function.parameters),
     
    484510                + "\n" + self.indent(icount) + "};\n\n"
    485511
    486         def constructor(self, type_name, carry_count, icount=0):
    487                 return self.indent(icount) + "%s() { """ % (type_name) + self.carry_init(carry_count) + " }"
     512        def constructor(self, type_name, carry_count, adv32_count, icount=0):
     513                adv32_decl = ""
     514                for i in range(adv32_count): adv32_decl += self.indent(icount+2) + "pending32[%s] = 0;\n" % i   
     515                return self.indent(icount) + "%s() { ""\n" % (type_name) + adv32_decl + self.carry_init(carry_count) + " }"
    488516                       
    489517        def do_block(self, parameters, declarations, initializations, statements, icount=0):
     
    539567                return self.indent(icount) + "CarryInit(carryQ, %i);" % (carry_count)
    540568       
    541         def carry_declare(self, carry_count, icount=0):
    542                 return self.indent(icount) + "CarryDeclare(carryQ, %i);" % (carry_count)
     569        def carry_declare(self, carry_count, adv32_count, icount=0):
     570                adv32_decl = ""
     571                if adv32_count > 0:
     572                        adv32_decl = "\n" + self.indent(icount) + "uint32_t pending32[%s];" % adv32_count
     573                return self.indent(icount) + "CarryDeclare(carryQ, %i);" % (carry_count) + adv32_decl
    543574
    544575        def carry_test(self, carry_variable, carry_count, icount=0):
     
    596627    self.main_node = self.stream_function_node[main_node_id]
    597628    self.main_carry_count = CarryCounter().count(self.main_node)
     629    self.main_adv32_count = Adv32Counter().count(self.main_node)
     630    assert self.main_adv32_count == 0, "Advance32() in main not supported.\n"
    598631    del self.stream_function_node[self.main_node_id]
    599632   
     
    602635                stream_function = StreamFunction()
    603636                stream_function.carry_count = CarryCounter().count(node)
     637                stream_function.adv32_count = Adv32Counter().count(node)
    604638                stream_function.type_name = node.name[0].upper() + node.name[1:]
    605639                stream_function.instance_name = node.name[0].lower() + node.name[1:]
Note: See TracChangeset for help on using the changeset viewer.