Merge remote-tracking branch 'origin/master' into xaig_dff
[yosys.git] / tests / various / constmsk_testmap.v
1 (* techmap_celltype = "$reduce_or" *)
2 module my_opt_reduce_or(...);
3 parameter A_SIGNED = 0;
4 parameter A_WIDTH = 1;
5 parameter Y_WIDTH = 1;
6
7 input [A_WIDTH-1:0] A;
8 output reg [Y_WIDTH-1:0] Y;
9
10 parameter _TECHMAP_CONSTMSK_A_ = 0;
11 parameter _TECHMAP_CONSTVAL_A_ = 0;
12
13 wire _TECHMAP_FAIL_ = count_nonconst_bits() == A_WIDTH;
14 wire [1024:0] _TECHMAP_DO_ = "proc;;";
15
16 function integer count_nonconst_bits;
17 integer i;
18 begin
19 count_nonconst_bits = 0;
20 for (i = 0; i < A_WIDTH; i=i+1)
21 if (!_TECHMAP_CONSTMSK_A_[i])
22 count_nonconst_bits = count_nonconst_bits+1;
23 end
24 endfunction
25
26 function has_const_one;
27 integer i;
28 begin
29 has_const_one = 0;
30 for (i = 0; i < A_WIDTH; i=i+1)
31 if (_TECHMAP_CONSTMSK_A_[i] && _TECHMAP_CONSTVAL_A_[i] === 1'b1)
32 has_const_one = 1;
33 end
34 endfunction
35
36 integer i;
37 reg [count_nonconst_bits()-1:0] tmp;
38
39 always @* begin
40 if (has_const_one()) begin
41 Y = 1;
42 end else begin
43 for (i = 0; i < A_WIDTH; i=i+1)
44 if (!_TECHMAP_CONSTMSK_A_[i])
45 tmp = {A[i], tmp[count_nonconst_bits()-1:1]};
46 Y = |tmp;
47 end
48 end
49 endmodule