File: t_constraint_operators.v

package info (click to toggle)
verilator 5.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 162,552 kB
  • sloc: cpp: 139,204; python: 20,931; ansic: 10,222; yacc: 6,000; lex: 1,925; makefile: 1,260; sh: 494; perl: 282; fortran: 22
file content (103 lines) | stat: -rw-r--r-- 2,942 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2023 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0

class Packet;
   rand int x;
   rand bit [31:0] b;
   rand bit [31:0] c;
   rand bit [31:0] d;
   rand bit tiny;
   rand bit zero;
   rand bit one;
   rand int out0, out1, out2, out3, out4, out5, out6;

   bit state;

   typedef bit signed [63:0] s64;
   typedef bit [63:0] u64;

   constraint arith { x + x - x == x; }
   constraint divmod { int'((x % 5) / 2) != (b % 99) / 7; }
   constraint mul { x * 9 != b * 3; }
   constraint impl { tiny == 1 -> x != 10; }
   constraint concat { {c, b} != 'h1111; }
   constraint unary { !(-~c == 'h22); }
   constraint log { ((b ^ c) & (b >>> c | b >> c | b << c)) > 0; }
   constraint cmps { x < x || x <= x || x > x || x >= x; }
   constraint cmpu { b < b || b <= b || b > b || b >= b; }
   constraint ext { s64'(x) != u64'(tiny); }
   constraint cond { (tiny == 1 ? b : c) != 17; }
   constraint zero_c { zero == 0; }
   constraint one_c { one == 1; }
   constraint sel { d[15:8] == 8'h55; }
   constraint ifelse {
      if (one) out0 == 'h333;

      if (!one) tiny != tiny;
      else out1 == 'h333;
      if (one == 1) out2 == 'h333;
      else tiny != tiny;
      if (0) tiny != tiny;
      else out3 == 'h333;
      if (1) out4 == 'h333;
      else tiny != tiny;

      if (one == 1)
         if (1) { out5 == 'h333; out5 == 'h333; out5 == 'h333; }
         else tiny != tiny;
      else
         if (1) tiny != tiny;
         else { tiny != tiny; }

      if (1)
         if (one == 1) { out6 == 'h333; out6 == 'h333; out6 == 'h333; }
         else tiny != tiny;
      else
         if (one == 1) tiny != tiny;
         else { tiny != tiny; }

      if (one && zero) tiny != tiny;
      if (~one && zero) tiny != tiny;
      if (zero || (one & zero)) tiny != tiny;
      if (zero && (one | zero)) tiny != tiny;
   }

endclass

module t (/*AUTOARG*/);

   Packet p;

   int v;

   initial begin
      p = new;
      v = p.randomize();
      if (v != 1) $stop;
      if ((p.x % 5) / 2 == (p.b % 99) / 7) $stop;
      if (p.x * 9 == p.b * 3) $stop;
      if (p.tiny && p.x == 10) $stop;
      if ({p.c, p.b} == 'h1111) $stop;
      if (-~p.c == 'h22) $stop;
      if (((p.b ^ p.c) & (p.b >>> p.c | p.b >> p.c | p.b << p.c)) <= 0) $stop;
      if (p.x == int'(p.tiny)) $stop;
      if ((p.tiny == 1 ? p.b : p.c) == 17) $stop;
      if ((p.tiny == 1 ? p.b : p.c) == 17) $stop;
      if (p.zero != 0) $stop;
      if (p.one != 1) $stop;
      if (p.out0 != 'h333) $stop;
      if (p.out1 != 'h333) $stop;
      if (p.out2 != 'h333) $stop;
      if (p.out3 != 'h333) $stop;
      if (p.out4 != 'h333) $stop;
      if (p.out5 != 'h333) $stop;
      if (p.out6 != 'h333) $stop;
      if (p.d[15:8] != 'h55) $stop;

      $write("*-* All Finished *-*\n");
      $finish;
   end
endmodule