日常记录(99)unique、unique0、priority

https://zhuanlan.zhihu.com/p/477933396

unique

在if分支语句或者case的并行语句中,确保唯一性。

if

因此当if分支出现没有else、分支语句满足多个条件时候,触发警告

unique if
module unique_if;
    //variables declaration
    int a,b,c;

    initial begin
        //initialization
        a=10;
        b=20;
        c=40;

        unique if ( a < b ) $display("\t a is less than b");
        else   if ( a < c ) $display("\t a is less than c");
        else                $display("\t a is greater than b and c");
    end
endmodule


	 a is less than b

Warning-[RT-MTOCMUIF] More than one condition match in statement
tbb.sv, 11
  More than one condition matches are found in 'unique if' statement inside 
  unique_if, at time 0s.
  
  Line number 11 and 12 are overlapping.

case

因此当case分支出现没有default、语句满足多个条件时候,触发警告

unique case
module taa ();
    reg [2:0] irq;
    reg int2, int1, int0;
    always @(irq) begin
        {int2, int1, int0} = 3'b000;
        unique casez (irq)
            3'b1?? : int2 = 1'b1;
            3'b?1? : int1 = 1'b1;
            3'b??1 : int0 = 1'b1;
        endcase
    end

    initial begin
        irq = 0;
        #10 irq = 3'b111;
    end

endmodule

Warning-[RT-NCMUCS] No condition matches in statement
taa.sv, 6
  No condition matches in 'unique case' statement. 'default' specification is 
  missing, inside taa, at time 0s.


Warning-[RT-MTOCMUCS] More than one condition match in statement
taa.sv, 6
  More than one condition matches are found in 'unique case' statement inside 
  taa, at time 10s.
  
  Line number 7 and 8 are overlapping.

unique0

只判断是否条件重叠,不判断是否有else

点击查看代码
module unique_if;
    //variables declaration
    int a,b,c;

    initial begin
        //initialization
        a=50;
        b=20;
        c=40;

        unique if ( a < b ) $display("\t [unique] a is less than b");
        else   if ( a < c ) $display("\t [unique] a is less than c");
    end

    initial begin
        //initialization
        a=50;
        b=20;
        c=40;

        unique0 if ( a < b ) $display("\t [unique0] a is less than b");
        else   if ( a < c ) $display("\t [unique0] a is less than c");
    end
endmodule


Warning-[RT-NCMUIF] No condition matches in statement
tcc.sv, 11
  No condition matches in 'unique if' statement. 'else' statement is missing 
  for the last 'else if' block, inside unique_if, at time 0s.

priority

存在不满足条件时候,发出警告

priority
module priority_if;

    //variables declaration
    int a,b,c;

    initial begin
        //initialization
        a=50;
        b=20;
        c=40;

        priority if ( a < b ) $display("\t [priority] a is less than b");
        else     if ( a < c ) $display("\t [priority] a is less than c");
    end
    initial begin
        //initialization
        a=50;
        b=20;
        c=40;

        if ( a < b ) $display("\t a is less than b");
        else     if ( a < c ) $display("\t a is less than c");
    end
endmodule

Warning-[RT-NCMPRIF] No condition matches in statement
tdd.sv, 12
  No condition matches in 'priority if' statement. 'else' statement is missing
  for the last 'else if' block, inside priority_if, at time 0s.
priority case
module tee ();
    logic [3:0] y;
    logic [1:0] a;
    logic       en;
    initial begin
        $display("en is %0d", en);
    end

    always_comb begin
        y = '0;
        priority case ({en,a})
            3'b100: y[a] = 1'b1;
            3'b101: y[a] = 1'b1;
            3'b110: y[a] = 1'b1;
            3'b111: y[a] = 1'b1;
        endcase
    end
endmodule


en is x

Warning-[RT-NCMPRCS] No condition matches in statement
tee.sv, 11
  No condition matches in 'priority case' statement. 'default' specification 
  is missing, inside tee, at time 0s.

constraint 中的unique

生成内容不同的array元素

module tff ();
    class unq;
        rand reg [3:0] a[10];
        constraint cons1{
            unique {a};
        }
    endclass

    initial begin
        unq q = new();
        q.randomize();
        foreach (q.a[i]) begin
            $write("%0d ", q.a[i]);
        end
    end
endmodule

输出

14 8 2 12 3 10 0 6 9 11
posted @ 2022-06-23 15:58  大浪淘沙、  阅读(283)  评论(0)    收藏  举报