Changeset 2260 for proto/Compiler


Ignore:
Timestamp:
Aug 4, 2012, 3:00:08 PM (7 years ago)
Author:
cameron
Message:

Initialize carries to one for scan_to_first.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/pablo.py

    r2255 r2260  
    6464  def visit_Call(self, callnode):
    6565    self.generic_visit(callnode)
    66     if len(callnode.args) == 0: return callnode
    6766    if not isinstance(callnode.args[0], ast.Call): return callnode
    6867    if is_BuiltIn_Call(callnode,'Advance', 1):
     
    277276    self.generic_visit(nodeToVisit)
    278277    return self.carry_count
     278
     279#
     280# Carry Initialization:  Aug. 4, 2012
     281# - Carry variables are initialized to 0 by default
     282# - However, the scan_to_first routine should ideally use
     283#   initialization with 1.
     284
     285#
     286class CarryInitToOneList(ast.NodeVisitor):
     287  def visit_Call(self, callnode):
     288    self.generic_visit(callnode)
     289    if is_BuiltIn_Call(callnode,'Advance', 1) or is_BuiltIn_Call(callnode,'ScanThru', 2) or is_BuiltIn_Call(callnode,'ScanTo', 2) or is_BuiltIn_Call(callnode,'AdvanceThenScanThru', 2) or is_BuiltIn_Call(callnode,'AdvanceThenScanTo', 2) or is_BuiltIn_Call(callnode,'SpanUpTo', 2) or  is_BuiltIn_Call(callnode,'InclusiveSpan', 2) or is_BuiltIn_Call(callnode,'ExclusiveSpan', 2):       
     290      self.carry_count += 1
     291    elif is_BuiltIn_Call(callnode,'ScanToFirst', 1):
     292      self.init_to_one_list.append(self.carry_count)
     293      self.carry_count += 1
     294  def visit_BinOp(self, exprnode):
     295    self.generic_visit(exprnode)
     296    if isinstance(exprnode.op, ast.Sub):
     297      self.carry_count += 1
     298    if isinstance(exprnode.op, ast.Add):
     299      self.carry_count += 1
     300  def count(self, nodeToVisit):
     301    self.carry_count = 0
     302    self.init_to_one_list = []
     303    self.generic_visit(nodeToVisit)
     304    return self.init_to_one_list
    279305
    280306class adv_nCounter(ast.NodeVisitor):
     
    630656                key = node.name[0].upper() + node.name[1:]
    631657                self.stream_function_node[key] = node
     658
     659
    632660               
    633661class StreamFunction():
    634662        def __init__(self):
    635663                self.carry_count = 0
     664                self.init_to_one_list = []
    636665                self.adv_n_count = 0
    637666                self.type_name = ""
     
    664693               
    665694                if stream_function.carry_count > 0 or stream_function.adv_n_count > 0:
    666                         constructor = self.constructor(stream_function.type_name, stream_function.carry_count, stream_function.adv_n_count)
     695                        constructor = self.constructor(stream_function.type_name, stream_function.carry_count, stream_function.init_to_one_list, stream_function.adv_n_count)
    667696                        carry_declaration = self.carry_declare('carryQ', stream_function.carry_count, stream_function.adv_n_count)
    668697
     
    696725                + "\n" + self.indent(icount) + "};\n\n"
    697726
    698         def constructor(self, type_name, carry_count, adv_n_count, icount=0):
     727        def constructor(self, type_name, carry_count, init_to_one_list, adv_n_count, icount=0):
     728                one_inits = ""
     729                for v in init_to_one_list:
     730                        one_inits += "  carryQ.cq[%s] = carry_flip(carryQ.cq[%s]);\n" % (v, v)
    699731                adv_n_decl = ""
    700732                #for i in range(adv_n_count): adv_n_decl += self.indent(icount+2) + "pending64[%s] = simd<1>::constant<0>();\n" % i     
    701                 return self.indent(icount) + "%s() { ""\n" % (type_name) + adv_n_decl + self.carry_init(carry_count) + " }"
     733                return self.indent(icount) + "%s() { ""\n" % (type_name) + adv_n_decl + self.carry_init(carry_count) + one_inits + " }"
    702734                       
    703735        def do_block(self, parameters, declarations, initializations, statements, icount=0):
     
    827859                stream_function = StreamFunction()
    828860                stream_function.carry_count = CarryCounter().count(node)
     861                stream_function.init_to_one_list = CarryInitToOneList().count(node)
    829862                stream_function.adv_n_count = adv_nCounter().count(node)
    830863                stream_function.type_name = node.name[0].upper() + node.name[1:]
Note: See TracChangeset for help on using the changeset viewer.