def end(self, branch = True): if self.mode == CTR and branch: self.code.add(ppc.bdnz(self.start_label)) elif self.mode == DEC: # branch if r_count is not zero (CR) # Note that this relies on someone (e.g. cleanup()) setting the # condition register properly. if branch: self.code.add(ppc.bgt(self.start_label)) # Reset the counter in case this is a nested loop util.load_word(self.code, self.r_count, self.get_count()) elif self.mode == INC: # branch if r_current < r_stop if branch: self.code.add(ppc.cmpw(0, self.r_count, self.r_stop)) #self.code.add(ppc.cmp_(0, 2, self.r_count, self.r_stop)) self.code.add(ppc.blt(self.start_label)) # Reset the the current value in case this is a nested loop util.load_word(self.code, self.r_count, self.get_start()) if self.r_count is not None: self.code.prgm.release_register(self.r_count) self.r_count = None if self.r_stop is not None and not self.external_stop: self.code.prgm.release_register(self.r_stop) self.r_count = None return
def TestFloat(): code = InstructionStream() proc = Processor() a = array.array("d", [3.14]) load_word(code, gp_return, a.buffer_info()[0]) code.add(ppc.lfd(code.fp_return, code.gp_return, 0)) r = proc.execute(code, mode="fp", debug=True) assert r == 3.14 print "float result:", r return
def TestFloat(): code = InstructionStream() proc = Processor() a = array.array('d', [3.14]) load_word(code, gp_return, a.buffer_info()[0]) code.add(ppc.lfd(code.fp_return, code.gp_return, 0)) r = proc.execute(code, mode='fp', debug=True) assert (r == 3.14) print 'float result:', r return
def _set_literal_value(self, value): # Put the lower 16 bits into r-temp #self.code.add(ppc.addi(self.reg, 0, value & 0xFFFF)) # Addis r-temp with the upper 16 bits (shifted add immediate) and # put the result in r-target #if (value & 0x7FFF) != value: # self.code.add(ppc.addis(self.reg, self.reg, ((value + 32768) >> 16))) util.load_word(self.code, self.reg, value) return
def TestFloat(): prgm = Program() code = prgm.get_stream() prgm += code proc = Processor() a = array.array('d', [3.14]) load_word(code, prgm.gp_return, a.buffer_info()[0]) code.add(ppc.lfd(prgm.fp_return, prgm.gp_return, 0)) r = proc.execute(prgm, mode='fp') assert (r == 3.14) print 'float result:', r return
def TestFloat(): prgm = Program() code = prgm.get_stream() prgm += code proc = Processor() a = array.array('d', [3.14]) load_word(code, prgm.gp_return, a.buffer_info()[0]) code.add(ppc.lfd(prgm.fp_return, prgm.gp_return, 0)) r = proc.execute(prgm, mode='fp') assert(r == 3.14) print 'float result:', r return
def TestCodedCall(): code = InstructionStream() proc = Processor() a = array.array("d", [3.14]) load_word(code, code.gp_return, a.buffer_info()[0]) ppc.set_active_code(code) ppc.lfd(code.fp_return, code.gp_return, 0) code.print_code() r = proc.execute(code, mode="fp", debug=True) assert r == 3.14 print "float result:", r return
def TestCodedCall(): code = InstructionStream() proc = Processor() a = array.array('d', [3.14]) load_word(code, code.gp_return, a.buffer_info()[0]) ppc.set_active_code(code) ppc.lfd(code.fp_return, code.gp_return, 0) code.print_code() r = proc.execute(code, mode='fp', debug=True) assert (r == 3.14) print 'float result:', r return
def _update_inc_count(self): code = self.obj.code r_block_size = code.prgm.acquire_register() r_offset = code.prgm.acquire_register() # Determine the block size for each loop util.load_word(code, r_block_size, self.get_count() - self.get_start()) code.add(ppc.divw(r_block_size, r_block_size, code.r_size)) # Determine the offset for the current block and update the r_count # (this is primarily for range, which uses different values in r_count # to initialize ranges that don't start at 0) code.add(ppc.mullw(r_offset, code.r_rank, r_block_size)) code.add(ppc.add(self.obj.r_count, self.obj.r_count, r_offset)) if self.obj.r_stop is not None: code.add(ppc.add(self.obj.r_stop, self.obj.r_count, r_block_size)) code.prgm.release_register(r_offset) code.prgm.release_register(r_block_size) return
def start(self, align=True, branch=True): if self.r_count is None: self.r_count = self.code.acquire_register() if self.mode == CTR and branch: if self.step_size() != 1: raise Exception( 'CTR loops must have step_size of 1, you used ' + str(self.step_size())) if self.external_stop: self.code.add(ppc.mtctr(self.r_stop)) else: util.load_word(self.code, self.r_count, self.n_steps()) self.code.add(ppc.mtctr(self.r_count)) self.code.release_register(self.r_count) self.r_count = None elif self.mode == DEC: util.load_word(self.code, self.r_count, self.get_count()) elif self.mode == INC: if self.r_stop is None and branch: self.r_stop = self.code.acquire_register() util.load_word(self.code, self.r_count, self.get_start()) if branch and not self.external_stop: util.load_word(self.code, self.r_stop, self.get_count()) # /end mode if if self.r_count is not None: # self.current_count = metavar.int_var(self.code, reg = self.r_count) self.current_count = vars.UnsignedWord(reg=self.r_count) if align and branch: # Align the start of the loop on a 16 byte boundary while (self.code.size()) % 4 != 0: self.code.add(ppc.noop()) # Label self.start_label = self.code.size() + 1 return
def start(self, align = True, branch = True): if self.r_count is None: self.r_count = self.code.prgm.acquire_register() if self.mode == CTR and branch: if self.step_size() != 1: raise Exception('CTR loops must have step_size of 1, you used ' + str(self.step_size())) if self.external_stop: self.code.add(ppc.mtctr(self.r_stop)) else: util.load_word(self.code, self.r_count, self.n_steps()) self.code.add(ppc.mtctr(self.r_count)) self.code.prgm.release_register(self.r_count) self.r_count = None elif self.mode == DEC: util.load_word(self.code, self.r_count, self.get_count()) elif self.mode == INC: if self.r_stop is None and branch: self.r_stop = self.code.prgm.acquire_register() util.load_word(self.code, self.r_count, self.get_start()) if branch and not self.external_stop: util.load_word(self.code, self.r_stop, self.get_count()) # /end mode if if self.r_count is not None: self.current_count = vars.UnsignedWord(code = self.code, reg = self.r_count) if align and branch: # Align the start of the loop on a 16 byte boundary while (self.code.size()) % 4 != 0: self.code.add(ppc.noop()) # Label self.start_label = self.code.prgm.get_unique_label("SYN_ITER_START") self.code.add(self.start_label) return
def TestLiterals(): import corepy.arch.ppc.platform as env prgm = env.Program() code = prgm.get_stream() prgm += code proc = env.Processor() ppc.set_active_code(code) vmx.set_active_code(code) zero = Bits.cast(SignedByte(0)) target = Bits() # Signed versions use splat, unsigned arrays b = Byte(2) sb = SignedByte(-2) vmx.vaddsbs(b, b, sb) h = Halfword(9999) sh = SignedHalfword(-9999) vmx.vaddshs(h, h, sh) w = Word(99999) sw = SignedWord(-99999) vmx.vaddsws(w, w, sw) # Combine the results (should be [0,0,0,0]) vmx.vor(target, b, h) vmx.vor(target, target, w) # Array initializers b = Byte(range(16)) sb = SignedByte(range(16)) vmx.vsubsbs(b, b, sb) vmx.vor(target, target, b) h = Halfword([9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992]) sh = SignedHalfword([9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992]) vmx.vsubshs(h, h, sh) vmx.vor(target, target, h) w = Word([99999, 99998, 99997, 99996]) sw = SignedWord([99999, 99998, 99997, 99996]) vmx.vsubsws(w, w, sw) target.v = vmx.vor.ex(target, w) result = extarray.extarray('I', [42, 42, 42, 42]) r_addr = prgm.acquire_register() util.load_word(code, r_addr, result.buffer_info()[0]) vmx.stvx(target, 0, r_addr) ppc.set_active_code(None) vmx.set_active_code(None) r = proc.execute(prgm) print result for i in result: assert (i == 0) # for i in result: print '%08X' % i, # print return
def TestLiterals(): import corepy.arch.ppc.platform as env prgm = env.Program() code = prgm.get_stream() prgm += code proc = env.Processor() ppc.set_active_code(code) vmx.set_active_code(code) zero = Bits.cast(SignedByte(0)) target = Bits() # Signed versions use splat, unsigned arrays b = Byte(2) sb = SignedByte(-2) vmx.vaddsbs(b, b, sb) h = Halfword(9999) sh = SignedHalfword(-9999) vmx.vaddshs(h, h, sh) w = Word(99999) sw = SignedWord(-99999) vmx.vaddsws(w, w, sw) # Combine the results (should be [0,0,0,0]) vmx.vor(target, b, h) vmx.vor(target, target, w) # Array initializers b = Byte(range(16)) sb = SignedByte(range(16)) vmx.vsubsbs(b, b, sb) vmx.vor(target, target, b) h = Halfword([9999,9998,9997,9996,9995,9994,9993,9992]) sh = SignedHalfword([9999,9998,9997,9996,9995,9994,9993,9992]) vmx.vsubshs(h, h, sh) vmx.vor(target, target, h) w = Word([99999,99998,99997,99996]) sw = SignedWord([99999,99998,99997,99996]) vmx.vsubsws(w, w, sw) target.v = vmx.vor.ex(target, w) result = extarray.extarray('I', [42,42,42,42]) r_addr = prgm.acquire_register() util.load_word(code, r_addr, result.buffer_info()[0]) vmx.stvx(target, 0, r_addr) ppc.set_active_code(None) vmx.set_active_code(None) r = proc.execute(prgm) print result for i in result: assert(i == 0) # for i in result: print '%08X' % i, # print return
ppc.addi(prgm.gp_return, 0, 12) ppc.b(prgm.lbl_epilogue) prgm.add(code) prgm.print_code(pro=True, epi=True, binary=True) r = proc.execute(prgm, debug=True) print 'int result:', r assert(r == 12) code.reset() a = array.array('d', [3.14]) load_word(code, prgm.gp_return, a.buffer_info()[0]) ppc.lfd(prgm.fp_return, prgm.gp_return, 0) r = proc.execute(prgm, mode='fp', debug=True) assert(r == 3.14) print 'float result:', r code.reset() load_word(code, prgm.gp_return, 0xFFFFFFFF) r = proc.execute(prgm, mode='int', debug=True) print "int result:",r assert(r == -1)
ppc.addi(code.gp_return, 0, 12) ppc.b(code.lbl_epilogue) code.cache_code() code.print_code(pro=True, epi=True, binary=True) r = proc.execute(code, debug=True) print 'int result:', r assert (r == 12) code.reset() a = array.array('d', [3.14]) load_word(code, code.gp_return, a.buffer_info()[0]) ppc.lfd(code.fp_return, code.gp_return, 0) r = proc.execute(code, mode='fp', debug=True) assert (r == 3.14) print 'float result:', r code.reset() load_word(code, code.gp_return, 0xFFFFFFFF) r = proc.execute(code, mode='int', debug=True) print "int result:", r assert (r == -1) code.reset()
def init_address(self): if self.addr_reg is None: return util.load_word(self.code, self.r_addr, _array_address(self.data))