2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * The internal logic cell technology mapper.
22 * This verilog library contains the mapping of internal cells (e.g. $not with
23 * variable bit width) to the internal logic cells (such as the single bit $_NOT_
24 * gate). Usually this logic network is then mapped to the actual technology
25 * using e.g. the "abc" pass.
27 * Note that this library does not map $mem cells. They must be mapped to logic
28 * and $dff cells using the "memory_map" pass first. (Or map it to custom cells,
29 * which is of course highly recommended for larger memories.)
33 `define MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b))
34 `define MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b))
37 // --------------------------------------------------------
38 // Use simplemap for trivial cell types
39 // --------------------------------------------------------
41 (* techmap_simplemap *)
42 (* techmap_celltype = "$pos $bu0" *)
43 module simplemap_buffers;
46 (* techmap_simplemap *)
47 (* techmap_celltype = "$not $and $or $xor $xnor" *)
48 module simplemap_bool_ops;
51 (* techmap_simplemap *)
52 (* techmap_celltype = "$reduce_and $reduce_or $reduce_xor $reduce_xnor $reduce_bool" *)
53 module simplemap_reduce_ops;
56 (* techmap_simplemap *)
57 (* techmap_celltype = "$logic_not $logic_and $logic_or" *)
58 module simplemap_logic_ops;
61 (* techmap_simplemap *)
62 (* techmap_celltype = "$slice $concat $mux" *)
63 module simplemap_various;
66 (* techmap_simplemap *)
67 (* techmap_celltype = "$sr $dff $adff $dffsr $dlatch" *)
68 module simplemap_registers;
72 // --------------------------------------------------------
73 // Trivial substitutions
74 // --------------------------------------------------------
77 parameter A_SIGNED = 0;
78 parameter A_WIDTH = 1;
79 parameter Y_WIDTH = 1;
81 input [A_WIDTH-1:0] A;
82 output [Y_WIDTH-1:0] Y;
97 module \$ge (A, B, Y);
98 parameter A_SIGNED = 0;
99 parameter B_SIGNED = 0;
100 parameter A_WIDTH = 1;
101 parameter B_WIDTH = 1;
102 parameter Y_WIDTH = 1;
104 input [A_WIDTH-1:0] A;
105 input [B_WIDTH-1:0] B;
106 output [Y_WIDTH-1:0] Y;
114 ) _TECHMAP_REPLACE_ (
121 module \$gt (A, B, Y);
122 parameter A_SIGNED = 0;
123 parameter B_SIGNED = 0;
124 parameter A_WIDTH = 1;
125 parameter B_WIDTH = 1;
126 parameter Y_WIDTH = 1;
128 input [A_WIDTH-1:0] A;
129 input [B_WIDTH-1:0] B;
130 output [Y_WIDTH-1:0] Y;
138 ) _TECHMAP_REPLACE_ (
146 // --------------------------------------------------------
148 // --------------------------------------------------------
150 (* techmap_celltype = "$shr $shl $sshl $sshr" *)
151 module shift_ops_shr_shl_sshl_sshr (A, B, Y);
152 parameter A_SIGNED = 0;
153 parameter B_SIGNED = 0;
154 parameter A_WIDTH = 1;
155 parameter B_WIDTH = 1;
156 parameter Y_WIDTH = 1;
158 parameter _TECHMAP_CELLTYPE_ = "";
159 localparam shift_left = _TECHMAP_CELLTYPE_ == "$shl" || _TECHMAP_CELLTYPE_ == "$sshl";
160 localparam sign_extend = A_SIGNED && _TECHMAP_CELLTYPE_ == "$sshr";
162 input [A_WIDTH-1:0] A;
163 input [B_WIDTH-1:0] B;
164 output [Y_WIDTH-1:0] Y;
166 localparam WIDTH = `MAX(A_WIDTH, Y_WIDTH);
167 localparam BB_WIDTH = `MIN($clog2(shift_left ? Y_WIDTH : A_SIGNED ? WIDTH : A_WIDTH) + 1, B_WIDTH);
169 wire [1023:0] _TECHMAP_DO_00_ = "proc;;";
170 wire [1023:0] _TECHMAP_DO_01_ = "RECURSION; CONSTMAP; opt_muxtree; opt_const -mux_undef -mux_bool -fine;;;";
173 reg [WIDTH-1:0] buffer;
177 overflow = B_WIDTH > BB_WIDTH ? |B[B_WIDTH-1:BB_WIDTH] : 1'b0;
178 buffer = overflow ? {WIDTH{sign_extend ? A[A_WIDTH-1] : 1'b0}} : {{WIDTH-A_WIDTH{A_SIGNED ? A[A_WIDTH-1] : 1'b0}}, A};
180 for (i = 0; i < BB_WIDTH; i = i+1)
183 buffer = {buffer, (2**i)'b0};
184 else if (2**i < WIDTH)
185 buffer = {{2**i{sign_extend ? buffer[WIDTH-1] : 1'b0}}, buffer[WIDTH-1 : 2**i]};
187 buffer = {WIDTH{sign_extend ? buffer[WIDTH-1] : 1'b0}};
194 (* techmap_celltype = "$shift $shiftx" *)
195 module shift_shiftx (A, B, Y);
196 parameter A_SIGNED = 0;
197 parameter B_SIGNED = 0;
198 parameter A_WIDTH = 1;
199 parameter B_WIDTH = 1;
200 parameter Y_WIDTH = 1;
202 input [A_WIDTH-1:0] A;
203 input [B_WIDTH-1:0] B;
204 output [Y_WIDTH-1:0] Y;
206 localparam BB_WIDTH = `MIN($clog2(`MAX(A_WIDTH, Y_WIDTH)) + (B_SIGNED ? 2 : 1), B_WIDTH);
207 localparam WIDTH = `MAX(A_WIDTH, Y_WIDTH) + (B_SIGNED ? 2**(BB_WIDTH-1) : 0);
209 parameter _TECHMAP_CELLTYPE_ = "";
210 localparam extbit = _TECHMAP_CELLTYPE_ == "$shift" ? 1'b0 : 1'bx;
212 wire [1023:0] _TECHMAP_DO_00_ = "proc;;";
213 wire [1023:0] _TECHMAP_DO_01_ = "CONSTMAP; opt_muxtree; opt_const -mux_undef -mux_bool -fine;;;";
216 reg [WIDTH-1:0] buffer;
221 buffer = {WIDTH{extbit}};
222 buffer[`MAX(A_WIDTH, Y_WIDTH)-1:0] = A;
224 if (B_WIDTH > BB_WIDTH) begin
226 for (i = BB_WIDTH; i < B_WIDTH; i = i+1)
227 if (B[i] != B[BB_WIDTH-1])
230 overflow = |B[B_WIDTH-1:BB_WIDTH];
232 buffer = {WIDTH{extbit}};
235 for (i = BB_WIDTH-1; i >= 0; i = i-1)
237 if (B_SIGNED && i == BB_WIDTH-1)
238 buffer = {buffer, {2**i{extbit}}};
239 else if (2**i < WIDTH)
240 buffer = {{2**i{extbit}}, buffer[WIDTH-1 : 2**i]};
242 buffer = {WIDTH{extbit}};
250 // --------------------------------------------------------
251 // ALU Infrastructure
252 // --------------------------------------------------------
254 module \$__alu_ripple (A, B, CI, X, Y, CO, CS);
257 input [WIDTH-1:0] A, B;
258 output [WIDTH-1:0] X, Y;
263 wire [WIDTH:0] carry;
264 assign carry[0] = CI;
265 assign CO = carry[WIDTH];
266 assign CS = carry[WIDTH-1];
270 for (i = 0; i < WIDTH; i = i+1)
272 // {x, y} = a + b + c
276 \$_AND_ gate1 ( .A(a), .B(b), .Y(t1) );
277 \$_XOR_ gate2 ( .A(a), .B(b), .Y(t2) );
278 \$_AND_ gate3 ( .A(t2), .B(c), .Y(t3) );
279 \$_XOR_ gate4 ( .A(t2), .B(c), .Y(y) );
280 \$_OR_ gate5 ( .A(t1), .B(t3), .Y(x) );
282 assign a = A[i], b = B[i], c = carry[i];
283 assign carry[i+1] = x, X[i] = t2, Y[i] = y;
288 module \$__lcu (P, G, CI, CO);
291 input [WIDTH-1:0] P, G;
294 output reg [WIDTH:0] CO;
297 reg [WIDTH-1:0] p, g;
299 wire [1023:0] _TECHMAP_DO_ = "proc; opt -fast";
305 // in almost all cases CI will be constant zero
306 g[0] = g[0] | (p[0] & CI);
308 // [[CITE]] Brent Kung Adder
309 // R. P. Brent and H. T. Kung, “A Regular Layout for Parallel Adders”,
310 // IEEE Transaction on Computers, Vol. C-31, No. 3, p. 260-264, March, 1982
313 for (i = 1; i <= $clog2(WIDTH); i = i+1) begin
314 for (j = 2**i - 1; j < WIDTH; j = j + 2**i) begin
315 g[j] = g[j] | p[j] & g[j - 2**(i-1)];
316 p[j] = p[j] & p[j - 2**(i-1)];
321 for (i = $clog2(WIDTH); i > 0; i = i-1) begin
322 for (j = 2**i + 2**(i-1) - 1; j < WIDTH; j = j + 2**i) begin
323 g[j] = g[j] | p[j] & g[j - 2**(i-1)];
324 p[j] = p[j] & p[j - 2**(i-1)];
332 module \$__alu_lookahead (A, B, CI, X, Y, CO, CS);
335 input [WIDTH-1:0] A, B;
336 output [WIDTH-1:0] X, Y;
341 wire [WIDTH-1:0] P, G;
344 assign CO = C[WIDTH];
345 assign CS = C[WIDTH-1];
349 for (i = 0; i < WIDTH; i = i+1)
351 wire a, b, c, p, g, y;
353 \$_AND_ gate1 ( .A(a), .B(b), .Y(g) );
354 \$_XOR_ gate2 ( .A(a), .B(b), .Y(p) );
355 \$_XOR_ gate3 ( .A(p), .B(c), .Y(y) );
357 assign a = A[i], b = B[i], c = C[i];
358 assign P[i] = p, G[i] = g, X[i] = p, Y[i] = y;
362 \$__lcu #(.WIDTH(WIDTH)) lcu (.P(P), .G(G), .CI(CI), .CO(C));
365 module \$__alu (A, B, CI, BI, X, Y, CO, CS);
366 parameter A_SIGNED = 0;
367 parameter B_SIGNED = 0;
368 parameter A_WIDTH = 1;
369 parameter B_WIDTH = 1;
370 parameter Y_WIDTH = 1;
372 input [A_WIDTH-1:0] A;
373 input [B_WIDTH-1:0] B;
374 output [Y_WIDTH-1:0] X, Y;
376 // carry in, sub, carry out, carry sign
380 wire [Y_WIDTH-1:0] A_buf, B_buf;
381 \$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
382 \$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
385 \$__alu_ripple #(.WIDTH(Y_WIDTH)) _TECHMAP_REPLACE_ (.A(A_buf), .B(BI ? ~B_buf : B_buf), .CI(CI), .X(X), .Y(Y), .CO(CO), .CS(CS));
387 if (Y_WIDTH <= 4) begin
388 \$__alu_ripple #(.WIDTH(Y_WIDTH)) _TECHMAP_REPLACE_ (.A(A_buf), .B(BI ? ~B_buf : B_buf), .CI(CI), .X(X), .Y(Y), .CO(CO), .CS(CS));
390 \$__alu_lookahead #(.WIDTH(Y_WIDTH)) _TECHMAP_REPLACE_ (.A(A_buf), .B(BI ? ~B_buf : B_buf), .CI(CI), .X(X), .Y(Y), .CO(CO), .CS(CS));
396 // --------------------------------------------------------
397 // ALU Cell Types: Compare, Add, Subtract
398 // --------------------------------------------------------
400 `define ALU_COMMONS(_width, _ci, _bi) """
401 parameter A_SIGNED = 0;
402 parameter B_SIGNED = 0;
403 parameter A_WIDTH = 1;
404 parameter B_WIDTH = 1;
405 parameter Y_WIDTH = 1;
407 localparam WIDTH = _width;
409 input [A_WIDTH-1:0] A;
410 input [B_WIDTH-1:0] B;
411 output [Y_WIDTH-1:0] Y;
414 wire [WIDTH-1:0] alu_x, alu_y;
435 assign of = alu_co ^ alu_cs;
436 assign sf = alu_y[WIDTH-1];
439 module \$lt (A, B, Y);
440 wire [1023:0] _TECHMAP_DO_ = "RECURSION; opt_const -mux_undef -mux_bool -fine;;;";
441 `ALU_COMMONS(`MAX(A_WIDTH, B_WIDTH), 1, 1)
442 assign Y = A_SIGNED && B_SIGNED ? of != sf : cf;
445 module \$le (A, B, Y);
446 wire [1023:0] _TECHMAP_DO_ = "RECURSION; opt_const -mux_undef -mux_bool -fine;;;";
447 `ALU_COMMONS(`MAX(A_WIDTH, B_WIDTH), 1, 1)
448 assign Y = &alu_x || (A_SIGNED && B_SIGNED ? of != sf : cf);
451 module \$add (A, B, Y);
452 wire [1023:0] _TECHMAP_DO_ = "RECURSION; opt_const -mux_undef -mux_bool -fine;;;";
453 `ALU_COMMONS(Y_WIDTH, 0, 0)
457 module \$sub (A, B, Y);
458 wire [1023:0] _TECHMAP_DO_ = "RECURSION; opt_const -mux_undef -mux_bool -fine;;;";
459 `ALU_COMMONS(Y_WIDTH, 1, 1)
464 // --------------------------------------------------------
466 // --------------------------------------------------------
468 module \$__acc_set (acc_new, value);
470 output reg [2*WIDTH-1:0] acc_new;
471 input [WIDTH-1:0] value;
473 wire [1023:0] _TECHMAP_DO_ = "proc;;;";
477 for (k = 0; k < WIDTH; k = k+1) begin
478 acc_new[2*k +: 2] = value[k];
483 module \$__acc_add (acc_new, acc_old, value);
485 output reg [2*WIDTH-1:0] acc_new;
486 input [2*WIDTH-1:0] acc_old;
487 input [WIDTH-1:0] value;
489 wire [1023:0] _TECHMAP_DO_ = "proc; simplemap; opt -purge";
495 for (k = 0; k < WIDTH; k = k+1) begin
497 b = k ? acc_old[2*k-1] : 1'b0;
499 acc_new[2*k] = (a ^ b) ^ c;
500 acc_new[2*k+1] = (a & b) | ((a ^ b) & c);
505 module \$__acc_get (value, acc);
507 output reg [WIDTH-1:0] value;
508 input [2*WIDTH-1:0] acc;
510 wire [1023:0] _TECHMAP_DO_ = "proc;;;";
515 // at the end of the multiplier chain the carry-save accumulator
516 // should also have propagated all carries. thus we just need to
517 // copy the even bits from the carry accumulator to the output.
518 for (k = 0; k < WIDTH; k = k+1) begin
524 module \$__acc_mul (A, B, Y);
526 input [WIDTH-1:0] A, B;
527 output [WIDTH-1:0] Y;
529 wire [1023:0] _TECHMAP_DO_ = "proc;;";
535 (* via_celltype = "\\$__acc_set acc_new" *)
536 (* via_celltype_defparam_WIDTH = WIDTH *)
537 function [2*WIDTH-1:0] acc_set;
538 input [WIDTH-1:0] value;
541 (* via_celltype = "\\$__acc_add acc_new" *)
542 (* via_celltype_defparam_WIDTH = WIDTH *)
543 function [2*WIDTH-1:0] acc_add;
544 input [2*WIDTH-1:0] acc_old;
545 input [WIDTH-1:0] value;
548 (* via_celltype = "\\$__acc_get value" *)
549 (* via_celltype_defparam_WIDTH = WIDTH *)
550 function [WIDTH-1:0] acc_get;
551 input [2*WIDTH-1:0] acc;
556 y = acc_set(A[0] ? x : 1'b0);
557 for (i = 1; i < WIDTH; i = i+1) begin
558 x = {x[WIDTH-2:0], 1'b0};
559 y = acc_add(y, A[i] ? x : 1'b0);
563 assign Y = acc_get(y);
566 module \$mul (A, B, Y);
567 parameter A_SIGNED = 0;
568 parameter B_SIGNED = 0;
569 parameter A_WIDTH = 1;
570 parameter B_WIDTH = 1;
571 parameter Y_WIDTH = 1;
573 input [A_WIDTH-1:0] A;
574 input [B_WIDTH-1:0] B;
575 output [Y_WIDTH-1:0] Y;
577 wire [1023:0] _TECHMAP_DO_ = "RECURSION; CONSTMAP; opt -purge";
579 wire [Y_WIDTH-1:0] A_buf, B_buf;
580 \$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
581 \$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
585 ) _TECHMAP_REPLACE_ (
593 // --------------------------------------------------------
595 // --------------------------------------------------------
597 module \$__div_mod_u (A, B, Y, R);
600 input [WIDTH-1:0] A, B;
601 output [WIDTH-1:0] Y, R;
603 wire [WIDTH*WIDTH-1:0] chaindata;
604 assign R = chaindata[WIDTH*WIDTH-1:WIDTH*(WIDTH-1)];
608 for (i = 0; i < WIDTH; i=i+1) begin:stage
609 wire [WIDTH-1:0] stage_in;
614 assign stage_in = chaindata[i*WIDTH-1:(i-1)*WIDTH];
617 assign Y[WIDTH-(i+1)] = stage_in >= {B, {WIDTH-(i+1){1'b0}}};
618 assign chaindata[(i+1)*WIDTH-1:i*WIDTH] = Y[WIDTH-(i+1)] ? stage_in - {B, {WIDTH-(i+1){1'b0}}} : stage_in;
623 module \$__div_mod (A, B, Y, R);
624 parameter A_SIGNED = 0;
625 parameter B_SIGNED = 0;
626 parameter A_WIDTH = 1;
627 parameter B_WIDTH = 1;
628 parameter Y_WIDTH = 1;
631 A_WIDTH >= B_WIDTH && A_WIDTH >= Y_WIDTH ? A_WIDTH :
632 B_WIDTH >= A_WIDTH && B_WIDTH >= Y_WIDTH ? B_WIDTH : Y_WIDTH;
634 input [A_WIDTH-1:0] A;
635 input [B_WIDTH-1:0] B;
636 output [Y_WIDTH-1:0] Y, R;
638 wire [WIDTH-1:0] A_buf, B_buf;
639 \$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(WIDTH)) A_conv (.A(A), .Y(A_buf));
640 \$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(WIDTH)) B_conv (.A(B), .Y(B_buf));
642 wire [WIDTH-1:0] A_buf_u, B_buf_u, Y_u, R_u;
643 assign A_buf_u = A_SIGNED && A_buf[WIDTH-1] ? -A_buf : A_buf;
644 assign B_buf_u = B_SIGNED && B_buf[WIDTH-1] ? -B_buf : B_buf;
655 assign Y = A_SIGNED && B_SIGNED && (A_buf[WIDTH-1] != B_buf[WIDTH-1]) ? -Y_u : Y_u;
656 assign R = A_SIGNED && B_SIGNED && A_buf[WIDTH-1] ? -R_u : R_u;
659 module \$div (A, B, Y);
660 parameter A_SIGNED = 0;
661 parameter B_SIGNED = 0;
662 parameter A_WIDTH = 1;
663 parameter B_WIDTH = 1;
664 parameter Y_WIDTH = 1;
666 input [A_WIDTH-1:0] A;
667 input [B_WIDTH-1:0] B;
668 output [Y_WIDTH-1:0] Y;
683 module \$mod (A, B, Y);
684 parameter A_SIGNED = 0;
685 parameter B_SIGNED = 0;
686 parameter A_WIDTH = 1;
687 parameter B_WIDTH = 1;
688 parameter Y_WIDTH = 1;
690 input [A_WIDTH-1:0] A;
691 input [B_WIDTH-1:0] B;
692 output [Y_WIDTH-1:0] Y;
708 // --------------------------------------------------------
710 // --------------------------------------------------------
712 module \$pow (A, B, Y);
713 parameter A_SIGNED = 0;
714 parameter B_SIGNED = 0;
715 parameter A_WIDTH = 1;
716 parameter B_WIDTH = 1;
717 parameter Y_WIDTH = 1;
719 input [A_WIDTH-1:0] A;
720 input [B_WIDTH-1:0] B;
721 output [Y_WIDTH-1:0] Y;
723 wire _TECHMAP_FAIL_ = 1;
727 // --------------------------------------------------------
728 // Equal and Not-Equal
729 // --------------------------------------------------------
731 module \$eq (A, B, Y);
732 parameter A_SIGNED = 0;
733 parameter B_SIGNED = 0;
734 parameter A_WIDTH = 1;
735 parameter B_WIDTH = 1;
736 parameter Y_WIDTH = 1;
738 localparam WIDTH = A_WIDTH > B_WIDTH ? A_WIDTH : B_WIDTH;
740 input [A_WIDTH-1:0] A;
741 input [B_WIDTH-1:0] B;
742 output [Y_WIDTH-1:0] Y;
744 wire carry, carry_sign;
745 wire [WIDTH-1:0] A_buf, B_buf;
746 \$bu0 #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(WIDTH)) A_conv (.A(A), .Y(A_buf));
747 \$bu0 #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(WIDTH)) B_conv (.A(B), .Y(B_buf));
749 assign Y = ~|(A_buf ^ B_buf);
752 module \$ne (A, B, Y);
753 parameter A_SIGNED = 0;
754 parameter B_SIGNED = 0;
755 parameter A_WIDTH = 1;
756 parameter B_WIDTH = 1;
757 parameter Y_WIDTH = 1;
759 localparam WIDTH = A_WIDTH > B_WIDTH ? A_WIDTH : B_WIDTH;
761 input [A_WIDTH-1:0] A;
762 input [B_WIDTH-1:0] B;
763 output [Y_WIDTH-1:0] Y;
765 wire carry, carry_sign;
766 wire [WIDTH-1:0] A_buf, B_buf;
767 \$bu0 #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(WIDTH)) A_conv (.A(A), .Y(A_buf));
768 \$bu0 #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(WIDTH)) B_conv (.A(B), .Y(B_buf));
770 assign Y = |(A_buf ^ B_buf);
773 module \$eqx (A, B, Y);
774 parameter A_SIGNED = 0;
775 parameter B_SIGNED = 0;
776 parameter A_WIDTH = 1;
777 parameter B_WIDTH = 1;
778 parameter Y_WIDTH = 1;
780 localparam WIDTH = A_WIDTH > B_WIDTH ? A_WIDTH : B_WIDTH;
782 input [A_WIDTH-1:0] A;
783 input [B_WIDTH-1:0] B;
784 output [Y_WIDTH-1:0] Y;
786 wire carry, carry_sign;
787 wire [WIDTH-1:0] A_buf, B_buf;
788 \$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(WIDTH)) A_conv (.A(A), .Y(A_buf));
789 \$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(WIDTH)) B_conv (.A(B), .Y(B_buf));
791 assign Y = ~|(A_buf ^ B_buf);
794 module \$nex (A, B, Y);
795 parameter A_SIGNED = 0;
796 parameter B_SIGNED = 0;
797 parameter A_WIDTH = 1;
798 parameter B_WIDTH = 1;
799 parameter Y_WIDTH = 1;
801 localparam WIDTH = A_WIDTH > B_WIDTH ? A_WIDTH : B_WIDTH;
803 input [A_WIDTH-1:0] A;
804 input [B_WIDTH-1:0] B;
805 output [Y_WIDTH-1:0] Y;
807 wire carry, carry_sign;
808 wire [WIDTH-1:0] A_buf, B_buf;
809 \$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(WIDTH)) A_conv (.A(A), .Y(A_buf));
810 \$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(WIDTH)) B_conv (.A(B), .Y(B_buf));
812 assign Y = |(A_buf ^ B_buf);
816 // --------------------------------------------------------
817 // Parallel Multiplexers
818 // --------------------------------------------------------
820 module \$pmux (A, B, S, Y);
822 parameter S_WIDTH = 1;
825 input [WIDTH*S_WIDTH-1:0] B;
826 input [S_WIDTH-1:0] S;
827 output [WIDTH-1:0] Y;
829 wire [WIDTH-1:0] Y_B;
833 wire [WIDTH*S_WIDTH-1:0] B_AND_S;
834 for (i = 0; i < S_WIDTH; i = i + 1) begin:B_AND
835 assign B_AND_S[WIDTH*(i+1)-1:WIDTH*i] = B[WIDTH*(i+1)-1:WIDTH*i] & {WIDTH{S[i]}};
837 for (i = 0; i < WIDTH; i = i + 1) begin:B_OR
838 wire [S_WIDTH-1:0] B_AND_BITS;
839 for (j = 0; j < S_WIDTH; j = j + 1) begin:B_AND_BITS_COLLECT
840 assign B_AND_BITS[j] = B_AND_S[WIDTH*j+i];
841 end:B_AND_BITS_COLLECT
842 assign Y_B[i] = |B_AND_BITS;
846 assign Y = |S ? Y_B : A;