Пример #1
0
 def dist_a(self):
     with vsc.foreach(self.a, idx=True) as i:
         vsc.dist(self.a[i], [ 
             vsc.weight(1, 10), 
             vsc.weight(2, 20), 
             vsc.weight(4, 40), 
             vsc.weight(8, 80)])
Пример #2
0
 def dist_a(self):
     vsc.dist(self.a, [
         vsc.weight(0,  1),
         vsc.weight(1,  97),
         vsc.weight(2,  1),
         vsc.weight(3,  1),
         vsc.weight(20, 10000) #Case D: this throws off distribution when combined with the line labeled below (the larger the weight, the worse -- seems that the weights get redistributed unevenly)
 ])
Пример #3
0
 def dist_a(self):
     vsc.dist(self.a, [
         vsc.weight(0, 10),
         vsc.weight(1, 10),
         vsc.weight(2, 10),
         vsc.weight(4, 10),
         vsc.weight(8, 10)
     ])
Пример #4
0
            def test_c(self):
                self.a[0].value < self.a[1].value

                # Error here
                vsc.dist(self.a[0].value, [
                    vsc.weight(1, 10),
                    vsc.weight(2, 20),
                    vsc.weight(4, 40),
                    vsc.weight(8, 80)])
    def post_randomize(self):
        order = []
        RA = cfg.ra
        order = [0] * self.num_of_jump_instr
        self.jump = [0] * self.num_of_jump_instr
        for i in range(len(order)):
            order[i] = i
        random.shuffle(order)
        self.setup_allowed_instr(1, 1)
        jal = [riscv_instr_name_t.JAL]
        if not cfg.disable_compressed_instr:
            jal.append(riscv_instr_name_t.C_J)
            if rcs.XLEN == 32:
                jal.append(riscv_instr_name_t.C_JAL)
        self.jump_start = riscv_instr_ins.get_instr(
            riscv_instr_name_t.JAL.name)
        with self.jump_start.randomize_with() as it:
            self.jump_start.rd == RA
        self.jump_start.imm_str = "{}f".format(order[0])
        self.jump_start.label = self.label

        # Last instruction
        self.jump_end = self.randomize_instr(self.jump_end)
        self.jump_end.label = "{}".format(self.num_of_jump_instr)
        for i in range(self.num_of_jump_instr):
            self.jump[i] = riscv_instr_ins.get_rand_instr(
                include_instr=[jal[0].name])
            with self.jump[i].randomize_with() as it:
                if self.jump[i].has_rd:
                    vsc.dist(self.jump[i].rd, [
                        vsc.weight(riscv_reg_t.RA, 5),
                        vsc.weight(vsc.rng(riscv_reg_t.SP, riscv_reg_t.T0), 1),
                        vsc.weight(vsc.rng(riscv_reg_t.T2, riscv_reg_t.T6), 2)
                    ])
                    self.jump[i].rd.not_inside(cfg.reserved_regs)
            self.jump[i].label = "{}".format(i)

        for i in range(len(order)):
            if i == self.num_of_jump_instr - 1:
                self.jump[order[i]].imm_str = "{}f".format(
                    self.num_of_jump_instr)
            else:
                if order[i + 1] > order[i]:
                    self.jump[order[i]].imm_str = "{}f".format(order[i + 1])
                else:
                    self.jump[order[i]].imm_str = "{}b".format(order[i + 1])
        self.instr_list.append(self.jump_start)
        self.instr_list.extend(self.jump)
        self.instr_list.append(self.jump_end)
        for i in range(len(self.instr_list)):
            self.instr_list[i].has_label = 1
            self.instr_list[i].atomic = 1
Пример #6
0
 def init_gpr(self):
     reg_val = vsc.rand_bit_t(pkg_ins.DATA_WIDTH)
     for i in range(rcs.NUM_GPR):
         if i in [cfg.sp.value, cfg.tp.value]:
             continue
         try:
             with vsc.randomize_with(reg_val):
                 vsc.dist(reg_val, [vsc.weight(0, 1), vsc.weight(0x80000000, 1),
                                    vsc.weight(vsc.rng(0x1, 0xf), 1),
                                    vsc.weight(vsc.rng(0x10, 0xefffffff), 1),
                                    vsc.weight(vsc.rng(0xf0000000, 0xffffffff), 1)])
         except Exception:
             logging.critical("Cannot Randomize reg_val")
             sys.exit(1)
         init_string = "{}li x{}, {}".format(pkg_ins.indent, i, hex(reg_val.get_val()))
         self.instr_stream.append(init_string)
Пример #7
0
 def dist_a(self):
     with vsc.if_then(self.b == 1):
         vsc.dist(self.a, [
             vsc.weight((10,15),  80),
             vsc.weight((20,30),  40),
             vsc.weight((40,70),  20),
             vsc.weight((80,100), 10)])
     with vsc.else_then:
         vsc.dist(self.a, [
             vsc.weight((10,15),  10),
             vsc.weight((20,30),  20),
             vsc.weight((40,70),  40),
             vsc.weight((80,100), 80)])
Пример #8
0
 def exception_dist_c(self):
     vsc.dist(self.exception,
              [vsc.weight(illegal_instr_type_e.kIllegalOpcode, 3),
               vsc.weight(illegal_instr_type_e.kIllegalCompressedOpcode, 1),
               vsc.weight(illegal_instr_type_e.kIllegalFunc3, 1),
               vsc.weight(illegal_instr_type_e.kIllegalFunc7, 1),
               vsc.weight(illegal_instr_type_e.kReservedCompressedInstr, 1),
               vsc.weight(illegal_instr_type_e.kHintInstr, 3),
               vsc.weight(illegal_instr_type_e.kIllegalSystemInstr, 3)
               ])
Пример #9
0
    def test_distweight(self):
        PCID = vsc.rand_uint16_t()
        
        hist1 = [0]*65536
        hist2 = [0]*65536

        items = 10000
        for i in range(items):
#            vsc.randomize(PCID)
            with vsc.randomize_with(PCID, debug=0):
#                PCID.inside(vsc.rng(1,65534))
                vsc.dist(PCID, [
                    vsc.weight(0, 1),
                    vsc.weight(vsc.rng(1,65534), 900),
                    vsc.weight(65535, 1)
                    ])
#            print("PCID: " + str(PCID.get_val()))
            hist1[PCID.get_val()] += 1 
            hist2[random.randint(1,65534)] += 1

        hist1_hit = 0
        hist2_hit = 0
        for e in hist1[1:65534]:
            if e != 0:
                hist1_hit += 1
        for e in hist2[1:65534]:
            if e != 0:
                hist2_hit += 1

        print("Items: %d hist1=%f hist2=%f" % (items, hist1_hit/65534, hist2_hit/65534))

        # Only check deeper if full random actually hit more than weighted
        if hist1_hit > hist2_hit:
            # Fail if plain randomization hit 15% more than weighted
            hist1_15p = int(hist1_hit * 0.15)
            self.assertLessEqual((hist1_hit-hist2_hit), hist1_15p)
Пример #10
0
 def dist_a(self):
     vsc.dist(self.a, [
         vsc.weight(1, self.en_one),
         vsc.weight(2, self.en_two),])
Пример #11
0
 def dist_a(self):
     vsc.dist(self.a, [
         vsc.weight(1, 10),
         vsc.weight(2, 0),
         vsc.weight(4, 40),
         vsc.weight(8, 80)])
Пример #12
0
            def dist_a(self):
#                vsc.dist(self.a, [vsc.weight(vsc.rng(my_e.A, my_e.C),10), vsc.weight(my_e.D, 20)]) 
                vsc.dist(self.a, [vsc.weight(vsc.rng(my_e.A, my_e.C),3), vsc.weight(my_e.D, 1)]) 
Пример #13
0
 def dist_a(self):
     vsc.dist(self.a, [
         vsc.weight((10,15),  80),
         vsc.weight((20,30),  40),
         vsc.weight((40,70),  20),
         vsc.weight((80,100), 10)])
Пример #14
0
 def dist_a(self):
     vsc.dist(self.a, [
         vsc.weight(1, 80),
         vsc.weight(2, 40),
         vsc.weight(3, 20),
         vsc.weight(4, 10)])
Пример #15
0
 def sp_c(self):
     vsc.dist(self.use_sp_as_rs1, [vsc.weight(1, 1), vsc.weight(0, 2)])
     with vsc.if_then(self.use_sp_as_rs1 == 1):
         self.rs1_reg == riscv_reg_t.SP
Пример #16
0
 def sample_c(self):
     self.con_one < self.con_two
     vsc.dist(self.con_one, [
         vsc.weight(0, 33),
         vsc.weight((1, 8192), 60),
         vsc.weight((8193, (2**16)-1), 7)])