aboutsummaryrefslogtreecommitdiffstats
path: root/tests/verilog/int_types.sv
blob: 8133f8218b8b874c9b8f2cf7a462a072ded6bcf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
`define TEST(typ, width, is_signed) \
    if (1) begin \
        typ x = -1; \
        localparam typ y = -1; \
        logic [127:0] a = x; \
        logic [127:0] b = y; \
        if ($bits(x) != width) \
            $error(`"typ doesn't have expected size width`"); \
        if ($bits(x) != $bits(y)) \
            $error(`"localparam typ doesn't match size of typ`"); \
        function automatic typ f; \
            input integer x; \
            f = x; \
        endfunction \
        logic [127:0] c = f(-1); \
        always @* begin \
            assert (x == y); \
            assert (a == b); \
            assert (a == c); \
            assert ((a == -1) == is_signed); \
        end \
    end

`define TEST_INTEGER_ATOM(typ, width) \
    `TEST(typ, width, 1) \
    `TEST(typ signed, width, 1) \
    `TEST(typ unsigned, width, 0)

`define TEST_INTEGER_VECTOR(typ) \
    `TEST(typ, 1, 0) \
    `TEST(typ signed, 1, 1) \
    `TEST(typ unsigned, 1, 0) \
    `TEST(typ [1:0], 2, 0) \
    `TEST(typ signed [1:0], 2, 1) \
    `TEST(typ unsigned [1:0], 2, 0)

module top;
    `TEST_INTEGER_ATOM(integer, 32)
    `TEST_INTEGER_ATOM(int, 32)
    `TEST_INTEGER_ATOM(shortint, 16)
    `TEST_INTEGER_ATOM(longint, 64)
    `TEST_INTEGER_ATOM(byte, 8)

    `TEST_INTEGER_VECTOR(reg)
    `TEST_INTEGER_VECTOR(logic)
    `TEST_INTEGER_VECTOR(bit)
endmodule