Changeset 2891


Ignore:
Timestamp:
Feb 3, 2013, 2:16:55 PM (6 years ago)
Author:
cameron
Message:

Lookahead support: add extra stream_function parameters as needed; final-block optimization

Location:
proto/Compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/lookAhead.py

    r2885 r2891  
    3737          raise LookAheadError('2nd argument to lookahead, if present, must be a numeric constant')
    3838        peek_amount = callnode.args[1].n
    39       elif len(callnode.args) == 2:
     39      elif len(callnode.args) == 1:
    4040        peek_amount = 1
    4141      else: raise LookAheadError('lookahead needs 1 or 2 args')
     
    4949
    5050class LookAheadTransformer (ast.NodeTransformer):
     51  def __init__(self, streamFunctionNode, mode="nonfinal"):
     52    self.LookAheadSet = streamFunctionNode.lookahead_info.LookAheadSet
     53    self.block_mode = mode
     54
    5155  def xfrm(self, t):
    5256    return self.generic_visit(t)
     
    5862    else:
    5963        peek_amount = 1
     64    if self.block_mode == "final":
     65      return ast.Call(ast.Name('bitblock::srli<%i>' %  peek_amount, ast.Load()), callnode.args, [], None, None)
    6066    module_name = callnode.args[0].value
    6167    strm = callnode.args[0].attr
    62     b0 = ast.Attribute(ast.Subscript(module_name, ast.Index(ast.Num(0)), ast.Load()), strm, ast.Load())
    63     b1 = ast.Attribute(ast.Subscript(module_name, ast.Index(ast.Num(1)), ast.Load()), strm, ast.Load())
     68    #b0 = ast.Attribute(ast.Subscript(module_name, ast.Index(ast.Num(0)), ast.Load()), strm, ast.Load())
     69    #b1 = ast.Attribute(ast.Subscript(module_name, ast.Index(ast.Num(1)), ast.Load()), strm, ast.Load())
     70    b0 = ast.Attribute(module_name, strm, ast.Load())
     71    b1 = ast.Attribute(ast.Name(module_name.id + "_ahead", ast.Load()), strm, ast.Load())
    6472    return ast.Call(ast.Name('pablo_blk_Lookahead_n_<%i>' %  peek_amount, ast.Load()), [b0, b1], [], None, None)
    6573
  • proto/Compiler/pablo.py

    r2885 r2891  
    745745
    746746class Emitter():
    747         def __init__(self, use_C_syntax, ccgo):
     747        def __init__(self, use_C_syntax, strm_fn):
    748748                self.use_C_syntax = use_C_syntax
    749                 self.ccgo = ccgo
     749                self.strm_fn = strm_fn
    750750
    751751        def definition(self, stream_function, icount=0):
     
    789789
    790790        def constructor(self, type_name, carry_count, init_to_one_list, adv_n_count, icount=0):
    791                 one_inits = self.ccgo.GenerateInitializations()
     791                one_inits = self.strm_fn.ccgo.GenerateInitializations()
    792792                #one_inits = ""
    793793                #for v in init_to_one_list:
     
    855855                #       adv_n_decl = "\n" + self.indent(icount) + "BitBlock pending64[%s];" % adv_n_count
    856856                #CARRY SET
    857                 return self.indent(icount) + self.ccgo.GenerateCarryDecls()
     857                return self.indent(icount) + self.strm_fn.ccgo.GenerateCarryDecls()
    858858
    859859        def carry_test(self, carry_variable, carry_count, icount=0):
     
    870870                        #return ", ".join([self.type_name + " * " + self.instance_name] + [upper1(p) + " * " + lower1(p) for p in parameters])
    871871                        return ", ".join([lower1(self.type_name)] + [lower1(p) for p in parameters])
    872                 else: return ", ".join([upper1(p) + " & " + lower1(p) for p in parameters])
     872                else:
     873                  normal_parms = [upper1(p) + " & " + lower1(p) for p in parameters]
     874                  lookahead_parms = [upper1(p) + " & " + lower1(p) + "_ahead" for p in parameters if self.strm_fn.lookahead_info.LookAheadSet.has_key(p)]
     875                  return ", ".join(normal_parms + lookahead_parms)
    873876               
    874877        def do_final_block_parameters(self, parameters):
     
    930933                carry_info_set = CarryInfoSetVisitor(node)
    931934                # Lookahead info is unused, but the visitor is called to verify some conditions
    932                 lookahead_info = lookAhead.LookAheadInfoSetVisitor(node)
     935                stream_function.lookahead_info = lookAhead.LookAheadInfoSetVisitor(node)
    933936                stream_function.ccgo = Strategic_CCGO_Factory(carry_info_set)
    934937                stream_function.type_name = node.name[0].upper() + node.name[1:]
     
    948951                AugAssignRemoval().xfrm(node)
    949952
    950                 lookAhead.LookAheadTransformer().xfrm(node)
    951 
    952953                Bitwise_to_SIMD().xfrm(node)
    953954                final_block_node = copy.deepcopy(node)
     955
    954956                if self.use_C_syntax:
    955957                        carryQname = stream_function.instance_name + ".carryQ"
    956958                else: carryQname = "carryQ"
    957959                CarryIntroVisitor = CarryIntro(stream_function.ccgo, carryQname)
     960
     961                lookAhead.LookAheadTransformer(stream_function, "nonfinal").xfrm(node)
     962                lookAhead.LookAheadTransformer(stream_function, "final").xfrm(final_block_node)
     963
    958964                CarryIntroVisitor.xfrm_fndef(node)
    959965                CarryIntroVisitor.xfrm_fndef_final(final_block_node)
     
    982988        sys.exit()
    983989               
    984     self.emitter = Emitter(self.use_C_syntax, stream_function.ccgo)
     990    self.emitter = Emitter(self.use_C_syntax, stream_function)
    985991   
    986992  def any_carry_expr(self):
     
    993999    for key in self.stream_functions.keys():
    9941000                sf = self.stream_functions[key]
    995                 self.Cglobals += Emitter(self.use_C_syntax, sf.ccgo).definition(sf, 2)     
     1001                self.Cglobals += Emitter(self.use_C_syntax, sf).definition(sf, 2)         
    9961002                       
    9971003  def gen_declarations(self): 
Note: See TracChangeset for help on using the changeset viewer.