Пример #1
0
def decode_data(x):
   tmp = struct.unpack('>I', x)[0]
   sgn = tmp >> 31
   val = (tmp >> 18) & BitOps.mask(13)
   if sgn == 1:
     val = (1 << 13) - val
   fault = tmp >> 16 & 1
   val = val * BitOps.bit2sign(sgn)

   ref_junc = tmp >> 4 & BitOps.mask(11)
   if tmp >> 15 & 1: ref_junc = (1 << 11) - ref_junc;
   ref_junc /= 2**4
   return val / 4, ref_junc
Пример #2
0
    def _set(self, val, off, size, lazy, le):
        # TODO: le ignored here
        base = off // 8
        off %= 8
        val = bytearray(val)
        if len(val) == 0: return
        if lazy == False or not self.lazy:
            nx = (off + size + 7) // 8
            if le: val = val[:nx]
            else: val = val[len(val) - nx:]
            val = Format(val).shiftl(off).v

            mask0 = BitOps.mask(off)
            maskn1 = BitOps.imask(
                BitOps.mod1(off + size, 8),
                modpw=8)  # we dont want imask(0) (imask(8) needed)

            b0 = self.buf.read(base)
            mask_b0 = mask0
            if nx == 1:
                b0 |= maskn1
            else:
                if maskn1 != 0:
                    val[-1] |= self.buf.read(base + nx - 1) & maskn1

            if mask_b0 != 0: val[0] |= b0 & mask_b0

            self.buf.write(base, val)
        else:
            assert False
Пример #3
0
    def resize_bits(self, n):
        assert isinstance(self.v, bytearray)
        nx = len(self.v) * 8 - n
        if nx // 8 != 0:
            del self.v[-(nx // 8):]

        if nx > 0:
            nx &= 7
            self.v[-1] &= BitOps.mask(8 - (nx & 7))
        return self
Пример #4
0
 def __init__(self, atom_bitsize, reader=None, writer=None):
     self.atom_bitsize = atom_bitsize
     self.reader = reader
     self.writer = writer
     self.atom_data = defaultdict(lambda: [BitOps.mask(atom_bitsize), 0])
     self.lrufifo = LRUFifo()