def load_value_int32(code, reg, value, clear = False): # obviously, value should be 32 bit integer code.add(spu.ilhu(reg, value / pow(2, 16))) # immediate load halfword upper code.add(spu.iohl(reg, value % pow(2, 16))) # immediate or halfword lower if clear: code.add(spu.shlqbyi(reg, reg, 12)) # shift left qw by bytes, clears right bytes return
def load_word(code, r_target, word, clear=False, zero=True): """If r0 is not set to 0, the zero parameter should be set to False""" if zero and (-512 < word < 511): code.add(spu.ai(r_target, code.r_zero, word)) elif (word & 0x7FFF) == word: code.add(spu.il(r_target, word)) elif (word & 0x3FFFF) == word: code.add(spu.ila(r_target, word)) else: code.add(spu.ilhu(r_target, (word & 0xFFFF0000) >> 16)) code.add(spu.iohl(r_target, (word & 0xFFFF))) if clear: code.add(spu.shlqbyi(r_target, r_target, 12)) return
def load_word(code, r_target, word, clear = False, zero = True): """If r0 is not set to 0, the zero parameter should be set to False""" #if zero and (-512 < word < 511): # code.add(spu.ai(r_target, code.r_zero, word)) #elif (word & 0x7FFF) == word: # code.add(spu.il(r_target, word)) if (word & 0x3FFFF) == word: code.add(spu.ila(r_target, word)) else: code.add(spu.ilhu(r_target, (word & 0xFFFF0000) >> 16)) if word & 0xFFFF != 0: code.add(spu.iohl(r_target, (word & 0xFFFF))) if clear: code.add(spu.shlqbyi(r_target, r_target, 12)) return
def Update(self): self.reg_frame.Update() 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))
def Update(self): self.reg_frame.Update() 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))