aboutsummaryrefslogtreecommitdiffstats
path: root/tests/verilog/func_tern_hint.sv
blob: 3c58c9913a5b08d75252b3ba91481501a431df89 (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
module top;
    function automatic [30:0] func;
        input integer inp;
        func = { // self-determined context
            (
                inp == 0
                ? -1 // causes whole ternary to be 32 bits
                : func(inp - 1) // 31 bits, unsigned
            ) >> 2};
    endfunction
    function automatic signed [3:0] dunk;
        input integer inp;
        dunk = (
                inp == 0
                ? 4'hF
                // shouldn't make the ternary signed
                : dunk(inp - 1)
            ) == -1;
    endfunction
    localparam A = func(0);
    localparam B = func(1);
    localparam C = func(2);
    localparam D = func(3);
    localparam X = dunk(0);
    localparam Y = dunk(1);
    initial begin
        assert(A == 31'h3F_FFFFFF);
        assert(B == 31'h0F_FFFFFF);
        assert(C == 31'h03_FFFFFF);
        assert(D == 31'h00_FFFFFF);
        assert(X == 0);
        assert(Y == 0);
    end
    initial begin
        logic x;
        case (1'b1)
            dunk(0): x = 0;
            default: x = 1;
        endcase
        assert(x);
    end
endmodule
"p">) { if(mc->bidx >= BUFFLEN) mc_reset(mc); else if( ('.' == c) || ('-' == c) ) { mc->b[mc->bidx] = c; mc->bidx++; } return; } /* mc_dec Decode a Morse code character (descend MC_DEC_KEY[]) * Input: b = BUFFLEN-length char array with '.'s and '-'s * Output: c = Character b represents, or '\0' if not a Morse code. */ char mc_dec(char b[BUFFLEN]) { uint8_t pos = 1; // Binary tree position ('.'=0; '-'=1) for(uint8_t idx=0; idx<BUFFLEN; idx++) { if('.' == b[idx]) pos = 2*pos; // Descend in . direction else if('-' == b[idx]) pos = 2*pos+1; // Descend in - direction else break; // End of morse code segment; finished descending } return MC_DEC_KEY[pos-1]; }