Example #1
0
def soft(e):

    to_expr(e)
    em = pop_expr()
    c = ConstraintSoftModel(em)
    c.srcinfo = em.srcinfo
    push_constraint_stmt(c)
Example #2
0
    def visit_covergroup(self, cg: CovergroupModel):

        if not self._in_generator or self._pass != 1:
            return

        # TODO: in the case of multiple covergroups, need to have
        # made a higher-level decision about which covergroup to target
        # TODO: determine which coverpoints we're going to enable
        # First try: just select one
        unhit_cp = []
        for cp in cg.coverpoint_l:
            if cp.get_coverage() != 100:
                unhit_cp.append(cp)
        for cp in cg.cross_l:
            if cp.get_coverage() != 100:
                unhit_cp.append(cp)

        if len(unhit_cp) > 0:
            # Only process the target coverpoint
            target_cp = self.randint(0, len(unhit_cp) - 1)
            bin_idx = unhit_cp[target_cp].select_unhit_bin(self)
            bin_expr = unhit_cp[target_cp].get_bin_expr(bin_idx)
            c = ConstraintSoftModel(bin_expr)
            cc = ConstraintBlockModel("coverage", [c])
            cc.accept(self)
Example #3
0
 def visit_constraint_soft(self, c: ConstraintSoftModel):
     c.priority = 0
Example #4
0
 def visit_constraint_soft(self, c: ConstraintSoftModel):
     if self.do_copy_level > 0:
         ret = ConstraintSoftModel(self.expr(c.expr))
         self.constraints.append(ret)
     else:
         super().visit_constraint_soft(c)
Example #5
0
def soft(e):

    to_expr(e)
    push_constraint_stmt(ConstraintSoftModel(pop_expr()))
Example #6
0
    def visit_constraint_dist(self, c):
        # We replace the dist constraint with an equivalent
        # set of hard and soft constraints
        scope = ConstraintDistScopeModel(c)

        ranges = ExprRangelistModel()
        for w in c.weights:
            if w.rng_rhs is not None:
                # two-value range
                ranges.add_range(ExprRangeModel(w.rng_lhs, w.rng_rhs))
            else:
                # single value
                ranges.add_range(w.rng_lhs)

        # First, create an 'in' constraint to restrict
        # values to the appropriate value set
        in_c = ConstraintExprModel(ExprInModel(c.lhs, ranges))
        scope.addConstraint(in_c)

        # Now, we need to add exclusion constraints for any
        # zero weights
        # (!w) -> (lhs != [val])
        # (!w) -> (lns not in [rng])
        for w in c.weights:
            if w.rng_rhs is not None:
                scope.addConstraint(
                    ConstraintImpliesModel(
                        ExprBinModel(w.weight, BinExprType.Eq,
                                     ExprLiteralModel(0, False, 8)),
                        [
                            ConstraintExprModel(
                                ExprUnaryModel(
                                    UnaryExprType.Not,
                                    ExprBinModel(
                                        ExprBinModel(c.lhs, BinExprType.Ge,
                                                     w.rng_lhs),
                                        BinExprType.And,
                                        ExprBinModel(c.lhs, BinExprType.Le,
                                                     w.rng_rhs))))
                        ]))
            else:
                scope.addConstraint(
                    ConstraintImpliesModel(
                        ExprBinModel(w.weight, BinExprType.Eq,
                                     ExprLiteralModel(0, False, 8)),
                        [
                            ExprUnaryModel(
                                UnaryExprType.Not,
                                ExprBinModel(c.lhs, BinExprType.Eq, w.rng_lhs))
                        ]))

        # Form a list of non-zero weighted tuples of weight/range
        # Sort in ascending order
        weight_l = []
        total_w = 0
        for i, w in enumerate(c.weights):
            weight = int(w.weight.val())
            total_w += weight
            if weight > 0:
                weight_l.append((weight, i))
        weight_l.sort(key=lambda w: w[0])

        seed_v = self.rng.randint(1, total_w)

        # Find the first range
        i = 0
        while i < len(weight_l):
            seed_v -= weight_l[i][0]

            if seed_v <= 0:
                break

            i += 1

        if i >= len(weight_l):
            i = len(weight_l) - 1

        scope.target_range = weight_l[i][1]
        target_w = c.weights[weight_l[i][1]]
        dist_soft_c = None
        if target_w.rng_rhs is not None:
            dist_soft_c = ConstraintSoftModel(
                ExprBinModel(
                    ExprBinModel(c.lhs, BinExprType.Ge, target_w.rng_lhs),
                    BinExprType.And,
                    ExprBinModel(c.lhs, BinExprType.Le, target_w.rng_rhs)))
        else:
            dist_soft_c = ConstraintSoftModel(
                ExprBinModel(c.lhs, BinExprType.Eq, target_w.rng_lhs))
        # Give dist constraints a high priority to allow
        # them to override all user-defined soft constraints
        dist_soft_c.priority = 1000000
        scope.set_dist_soft_c(dist_soft_c)

        self.override_constraint(scope)