Ejemplo n.º 1
0
def TestRelativeAddressing():
  import corepy.arch.cal.platform as env
  import corepy.arch.cal.isa as cal
  
  proc = env.Processor(0)
  
  input_mem = proc.alloc_remote('I', 4, 16, 1)
  output_mem = proc.alloc_remote('I', 4, 1, 1)
  
  for i in range(16*1*4):
    for j in range(4):
      input_mem[i*4 + j] = i

  prgm = env.Program()  
  code = prgm.get_stream()
  cal.set_active_code(code)
    
  cal.dcl_output(o0, USAGE=cal.usage.generic)
  cal.dcl_literal(l0, 1, 1, 1, 1)
  cal.dcl_literal(l1, 16, 16, 16, 16)
  cal.mov(r0, r0('0000'))
  cal.mov(r1, r1('0000'))
  

  cal.whileloop()
  cal.iadd(r1, r1, g[r0.x])
  cal.iadd(r0, r0, l0)
  cal.breakc(cal.relop.ge, r0, l1)
  cal.endloop()

  cal.mov(o0, r1)
  
  prgm.set_binding('g[]', input_mem)
  prgm.set_binding('o0', output_mem)

  prgm.add(code)
  domain = (0, 0, 128, 128)

  prgm.print_code()
  proc.execute(prgm, domain)
  
  # code.cache_code()
  # print code.render_string
 
  if output_mem[0] == 120:
    print "Passed relative addressing test"
  else:
    print "Failed relative addressing test"

  proc.free(input_mem)
  proc.free(output_mem)
Ejemplo n.º 2
0
def TestRelativeAddressing():
    import corepy.arch.cal.platform as env
    import corepy.arch.cal.isa as cal

    proc = env.Processor(0)

    input_mem = proc.alloc_remote('I', 4, 16, 1)
    output_mem = proc.alloc_remote('I', 4, 1, 1)

    for i in range(16 * 1 * 4):
        for j in range(4):
            input_mem[i * 4 + j] = i

    prgm = env.Program()
    code = prgm.get_stream()
    cal.set_active_code(code)

    cal.dcl_output(o0, USAGE=cal.usage.generic)
    cal.dcl_literal(l0, 1, 1, 1, 1)
    cal.dcl_literal(l1, 16, 16, 16, 16)
    cal.mov(r0, r0('0000'))
    cal.mov(r1, r1('0000'))

    cal.whileloop()
    cal.iadd(r1, r1, g[r0.x])
    cal.iadd(r0, r0, l0)
    cal.breakc(cal.relop.ge, r0, l1)
    cal.endloop()

    cal.mov(o0, r1)

    prgm.set_binding('g[]', input_mem)
    prgm.set_binding('o0', output_mem)

    prgm.add(code)
    domain = (0, 0, 128, 128)

    prgm.print_code()
    proc.execute(prgm, domain)

    # code.cache_code()
    # print code.render_string

    if output_mem[0] == 120:
        print "Passed relative addressing test"
    else:
        print "Failed relative addressing test"

    proc.free(input_mem)
    proc.free(output_mem)
Ejemplo n.º 3
0
 def acquire_register(self, type = None, reg = None):
   if isinstance(type, (list, tuple)):
     # if this is a LiteralRegister, acquire and set the value
     l = spe.InstructionStream.acquire_register(self, type='l', reg=reg)
     self.add(isa.dcl_literal(l, type[0], type[1], type[2], type[3]))
     return l
   else:
     return spe.InstructionStream.acquire_register(self, type=type, reg=reg)
Ejemplo n.º 4
0
 def acquire_register(self, reg_type = None, reg_name = None):
   if isinstance(reg_type, (list, tuple)):
     # if this is a LiteralRegister, acquire and set the value
     l = spe.Program.acquire_register(self, reg_type='l', reg_name=reg_name)
     self._literals.append(isa.dcl_literal(l, reg_type[0], reg_type[1], reg_type[2], reg_type[3], ignore_active = True))
     return l
   else:
     return spe.Program.acquire_register(self,
         reg_type = reg_type, reg_name = reg_name)
Ejemplo n.º 5
0
 def acquire_register(self, type=None, reg=None):
     if isinstance(type, (list, tuple)):
         # if this is a LiteralRegister, acquire and set the value
         l = spe.InstructionStream.acquire_register(self, type='l', reg=reg)
         self.add(isa.dcl_literal(l, type[0], type[1], type[2], type[3]))
         return l
     else:
         return spe.InstructionStream.acquire_register(self,
                                                       type=type,
                                                       reg=reg)