Exemplo n.º 1
0
    def synthesize(self, code):
        """
    Render a vector with 4 pixels.
    """
        old_code = spu.get_active_code()
        spu.set_active_code(code)

        if self.x_offset is None: raise Exception('Please call setup')
        if self.result is None: raise Exception('Please set result')
        if self.one is None: raise Exception('Please set one')

        # Make the part of the result positive and subtract 1
        # to transform (-1,-oo) into (0,oo)
        self.result.v = spu.fs.ex(0, self.result)
        self.result.v = spu.fs.ex(self.result, self.one)

        # Convert the result to an unsigned int, scaling by 2^4 to put
        # values between 0 and 16 in the gradient.  Values outside [0,16]
        # are 0 or FF
        self.result.v = spu.cfltu.ex(self.result, 169)  # 173 - 169 == 4
        # self.result.v = spu.sfi.ex(self.result, 255) # 173 - 169 == 4

        # Extract the first two bytes from the result into the RGB positions
        # and set alpha to 0xFF
        self.result.v = spu.shufb.ex(self.result, self.ff, self.uint2rgba)

        # Save the result and increment the offset
        spu.stqd(self.result, self.x_offset, self.lsa >> 4)
        spu.ai(self.x_offset, self.x_offset, 16)

        spu.set_active_code(old_code)
        return
Exemplo n.º 2
0
  def synthesize(self, code):
    """
    Render a vector with 4 pixels.
    """
    old_code = spu.get_active_code()
    spu.set_active_code(code)

    if self.x_offset is None: raise Exception('Please call setup')
    if self.result is None: raise Exception('Please set result')
    if self.one is None: raise Exception('Please set one')

    # Make the part of the result positive and subtract 1
    # to transform (-1,-oo) into (0,oo)
    self.result.v = spu.fs.ex(0, self.result)
    self.result.v = spu.fs.ex(self.result, self.one)

    # Convert the result to an unsigned int, scaling by 2^4 to put 
    # values between 0 and 16 in the gradient.  Values outside [0,16] 
    # are 0 or FF
    self.result.v = spu.cfltu.ex(self.result, 169) # 173 - 169 == 4
    # self.result.v = spu.sfi.ex(self.result, 255) # 173 - 169 == 4

    # Extract the first two bytes from the result into the RGB positions
    # and set alpha to 0xFF
    self.result.v = spu.shufb.ex(self.result, self.ff, self.uint2rgba)

    # Save the result and increment the offset
    spu.stqd(self.result, self.x_offset, self.lsa >> 4)
    spu.ai(self.x_offset, self.x_offset, 16)

    spu.set_active_code(old_code)
    return
Exemplo n.º 3
0
    # The PPU will collect all the PS map addresses into an array for the SPUs.
    r_psinfo_mma = dma.spu_read_signal1(code)

    # DMA the PS info into local store
    dma.mem_get(code, 0x0, r_psinfo_mma, SPUS * 4 * 4, 17)
    dma.mem_complete(code, 17)

    # Load the PS info into some registers.. one register per address
    r_psinfo = prgm.acquire_registers(SPUS)
    for i in xrange(0, SPUS):
      spu.lqd(r_psinfo[i], code.r_zero, i)

    # Initialize a data register with this rank and store it at LSA 0
    r_send = prgm.acquire_register()
    load_word(code, r_send, rank)
    spu.stqd(r_send, code.r_zero, 0)
    prgm.release_register(r_send)

    # Send our rank as a mailbox message to the rank after this rank
    dma.mem_write_in_mbox(code, r_psinfo[(rank + 1) % SPUS], 12, 18)
    dma.mem_complete(code, 18)

    # Receive the message the preceding rank sent
    r_recv = dma.spu_read_in_mbox(code)

    # Write the value out the interrupt mailbox for the PPU
    dma.spu_write_out_intr_mbox(code, r_recv)
    code.prgm.release_register(r_recv)

    prgm.add(code)
Exemplo n.º 4
0
        self.ls_frame.Update()
        self.mem_frame.Update()
        return


if __name__ == '__main__':
    prgm = env.Program()
    code = prgm.get_stream()
    reg = prgm.acquire_register()
    foo = prgm.acquire_register(reg_name=5)

    code.add(prgm.get_label("FOO"))
    code.add(spu.il(foo, 0xCAFE))
    code.add(spu.ilhu(reg, 0xDEAD))
    code.add(spu.iohl(reg, 0xBEEF))
    code.add(spu.stqd(reg, code.r_zero, 4))

    lbl_loop = prgm.get_label("LOOP")
    lbl_break = prgm.get_label("BREAK")

    r_cnt = code.gp_return
    r_stop = prgm.acquire_register(reg_name=9)
    r_cmp = prgm.acquire_register()

    code.add(spu.ori(r_cnt, code.r_zero, 0))
    code.add(spu.il(r_stop, 5))

    code.add(lbl_loop)
    code.add(spu.ceq(r_cmp, r_cnt, r_stop))
    code.add(spu.brnz(r_cmp, prgm.get_label("BREAK")))
    code.add(spu.ai(r_cnt, r_cnt, 1))
Exemplo n.º 5
0
    self.ls_frame.Update()
    self.mem_frame.Update()
    return


if __name__=='__main__':
  prgm = env.Program()
  code = prgm.get_stream()
  reg = prgm.acquire_register()
  foo = prgm.acquire_register(reg_name = 5)

  code.add(prgm.get_label("FOO"))
  code.add(spu.il(foo, 0xCAFE))
  code.add(spu.ilhu(reg, 0xDEAD))
  code.add(spu.iohl(reg, 0xBEEF))
  code.add(spu.stqd(reg, code.r_zero, 4))

  lbl_loop = prgm.get_label("LOOP")
  lbl_break = prgm.get_label("BREAK")

  r_cnt = code.gp_return
  r_stop = prgm.acquire_register(reg_name = 9)
  r_cmp = prgm.acquire_register()

  code.add(spu.ori(r_cnt, code.r_zero, 0))
  code.add(spu.il(r_stop, 5))

  code.add(lbl_loop)
  code.add(spu.ceq(r_cmp, r_cnt, r_stop))
  code.add(spu.brnz(r_cmp, prgm.get_label("BREAK")))
  code.add(spu.ai(r_cnt, r_cnt, 1))