File: int_types.sv

package info (click to toggle)
yosys 0.52-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 69,796 kB
  • sloc: ansic: 696,955; cpp: 239,736; python: 14,617; yacc: 3,529; sh: 2,175; makefile: 1,945; lex: 697; perl: 445; javascript: 323; tcl: 162; vhdl: 115
file content (47 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download | duplicates (2)
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