Exemple #1
0
 def encodeVbn(self, value, buf):
     offset = 0
     done = False
     while not done:
         bits = value & 0x7F
         value >>= 7
         done = (value == 0 or ~value == 0) and \
                utils.bit(bits, 6) == utils.bit(value, 0)
         if not done:
             bits |= 0x80
         buf.append(bits)
Exemple #2
0
 def test(self, int_list):
     T = [0 for i in range(int(pow(2, self.L)))]
     blocks = []
     n = len(int_list) * 32
     blocks_num = int(n / self.L)
     ind_int = 0
     ind_bit = 0
     for i in range(blocks_num):
         val = 0
         for j in range(self.L):
             val += bit(int_list[ind_int], ind_bit) * int(
                 pow(2, self.L - j - 1))
             ind_bit += 1
             if ind_bit >= 32:
                 ind_bit = 0
                 ind_int += 1
         blocks.append(val)
     for i in range(self.Q):
         T[blocks[i]] = i + 1
     fn = 0.0
     for i in range(self.Q, blocks_num):
         tmp = i + 1 - T[blocks[i]]
         T[blocks[i]] = i + 1
         fn += log2(tmp)
     K = blocks_num - self.Q
     fn /= K
     c = 0.7 - 0.8 / self.L + (4 + 32.0 / self.L) * (pow(K, -3.0 / self.L) /
                                                     15)
     sgm = c * sqrt(1.0 * self.E[self.L - 6][1] / (blocks_num - self.Q))
     p_val = erfc(abs((fn - self.E[self.L - 6][0]) / (sqrt(2) * sgm)))
     return p_val >= 0.01
Exemple #3
0
 def test(self, int_list):
     n = len(int_list) * 32
     if not n >= 38 * self.M * self.Q:
         raise AssertionError()
     r = [0.0, 0.0, 0.0]
     ind_int = 0
     matrix_num = int(n / (self.M * self.Q))
     for i in range(matrix_num):
         m = []
         for j in range(self.M):
             l = []
             for k in range(self.Q):
                 l.append(bit(int_list[ind_int], k))
             ind_int += 1
             m.append(l)
         rank = matrix_rank(m)
         if rank == self.M:
             r[0] += 1
         elif rank == self.M - 1:
             r[1] += 1
     r[2] = matrix_num - r[0] - r[1]
     chi_sq = (pow((r[0] - 0.2888 * matrix_num), 2) / (0.2888 * matrix_num))
     chi_sq += (pow(
         (r[1] - 0.5776 * matrix_num), 2) / (0.5776 * matrix_num))
     chi_sq += (pow(
         (r[2] - 0.1336 * matrix_num), 2) / (0.1336 * matrix_num))
     #p_val = exp(-chi_sq / 2)
     p_val = gammaincc(1.0, chi_sq / 2)
     return p_val >= 0.01
Exemple #4
0
 def test(self, int_list):
     s = 0
     for num in int_list:
         for i in range(32):
             s += 2 * bit(num, i) - 1
     s_obs = abs(s) / sqrt(len(int_list) * 32)
     p_val = erfc(s_obs / sqrt(2))
     return p_val >= 0.01
Exemple #5
0
 def test(self, int_list):
     n = len(int_list) * 32
     if not n >= 100:
         raise AssertionError()
     pi = 0
     for num in int_list:
         for i in range(32):
             pi += bit(num, i)
     pi /= n
     if abs(pi - 0.5) >= 2 / sqrt(n):
         return False
     v = 1
     last = None
     for num in int_list:
         for i in range(32):
             if last is not None and last != bit(num, i):
                 v += 1
             last = bit(num, i)
     val = abs(v - 2 * n * pi * (1 - pi)) / (2 * sqrt(2 * n) * pi *
                                             (1 - pi))
     p_val = erfc(val)
     return p_val >= 0.01
Exemple #6
0
 def test(self, int_list):
     n = len(int_list) * 32
     N = int(n / self.M)
     if not n >= 100 or not self.M > 20 or not self.M > 0.01 * n or not N < 100:
         raise AssertionError()
     ind_int = 0
     ind_bit = 0
     chi_sq = 0.0
     for i in range(N):
         sp = 0
         for j in range(self.M):
             sp += bit(int_list[ind_int], ind_bit)
             ind_bit += 1
             if ind_bit >= 32:
                 ind_bit = 0
                 ind_int += 1
         chi_sq += pow((sp / self.M) - 0.5, 2)
     chi_sq *= 4 * self.M
     p_val = gammaincc(N / 2, chi_sq / 2)
     return p_val >= 0.01
Exemple #7
0
    def test(self, int_list):
        if not self.m >= 3:
            raise AssertionError()
        n = len(int_list) * 32
        if not self.m < int(log2(n)) - 2:
            raise AssertionError()
        v0 = [0 for i in range(int(pow(2, self.m)))]
        v1 = [0 for i in range(int(pow(2, self.m - 1)))]
        v2 = [0 for i in range(int(pow(2, self.m - 2)))]

        bits = ''
        for num in int_list:
            for j in range(32):
                bits += str(bit(num, j))

        bits0 = bits + bits[0 : self.m - 1]
        bits1 = bits + bits[0 : self.m - 2]
        bits2 = bits + bits[0 : self.m - 3]

        fi0 = fi1 = fi2 = 0

        for i in range(len(v0)):
            fi0 += pow(count_all(bits0, intToStrBin(i, self.m)), 2)
        for i in range(len(v1)):
            fi1 += pow(count_all(bits1, intToStrBin(i, self.m - 1)), 2)
        for i in range(len(v2)):
            fi2 += pow(count_all(bits2, intToStrBin(i, self.m - 2)), 2)

        fi0 = (pow(2, self.m) / n) * fi0 - n
        fi1 = (pow(2, self.m - 1) / n) * fi1 - n
        fi2 = (pow(2, self.m - 2) / n) * fi2 - n

        d1 = fi0 - fi1
        d2 = fi0 - 2 * fi1 + fi2

        p_val1 = gammaincc(pow(2, self.m - 2), d1)
        p_val2 = gammaincc(pow(2, self.m - 3), d2)

        return p_val1 >= 0.01 and p_val2 >= 0.01
Exemple #8
0
def send_bits(bits):
    for b in bits:
        utils.bit(b)
Exemple #9
0
 def test(self, int_list):
     n = len(int_list) * 32
     if not n >= 128:
         raise AssertionError()
     ind_data = 0
     if n >= 10000:
         ind_data = 2
     elif n >= 6272:
         ind_data = 1
     M = self.data[ind_data][0]
     K = self.data[ind_data][1]
     N = self.data[ind_data][2]
     blocks_num = int(n / M)
     ind_int = 0
     ind_bit = 0
     blocks = []
     for i in range(blocks_num):
         block = ''
         for j in range(M):
             block += str(bit(int_list[ind_int], ind_bit))
             ind_bit += 1
             if ind_bit >= 32:
                 ind_bit = 0
                 ind_int += 1
         blocks.append(block)
     v = [0 for i in range(7)]
     for block in blocks:
         ones = 0
         ones_max = 0
         for c in block:
             if c == '1':
                 ones += 1
             else:
                 if ones > ones_max:
                     ones_max = ones
                 ones = 0
         if M == 8:
             if ones_max <= 1:
                 v[0] += 1
             elif ones_max == 2:
                 v[1] += 1
             elif ones_max == 3:
                 v[2] += 1
             else:
                 v[3] += 1
         elif M == 128:
             if ones_max <= 4:
                 v[0] += 1
             elif ones_max == 5:
                 v[1] += 1
             elif ones_max == 6:
                 v[2] += 1
             elif ones_max == 7:
                 v[3] += 1
             elif ones_max == 8:
                 v[4] += 1
             else:
                 v[5] += 1
         elif M == 10000:
             if ones_max <= 10:
                 v[0] += 1
             elif ones_max == 11:
                 v[1] += 1
             elif ones_max == 12:
                 v[2] += 1
             elif ones_max == 13:
                 v[3] += 1
             elif ones_max == 14:
                 v[4] += 1
             elif ones_max == 15:
                 v[5] += 1
             else:
                 v[6] += 1
     chi_sq = 0.0
     for i in range(K + 1):
         chi_sq += pow((v[i] - N * self.data[ind_data][3][i]),
                       2) / (N * self.data[ind_data][3][i])
     p_val = gammaincc(K / 2.0, chi_sq / 2)
     return p_val >= 0.01
Exemple #10
0
alu_src_b_reg = 0
alu_src_b_imm = 1
alu_src_b_shamt = 2
alu_src_b_imm_hi = 3
alu_src_b_zero = 4

pc_src_pc_add_4 = 0
pc_src_addr = 1
pc_src_reg = 2
pc_src_imm = 3

reg_src_alu = 0
reg_src_mem = 1
reg_src_pc = 2

alu_ctrl_zero = bit("0000")
alu_ctrl_add = bit("0010")
alu_ctrl_sub = bit("0011")
alu_ctrl_slt = bit("0101")
alu_ctrl_and = bit("1000")
alu_ctrl_or = bit("1001")
alu_ctrl_xor = bit("1010")
alu_ctrl_sll = bit("1100")
alu_ctrl_srl = bit("1101")
alu_ctrl_sra = bit("1110")

alu_funct_add = bit("100000")
alu_funct_addu = bit("100001")
alu_funct_sub = bit("100010")
alu_funct_subu = bit("100011")
alu_funct_and = bit("100100")
Exemple #11
0
        else:
            out2.append(label)

    print(f"    0b{'|'.join(out)}")

    if split_breakdown:
        maxlen = max(len(v) for v in out2)
        for o1, o2 in zip(out, out2):
            print(f"       {o2:>{maxlen}}: 0b{o1}")
    else:
        print(f"      {'|'.join(out2)}")


print_fields(desc, level3_fields)

if not bit(desc, 0):
    print()
    print("<invalid>")
else:
    print()
    oa = level3_fields[(47, 12)]["value"] << 12
    print(f"OA = {human_number(oa, 47-12+1)}")
    # upper
    upper_attrs_fields = {
        (63 - 50, 63 - 50): {
            "name": "IGNORED"
        },
        (62 - 50, 59 - 50): {
            "name": "PBHA"
        },
        (58 - 50, 55 - 50): {
        },
    ),
}

iss_fields_structs = {
    0b010001: svc_fields,
    0b010101: svc_fields,
    0b011000: msr_fields,
    0b100000: iabt_fields,
    0b100001: iabt_fields,
    0b100100: dabt_fields,
    0b100101: dabt_fields,
}

ec = bitslice(esr, 31, 26)
il = bit(esr, 25)
iss = bitslice(esr, 24, 0)

print(f"ESR_EL1 = 0b{0:>032b}|{ec:>06b}|{il:>1b}|{iss:>025b}")
print("                           RES0                EC   IL          ISS   ")

ec_desc = wrap(ec_descs[ec], prefix="EC: <")
print(f"EC: <{ec_desc}>")

iss_fields = iss_fields_structs.get(ec)
if iss_fields is not None:
    print()
    print(f"ISS: {human_number(iss, 25)} :")
    for f, v in iss_fields.items():
        if isinstance(f, int):
            vbit = bit(iss, f)