예제 #1
0
 def _aggZeroesBetweenIntArrays(self):
   if len(self._fields) < 3:
     return
   self._dirty=True
   
   myfields = sorted(self._fields)
   i = 0
   while ( i < len(myfields) - 3 ):
     prev = myfields[i]
     field = myfields[i+1]
     next = myfields[i+2]
     if prev.isArray() and next.isArray() and field.isZeroes() and (
         fieldtypes.isIntegerType(prev.basicTypename) and
         fieldtypes.isIntegerType(next.basicTypename) ):
       # we have zeroes in the middle
       fieldLen = len(field)
       nbWord = fieldLen//Config.WORDSIZE 
       if (fieldLen % Config.WORDSIZE == 0) and  nbWord < 4: # more than 3 word zerroes it is probably another buffer
         # concat prev, field and next arrays to get on array
         newFields = prev.elements+[field]
         field.checkSmallInt() # force it in a small integer
         if nbWord > 1:
           for offsetadd in range(Config.WORDSIZE, Config.WORDSIZE*nbWord, Config.WORDSIZE):
             newFields.append(self._addField(field.offset+offsetadd, FieldType.SMALLINT, Config.WORDSIZE, False))
         newFields.extend(next.elements)
         # make an array for newFields and insert it in place of prev+field+next
         # pop prev, newfields and next, and put them in an array
         #print 'aggZeroes', i, len(newFields)#, ','.join([f.toString('') for f in newFields])
         drop = [ myfields.pop(i) for x in range(3) ] #prev, 
         array = makeArrayField(self, newFields )          
         myfields.insert(i, array)
     #
     i+=1
   self._fields = myfields
   return
예제 #2
0
  def _excludeSizeVariableFromIntArray(self):
    if len(self._fields) < 2:
      return
    self._dirty=True
    
    ''' nested func will explode the array fields in 3 fields '''
    def cutInThree():
      log.debug('cutting in three %d %d %d'%(ind, nbSeen, val))
      # cut array in three
      index = self._fields.index(_arrayField)
      oldArray = self._fields.pop(index) # cut it from self.fields
      # cut the field in 3 parts ( ?zerroes, val, list)
      # add the rest
      if len(_arrayField.elements[ind+1:]) > 1: # add zerroes in front
        self._fields.insert(index, makeArrayField(self, _arrayField.elements[ind+1:]) )
      elif len(_arrayField.elements[ind+1:]) == 1: # add zero field
        self._fields.insert(index, _arrayField.elements[ind+1])
      # add the value
      self._fields.insert(index, _arrayField.elements[ind])
      # add zerroes in front
      if ind > 1: 
        self._fields.insert(index, makeArrayField(self, _arrayField.elements[:ind]) )
      elif ind == 1: # add zero field
        self._fields.insert(index, _arrayField.elements[0])
      #end

    # test    
    #intArrays = [ f for f in self.fields if f.isArray() and fieldtypes.isIntegerType(f.basicTypename) and len(f.elements) > 7]
    #log.debug( '%d intArrays'%(len(intArrays)) )
    #for _arrayField in intArrays:
    #  values = [ f.value for f in _arrayField.elements ]
    #  self._chopAnywhere(values)
    
    # small array, no interest.
    intArrays = [ f for f in self._fields if f.isArray() and fieldtypes.isIntegerType(f.basicTypename) and len(f.elements) > 7]
    log.debug( '%d intArrays'%(len(intArrays)) )
    for _arrayField in intArrays:
      values = [ f.value for f in _arrayField.elements ]
      ## head
      ret  = self._chopImprobableHead(values)
      if ret is not None: 
        ind, nbSeen, val = ret
        cutInThree()

    log.debug('going choping reverse')
    # small array, no interest.
    intArrays = [ f for f in self._fields if f.isArray() and fieldtypes.isIntegerType(f.basicTypename) and len(f.elements) > 7]
    log.debug( 'reverse %d intArrays'%(len(intArrays)) )
    for _arrayField in intArrays:
      ## tail
      values = [ f.value for f in _arrayField.elements ]
      values.reverse()
      ret  = self._chopImprobableHead(values)
      if ret is not None:
        ind, nbSeen, val = ret
        ind = len(values) - ind -1
        # cut the field in 3 parts ( ?zerroes, val, list)
        cutInThree()
    return
예제 #3
0
    def _aggZeroesBetweenIntArrays(self):
        if len(self._fields) < 3:
            return
        self._dirty = True

        myfields = sorted(self._fields)
        i = 0
        while (i < len(myfields) - 3):
            prev = myfields[i]
            field = myfields[i + 1]
            next = myfields[i + 2]
            if prev.isArray() and next.isArray() and field.isZeroes() and (
                    fieldtypes.isIntegerType(prev.basicTypename)
                    and fieldtypes.isIntegerType(next.basicTypename)):
                # we have zeroes in the middle
                fieldLen = len(field)
                nbWord = fieldLen // Config.WORDSIZE
                if (
                        fieldLen % Config.WORDSIZE == 0
                ) and nbWord < 4:  # more than 3 word zerroes it is probably another buffer
                    # concat prev, field and next arrays to get on array
                    newFields = prev.elements + [field]
                    field.checkSmallInt()  # force it in a small integer
                    if nbWord > 1:
                        for offsetadd in range(Config.WORDSIZE,
                                               Config.WORDSIZE * nbWord,
                                               Config.WORDSIZE):
                            newFields.append(
                                self._addField(field.offset + offsetadd,
                                               FieldType.SMALLINT,
                                               Config.WORDSIZE, False))
                    newFields.extend(next.elements)
                    # make an array for newFields and insert it in place of prev+field+next
                    # pop prev, newfields and next, and put them in an array
                    #print 'aggZeroes', i, len(newFields)#, ','.join([f.toString('') for f in newFields])
                    drop = [myfields.pop(i) for x in range(3)]  #prev,
                    array = makeArrayField(self, newFields)
                    myfields.insert(i, array)
            #
            i += 1
        self._fields = myfields
        return
예제 #4
0
 def _checkZeroesIndexes(self):
   intArrays = [ f for f in self._fields if f.isArray() and fieldtypes.isIntegerType(f.basicTypename) and len(f.elements) > 7]
   print( '_checkZeroesIndexes %d intArrays'%(len(intArrays)) )
   for _arrayField in intArrays:
     values = [ f.value for f in _arrayField.elements ]
     ## get indices for 0
     indices = [ ind for ind, val in enumerate(values) if val == 0]
     if len(indices) > 2:
       intervals = [ (indices[i+1] - indices[i]) for i in range(0,len(indices)-1)]
       if len(set(intervals)) == 1:
         log.debug('only one interval values. Looks like a array terminator')
예제 #5
0
 def _checkZeroesIndexes(self):
     intArrays = [
         f for f in self._fields
         if f.isArray() and fieldtypes.isIntegerType(f.basicTypename)
         and len(f.elements) > 7
     ]
     print('_checkZeroesIndexes %d intArrays' % (len(intArrays)))
     for _arrayField in intArrays:
         values = [f.value for f in _arrayField.elements]
         ## get indices for 0
         indices = [ind for ind, val in enumerate(values) if val == 0]
         if len(indices) > 2:
             intervals = [(indices[i + 1] - indices[i])
                          for i in range(0,
                                         len(indices) - 1)]
             if len(set(intervals)) == 1:
                 log.debug(
                     'only one interval values. Looks like a array terminator'
                 )
예제 #6
0
    def _checkBufferLen(self):

        fieldsToRemove = []
        # list all untyped arrays
        for i, f in enumerate(self.fields):
            if f in fieldsToRemove:
                continue
            l = len(f)
            m = math.modf(math.log(l, 2))
            if m[0] == 0.0:  # we have a perfect buffer size  on 2**x
                continue
            if f.typename == FieldType.UNKNOWN:
                log.debug('ok found one')
                if m[1] > 5.0 and m[
                        0] > 0.9:  # big buffer size, but not a big enough. look at next fields
                    target = 2**(m[1] + 1)
                    log.debug('Untyped Buffer resize we are missing %d bytes' %
                              (target - l))
                    cnt = l
                    newfields = []
                    for f2 in self._fields[i + 1:]:
                        cnt += len(f2)
                        newfields.append(f2)
                        if cnt < target:
                            continue
                        elif cnt > target:
                            # we need to cut f2 ???
                            log.debug(
                                'we need to cut f2:%s to meet size heuristics. dropping'
                                % (f2))
                            newfields = []
                            break
                        else:  # perfect
                            log.debug(
                                'Untyped buffer resize need to aggregate %d next fields'
                                % (len(newfields)))
                            breaktarget = 2**(m[1] + 1)
                    if len(newfields) == 0:
                        continue  # need to cut
                    fieldsToRemove.extend(newfields)
                    f.size = target
                    log.debug('Aggregation done. fields sent to delete corner')
            elif f.isArray() and fieldtypes.isIntegerType(
                    f.basicTypename) and len(f.elements) > 7:
                # check number of elements.
                m = math.modf(math.log(l, 2))
                # if close to 2** > 7
                if m[0] < 0.1:  # close enough btu too big
                    target = 2**(m[1])
                    size = f.size
                    offset = f.offset
                    changing = True
                    while size > target and changing:
                        changing = False
                        if f.elements[0].value == 0:
                            # cut head
                            changing = True
                            offset += Config.WORDSIZE
                            size -= Config.WORDSIZE
                        elif f.elements[0].value == 0:
                            # cut head
                            changing = True
                            size -= Config.WORDSIZE
                    if size != target:
                        log.debug(
                            'I am not capable of shorting this array by expelling zeroes'
                        )
                        continue
                    f.offset = offset
                    f.size = size
                    f.checkIntegerArray()
                    self._fixGaps()
        #cleaning
        for f in fieldsToRemove:
            self._fields.remove(f)
        return
예제 #7
0
    def _excludeSizeVariableFromIntArray(self):
        if len(self._fields) < 2:
            return
        self._dirty = True
        ''' nested func will explode the array fields in 3 fields '''
        def cutInThree():
            log.debug('cutting in three %d %d %d' % (ind, nbSeen, val))
            # cut array in three
            index = self._fields.index(_arrayField)
            oldArray = self._fields.pop(index)  # cut it from self.fields
            # cut the field in 3 parts ( ?zerroes, val, list)
            # add the rest
            if len(_arrayField.elements[ind + 1:]) > 1:  # add zerroes in front
                self._fields.insert(
                    index, makeArrayField(self,
                                          _arrayField.elements[ind + 1:]))
            elif len(_arrayField.elements[ind + 1:]) == 1:  # add zero field
                self._fields.insert(index, _arrayField.elements[ind + 1])
            # add the value
            self._fields.insert(index, _arrayField.elements[ind])
            # add zerroes in front
            if ind > 1:
                self._fields.insert(
                    index, makeArrayField(self, _arrayField.elements[:ind]))
            elif ind == 1:  # add zero field
                self._fields.insert(index, _arrayField.elements[0])
            #end

        # test
        #intArrays = [ f for f in self.fields if f.isArray() and fieldtypes.isIntegerType(f.basicTypename) and len(f.elements) > 7]
        #log.debug( '%d intArrays'%(len(intArrays)) )
        #for _arrayField in intArrays:
        #  values = [ f.value for f in _arrayField.elements ]
        #  self._chopAnywhere(values)

        # small array, no interest.
        intArrays = [
            f for f in self._fields
            if f.isArray() and fieldtypes.isIntegerType(f.basicTypename)
            and len(f.elements) > 7
        ]
        log.debug('%d intArrays' % (len(intArrays)))
        for _arrayField in intArrays:
            values = [f.value for f in _arrayField.elements]
            ## head
            ret = self._chopImprobableHead(values)
            if ret is not None:
                ind, nbSeen, val = ret
                cutInThree()

        log.debug('going choping reverse')
        # small array, no interest.
        intArrays = [
            f for f in self._fields
            if f.isArray() and fieldtypes.isIntegerType(f.basicTypename)
            and len(f.elements) > 7
        ]
        log.debug('reverse %d intArrays' % (len(intArrays)))
        for _arrayField in intArrays:
            ## tail
            values = [f.value for f in _arrayField.elements]
            values.reverse()
            ret = self._chopImprobableHead(values)
            if ret is not None:
                ind, nbSeen, val = ret
                ind = len(values) - ind - 1
                # cut the field in 3 parts ( ?zerroes, val, list)
                cutInThree()
        return
예제 #8
0
 def _checkBufferLen(self):
   
   fieldsToRemove = []
   # list all untyped arrays
   for i,f in enumerate(self.fields):
     if f in fieldsToRemove:
       continue
     l = len(f)
     m = math.modf(math.log( l, 2)) 
     if m[0] == 0.0: # we have a perfect buffer size  on 2**x
       continue
     if f.typename == FieldType.UNKNOWN:
       log.debug( 'ok found one')
       if m[1]>5.0  and m[0] > 0.9: # big buffer size, but not a big enough. look at next fields
         target = 2**(m[1]+1)
         log.debug('Untyped Buffer resize we are missing %d bytes'%(target-l))
         cnt = l
         newfields = []
         for f2 in self._fields[i+1:]:
           cnt+=len(f2)
           newfields.append(f2)
           if cnt < target:
             continue
           elif cnt > target:
             # we need to cut f2 ???
             log.debug('we need to cut f2:%s to meet size heuristics. dropping'%(f2))
             newfields = []
             break
           else: # perfect
             log.debug('Untyped buffer resize need to aggregate %d next fields'%(len(newfields))) 
             breaktarget = 2**(m[1]+1)
         if len(newfields) == 0:
           continue # need to cut
         fieldsToRemove.extend(newfields)
         f.size = target
         log.debug('Aggregation done. fields sent to delete corner')
     elif f.isArray() and fieldtypes.isIntegerType(f.basicTypename) and len(f.elements) > 7:
       # check number of elements.
       m = math.modf(math.log( l, 2)) 
       # if close to 2** > 7
       if m[0] < 0.1: # close enough btu too big
         target = 2**(m[1])
         size = f.size
         offset = f.offset
         changing = True
         while size > target and changing:
           changing = False
           if f.elements[0].value == 0:
             # cut head
             changing = True
             offset += Config.WORDSIZE
             size -= Config.WORDSIZE
           elif f.elements[0].value == 0:
             # cut head
             changing = True
             size -= Config.WORDSIZE
         if size != target:
           log.debug('I am not capable of shorting this array by expelling zeroes')
           continue
         f.offset = offset
         f.size = size
         f.checkIntegerArray()
         self._fixGaps()
   #cleaning
   for f in fieldsToRemove:
     self._fields.remove(f)
   return