inside_expr.sv 1.93 KB
Newer Older
1
module top;
2

3 4 5 6 7 8 9
    initial
        for (logic [1:0] a = 0; a < 3; a++) begin
            if (a inside {2'b01, 2'b00})
                $display("fizz");
            if (a inside {2'b10})
                $display("buzz");
        end
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

    initial $display("A", 3'bz11 inside {3'b?01});
    initial $display("B", 3'bz11 inside {3'b1?1});
    initial $display("C", 3'bz11 inside {3'b011});
    initial $display("D", 3'bz11 inside {3'b1?1, 3'b011});
    initial $display("E", 3'bz11 inside {3'b?01, 3'b011});

    function test1;
        input logic [2:0] inp;
        return inp inside {3'b1?1};
    endfunction
    initial begin
        // should match
        $display("test1: %b %b", 3'b101, test1(3'b101));
        $display("test1: %b %b", 3'b111, test1(3'b111));
        $display("test1: %b %b", 3'b1x1, test1(3'b1x1));
        $display("test1: %b %b", 3'b1z1, test1(3'b1z1));
        // shouldn't match
        $display("test1: %b %b", 3'b001, test1(3'b001));
        $display("test1: %b %b", 3'b011, test1(3'b011));
        $display("test1: %b %b", 3'b0x1, test1(3'b0x1));
        $display("test1: %b %b", 3'b0z1, test1(3'b0z1));
    end

34
    integer arr [] = { 32'd60, 32'd61, 32'd63 };
35 36
    function test2;
        input integer inp;
37 38 39 40 41 42
        // TODO: Add support for array value ranges.
        test2 = 0;
        for (integer i = 0; i < 3; ++i)
            if (inp == arr[i])
                return 1'b1;
        return test2 || inp inside { [16:23], [32:47] };
43 44 45 46 47 48
    endfunction
    initial begin
        for (integer i = 0; i < 64; ++i)
            $display("test2(%02d) = %b", i, test2(i));
    end

49 50 51 52 53 54 55 56 57 58 59 60 61 62
    function integer test3;
        input integer inp;
        case (inp) inside
            [16:23]: return 1;
            [32:47]: return 2;
            default: return 0;
            0, [60:61], 4: return 3;
        endcase
    endfunction
    initial begin
        for (integer i = 0; i < 64; ++i)
            $display("test3(%02d) = %b", i, test3(i));
    end

63
endmodule