import os.path import struct import numpy as np def normalize(a): return(a/np.max(np.abs(a))) TAILONLY = 1 BODYONLY = 2 BODYANDTAIL = 3 # Datatype formats F64 = 64 F32 = 0 F16 = 16 Q63 = 63 Q31 = 31 Q15 = 15 Q7 = 7 def loopnb(format,loopkind): nb = 0 if loopkind == TAILONLY: if format == 64 or format == Q63: nb = 2 if format == 0 or format == 31: nb = 3 if format == 15 or format == 16: nb = 7 if format == 7: nb = 15 if loopkind == BODYONLY: if format == 64 or format == Q63: nb = 4 if format == 0 or format == 31: nb = 8 if format == 15 or format == 16: nb = 16 if format == 7: nb = 32 if loopkind == BODYANDTAIL: if format == 64 or format == Q63: nb = 5 if format == 0 or format == 31: nb = 11 # 9 if format == 15 or format == 16: nb = 23 # 17 if format == 7: nb = 47 # 33 return(nb) # Tools to generate pattern files def createMissingDir(destPath): theDir=os.path.normpath(destPath) if not os.path.exists(theDir): os.makedirs(theDir) # Pack an array of boolean into uint32 def packset(a): b = np.packbits(a) newSize = int(np.ceil(b.shape[0] / 4.0)) * 4 c = np.copy(b) c.resize(newSize) #print(c) vecSize = round(newSize/4) c=c.reshape(vecSize,4) #print(c) r = np.zeros(vecSize) result = [] for i in range(0,vecSize): #print(c[i,:]) #print("%X %X %X %X" % (c[i,0],c[i,1],c[i,2],c[i,3])) d = (c[i,0] << 24) | (c[i,1] << 16) | (c[i,2] << 8) | c[i,3] result.append(np.uint32(d)) return(result) def float_to_hex(f): """ Convert and x86 float to an ARM unsigned long int. Args: f (float): value to be converted Raises: Nothing Returns: str : representation of the hex value """ return hex(struct.unpack(' 0x07FFFFFFFFFFFFFFF): r = 0x07FFFFFFFFFFFFFFF if (r < -0x08000000000000000): r = -0x08000000000000000 return ("0x%s" % format(struct.unpack(' 0x07FFFFFFF): r = 0x07FFFFFFF if (r < -0x080000000): r = -0x080000000 return ("0x%s" % format(struct.unpack(' 0x07FFF): r = 0x07FFF if (r < -0x08000): r = -0x08000 return ("0x%s" % format(struct.unpack(' 0x07F): r = 0x07F if (r < -0x080): r = -0x080 return ("0x%s" % format(struct.unpack('