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
c.v = a + (b & byte_mask) ppc.set_active_code(None) r = proc.execute(prgm) assert(r == 42) code.print_code() # ------------------------------------------------------------ # VMX # ------------------------------------------------------------ code.reset() ppc.set_active_code(code) vmx.set_active_code(code) v_x = prgm.acquire_register('vector') result = array.array('I', [0,0,0,0,0,0]) r_addr = prgm.acquire_register() # Minor hack to align the address to a 16-byte boundary. # Note that enough space was allocated in the array to # ensure the save location is valid. # (we are working on a cleaner memory management interface # for CorePy that will fix these annoying alignment issues) addr = result.buffer_info()[0] if addr % 16 != 0: addr += 16 - (addr % 16) print 'aligning addr'
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
c.v = a + (b & byte_mask) ppc.set_active_code(None) r = proc.execute(code) assert (r == 42) code.print_code() # ------------------------------------------------------------ # VMX # ------------------------------------------------------------ code.reset() ppc.set_active_code(code) vmx.set_active_code(code) v_x = code.acquire_register('vector') result = array.array('I', [0, 0, 0, 0, 0, 0]) r_addr = code.acquire_register() # Minor hack to align the address to a 16-byte boundary. # Note that enough space was allocated in the array to # ensure the save location is valid. # (we are working on a cleaner memory management interface # for CorePy that will fix these annoying alignment issues) addr = result.buffer_info()[0] if addr % 16 != 0: addr += 16 - (addr % 16) print 'aligning addr'