Ejemplo n.º 1
0
def TestExternalStop():

  prgm = synppc.Program()
  code = prgm.get_stream()
  prgm.add(code)
  ppc.set_active_code(code)
  
  # Data
  data = array.array('d', range(5*5))

  # Constants - read only
  n_rows = vars.SignedWord(5)
  n_cols = vars.SignedWord(5)
  addr   = vars.SignedWord(data.buffer_info()[0])  
  dbl_size  = vars.SignedWord(synppc.WORD_SIZE * 2)
  row_bytes = vars.SignedWord(synppc.WORD_SIZE * 5 * 2)

  # Variables - read/write
  sum = vars.DoubleFloat(0.0)
  x = vars.DoubleFloat(0.0)

  offset = vars.SignedWord(0)

  # Iterators
  i_iter = syn_iter(code, 0, mode = INC)
  i_iter.set_external_stop(n_rows.reg)

  j_ctr = syn_iter(code, 0, mode = CTR)
  j_ctr.set_external_stop(n_cols.reg)

  for i in i_iter:
    offset.v = vars.SignedWord.cast(i) * row_bytes
    
    # Note that j_cnt is unreadable since it's in the ctr register
    for j_cnt in j_ctr:
      # Load the next vaule in the matrix
      ppc.lfdx(x, addr, offset)
      sum.v = vars.fmadd(x, x, sum) # sum += x*x
      offset.v = offset + dbl_size

  # code.add(ppc.Illegal())
  util.return_var(sum)

  proc = synppc.Processor()
  r = proc.execute(prgm, mode = 'fp')
  # print 'Test external stop: ', r
  assert(r == 4900.0)
    
  return
Ejemplo n.º 2
0
  def load(self, addr, offset = 0):

    # If addr is a constant, create a variable and store the value
    if not issubclass(type(addr), spe.Type):
      r_storage = self.code.prgm.acquire_register()
      addr = Bits(addr, reg = r_storage)
    else:
      r_storage = None

    # If offset is a constant, use lfd, otherwise use lfdx
    if issubclass(type(offset), spe.Type):
      self.code.add(ppc.lfdx(self, addr, offset))
    else:
      # TODO: Check size of offset to ensure it fits in the immediate field 
      self.code.add(ppc.lfd(self, addr, offset))

    if r_storage is not None:
      self.code.prgm.release_register(r_storage)

    return