Exemple #1
0
def TestFloats():
    import math

    code = synspu.InstructionStream()
    proc = synspu.Processor()

    spu.set_active_code(code)

    code.set_debug(True)

    # Create a simple SPU program that computes log for all values bettween
    # .01 and 10.0 with .01 increments

    start = .65
    stop = .75
    inc = .01

    sp_step = 0x3C23D70A
    # r_current = var.Word(0x3C23D70A) # .01 in single precision
    r_current = var.Word(0x3F266666)
    r_step = var.Word(sp_step)  # .01 in single precision
    result = var.Word(0)
    log = SPULog()

    log.setup(code)
    log.set_result(result)
    log.set_x(r_current)

    log_iter = syn_iter(code, int((stop - start) / inc))

    for i in log_iter:

        log.synthesize(code)
        spu.fa(r_current, r_current, r_step)
        spu.wrch(result, dma.SPU_WrOutMbox)

    # code.print_code()
    spe_id = proc.execute(code, mode='async')

    x = start
    for i in range(int((stop - start) / inc)):
        while synspu.spu_exec.stat_out_mbox(spe_id) == 0:
            pass
        slog = synspu.spu_exec.read_out_mbox(spe_id)
        print '%.3f 0x%08X  %.08f %.08f ' % (x, slog, _sp_to_float(slog),
                                             math.log(x, 2))
        x += inc

    proc.join(spe_id)

    return
Exemple #2
0
  def _compute_ratio(self, ab, c, result):

    # Convert ab and c to float
    spu.cuflt(ab, ab, 155)
    spu.cuflt(c,   c, 155)

    # Compute ab = ab + c
    spu.fa(ab, ab, c)

    # Compute c / (ab + c)

    fdiv(spu.get_active_code(), result, c, ab, self._one)
    
    return
Exemple #3
0
def TestFloats():
  import math
  
  code = synspu.InstructionStream()
  proc = synspu.Processor()

  spu.set_active_code(code)

  code.set_debug(True)
  
  # Create a simple SPU program that computes log for all values bettween
  # .01 and 10.0 with .01 increments

  start = .65
  stop  = .75
  inc   = .01

  sp_step = 0x3C23D70A
  # r_current = var.Word(0x3C23D70A) # .01 in single precision
  r_current = var.Word(0x3F266666)
  r_step  = var.Word(sp_step)    # .01 in single precision
  result  = var.Word(0)
  log = SPULog()

  log.setup(code)
  log.set_result(result)
  log.set_x(r_current)
  
  log_iter = syn_iter(code, int((stop - start) / inc))

  for i in log_iter:
    
    log.synthesize(code)
    spu.fa(r_current, r_current, r_step)
    spu.wrch(result, dma.SPU_WrOutMbox)

  # code.print_code()
  spe_id = proc.execute(code, mode = 'async')

  x = start
  for i in range(int((stop - start) / inc)):
    while synspu.spu_exec.stat_out_mbox(spe_id) == 0: pass
    slog = synspu.spu_exec.read_out_mbox(spe_id)
    print '%.3f 0x%08X  %.08f %.08f ' % (x, slog, _sp_to_float(slog), math.log(x, 2))
    x += inc

  proc.join(spe_id)

  return