예제 #1
0
def fdiv(code, d, x, y, one = None):
  """
  Single-precision floating point division for x / y
  """
  Y = code.acquire_registers(3)
  t = code.acquire_register()
  regs = Y[:]
  regs.append(t)
  
  if one is None:
    one = code.acquire_register()
    spu.xor(one, one, one)
    spu.ai(one, one, 1)
    spu.cuflt(one, one, 155)
    regs.append(one)
    
  # Compute 1/y (from SPU ISA 1.1, p208, Normal case)
  spu.frest(Y[0], y)
  spu.fi(Y[1], y, Y[0])
  spu.fnms(t, y, Y[1], one)
  spu.fma(Y[2], t, Y[1], Y[1])

  # Compute x * (1/y)
  spu.fm(d, x, Y[2])
  
  code.release_registers(regs)
    
  return
예제 #2
0
파일: div_test.py 프로젝트: tmaone/efi
ione = 110
fone = 111

insts = [
    # Create fone = 1.0, fa = 2.0 and fb = 4.0
    spu.ai(ione, 0, 1),
    spu.ai(ia, 0, 2),
    spu.ai(ib, 0, 4),
    spu.cuflt(fone, ione, 155),
    spu.cuflt(fa, ia, 155),
    spu.cuflt(fb, ib, 155),

    # Compute 1/fb
    spu.frest(y0, fb),
    spu.fi(y1, fb, y0),
    spu.fnms(t1, fb, y1, fone),
    spu.fma(y2, t1, y1, y1),
    spu.fm(result, fa, y2)
]

for inst in insts:
    cli.execute(inst)

regs = cli.get_regs()

for reg in (ione, fone, ia, ib, fa, fb, y0, y1, y2, t1, result):
    print reg, '0x%08X 0x%08X 0x%08X 0x%08X' % regs[reg]

cli.stop()
예제 #3
0
ione = 110
fone = 111

insts = [
  # Create fone = 1.0, fa = 2.0 and fb = 4.0
  spu.ai(ione, 0, 1),  
  spu.ai(ia, 0, 2),
  spu.ai(ib, 0, 4),
  spu.cuflt(fone, ione, 155),  
  spu.cuflt(fa, ia, 155),
  spu.cuflt(fb, ib, 155),

  # Compute 1/fb
  spu.frest(y0, fb),
  spu.fi(y1, fb, y0),
  spu.fnms(t1, fb, y1, fone),
  spu.fma(y2, t1, y1, y1),

  spu.fm(result, fa, y2)
  ]

for inst in insts:
  cli.execute(inst)

regs = cli.get_regs()

for reg in (ione, fone, ia, ib, fa, fb, y0, y1, y2, t1, result):
  print reg, '0x%08X 0x%08X 0x%08X 0x%08X' % regs[reg]

cli.stop()