def _set_literal_value(self, value): if type(value) is _array_type: if value.typecode not in self.array_typecodes: raise Exception("Array typecode '%s' is not supported" % (value.typecode, )) if len(value) < INT_ARRAY_SIZES[self.array_typecode]: print 'Warning: Variable array initializer has fewer elements than the corresponding vector: %d < %d' % ( len(value), INT_ARRAY_SIZES[self.array_typecode]) util.load_vector(self.code, self.reg, value.buffer_info()[0]) self.storage = value elif type(value) in (list, tuple): if len(value) < INT_ARRAY_SIZES[self.array_typecode]: print 'Warning: Variable %s initializer has fewer elements than the corresponding vector: %d < %d' % ( type(value), len(value), INT_ARRAY_SIZES[self.array_typecode]) storage = extarray.extarray(self.array_typecode, value) util.load_vector(self.code, self.reg, storage.buffer_info()[0]) self.storage = storage elif type(value) in self.literal_types: if (value & 0x1F) == value and isinstance( self, (SignedByteType, SignedHalfwordType, SignedWordType)): # Use the splat instructions if isinstance(self, SignedByteType): self.code.add(vmx.vspltisb(self.reg, value)) elif isinstance(self, SignedHalfwordType): self.code.add(vmx.vspltish(self.reg, value)) elif isinstance(self, SignedWordType): self.code.add(vmx.vspltisw(self.reg, value)) else: raise Exception( 'Unsupported typecode for vector literal splat: ' + str(type(self))) else: splat = [ self.value for i in xrange(INT_ARRAY_SIZES[self.array_typecode]) ] vsplat = extarray.extarray(self.array_typecode, splat) util.load_vector(self.code, self.reg, vsplat.buffer_info()[0]) self.code.prgm.add_storage(vsplat) self.storage = vsplat self.value = value if self.storage is not None: self.code.prgm.add_storage(self.storage) return
def _set_literal_value(self, value): if type(value) is _array_type: if value.typecode not in self.array_typecodes: raise Exception("Array typecode '%s' is not supported" % (value.typecode,)) if len(value) < INT_ARRAY_SIZES[self.array_typecode]: print 'Warning: Variable array initializer has fewer elements than the corresponding vector: %d < %d' % ( len(value), INT_ARRAY_SIZES[self.array_typecode]) util.load_vector(self.code, self.reg, value.buffer_info()[0]) self.storage = value elif type(value) in (list, tuple): if len(value) < INT_ARRAY_SIZES[self.array_typecode]: print 'Warning: Variable %s initializer has fewer elements than the corresponding vector: %d < %d' % ( type(value), len(value), INT_ARRAY_SIZES[self.array_typecode]) storage = extarray.extarray(self.array_typecode, value) util.load_vector(self.code, self.reg, storage.buffer_info()[0]) self.storage = storage elif type(value) in self.literal_types: if (value & 0x1F) == value and isinstance(self, (SignedByteType, SignedHalfwordType, SignedWordType)): # Use the splat instructions if isinstance(self, SignedByteType): self.code.add(vmx.vspltisb(self.reg, value)) elif isinstance(self, SignedHalfwordType): self.code.add(vmx.vspltish(self.reg, value)) elif isinstance(self, SignedWordType): self.code.add(vmx.vspltisw(self.reg, value)) else: raise Exception('Unsupported typecode for vector literal splat: ' + str(type(self))) else: splat = [self.value for i in xrange(INT_ARRAY_SIZES[self.array_typecode])] vsplat = extarray.extarray(self.array_typecode, splat) util.load_vector(self.code, self.reg, vsplat.buffer_info()[0]) self.code.prgm.add_storage(vsplat) self.storage = vsplat self.value = value if self.storage is not None: self.code.prgm.add_storage(self.storage) return
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' load_word(code, r_addr, addr) vmx.vspltisw(v_x, 4) vmx.stvx(v_x, 0, r_addr) ppc.set_active_code(None) vmx.set_active_code(None) r = proc.execute(prgm) # , debug = True) # code.print_code(pro = True, epi = True) print result
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' load_word(code, r_addr, addr) vmx.vspltisw(v_x, 4) vmx.stvx(v_x, 0, r_addr) ppc.set_active_code(None) vmx.set_active_code(None) r = proc.execute(code) # , debug = True) # code.print_code(pro = True, epi = True) print result