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 // ============================================================================
23 (* techmap_celltype = "$lcu" *)
24 module _80_xilinx_lcu (P, G, CI, CO);
28 input [WIDTH-1:0] P, G;
32 output [WIDTH-1:0] CO;
34 wire _TECHMAP_FAIL_ = WIDTH <= 2;
38 `ifdef _EXPLICIT_CARRY
39 localparam EXPLICIT_CARRY = 1'b1;
41 localparam EXPLICIT_CARRY = 1'b0;
44 generate if (EXPLICIT_CARRY || `LUT_SIZE == 4) begin
47 wire [WIDTH-1:0] C = {CO, CI};
49 wire [WIDTH-1:0] S = P & ~G;
51 generate for (i = 0; i < WIDTH; i = i + 1) begin:slice
62 localparam CARRY4_COUNT = (WIDTH + 3) / 4;
63 localparam MAX_WIDTH = CARRY4_COUNT * 4;
64 localparam PAD_WIDTH = MAX_WIDTH - WIDTH;
67 wire [MAX_WIDTH-1:0] S = {{PAD_WIDTH{1'b0}}, P & ~G};
69 wire [MAX_WIDTH-1:0] GG = {{PAD_WIDTH{1'b0}}, G};
71 wire [MAX_WIDTH-1:0] C;
74 generate for (i = 0; i < CARRY4_COUNT; i = i + 1) begin:slice
100 // ============================================================================
103 (* techmap_celltype = "$alu" *)
104 module _80_xilinx_alu (A, B, CI, BI, X, Y, CO);
105 parameter A_SIGNED = 0;
106 parameter B_SIGNED = 0;
107 parameter A_WIDTH = 1;
108 parameter B_WIDTH = 1;
109 parameter Y_WIDTH = 1;
110 parameter _TECHMAP_CONSTVAL_CI_ = 0;
111 parameter _TECHMAP_CONSTMSK_CI_ = 0;
114 input [A_WIDTH-1:0] A;
116 input [B_WIDTH-1:0] B;
118 output [Y_WIDTH-1:0] X, Y;
122 output [Y_WIDTH-1:0] CO;
124 wire _TECHMAP_FAIL_ = Y_WIDTH <= 2;
127 wire [Y_WIDTH-1:0] A_buf, B_buf;
128 \$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
129 \$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
132 wire [Y_WIDTH-1:0] AA = A_buf;
134 wire [Y_WIDTH-1:0] BB = BI ? ~B_buf : B_buf;
138 `ifdef _EXPLICIT_CARRY
139 localparam EXPLICIT_CARRY = 1'b1;
141 localparam EXPLICIT_CARRY = 1'b0;
144 generate if (`LUT_SIZE == 4) begin
147 wire [Y_WIDTH-1:0] C = {CO, CI};
149 wire [Y_WIDTH-1:0] S = {AA ^ BB};
152 generate for (i = 0; i < Y_WIDTH; i = i + 1) begin:slice
166 end else if (EXPLICIT_CARRY) begin
169 wire [Y_WIDTH-1:0] S = AA ^ BB;
174 // VPR requires that the carry chain never hit the fabric. The CO input
175 // to this techmap is the carry outputs for synthesis, e.g. might hit the
178 // So we maintain two wire sets, CO_CHAIN is the carry that is for VPR,
179 // e.g. off fabric dedicated chain. CO is the carry outputs that are
180 // available to the fabric.
182 wire [Y_WIDTH-1:0] CO_CHAIN;
184 wire [Y_WIDTH-1:0] C = {CO_CHAIN, CINIT};
186 // If carry chain is being initialized to a constant, techmap the constant
187 // source. Otherwise techmap the fabric source.
188 generate for (i = 0; i < 1; i = i + 1) begin:slice
189 CARRY0 #(.CYINIT_FABRIC(1)) carry(
193 .CO_CHAIN(CO_CHAIN[0]),
199 generate for (i = 1; i < Y_WIDTH-1; i = i + 1) begin:slice
205 .CO_CHAIN(CO_CHAIN[i]),
216 .CO_CHAIN(CO_CHAIN[i]),
223 generate for (i = Y_WIDTH-1; i < Y_WIDTH; i = i + 1) begin:slice
225 CARRY0 top_of_carry (
229 .CO_CHAIN(CO_CHAIN[i]),
239 .CO_CHAIN(CO_CHAIN[i]),
243 // Turns out CO_FABRIC and O both use [ABCD]MUX, so provide
244 // a non-congested path to output the top of the carry chain.
245 // Registering the output of the CARRY block would solve this, but not
246 // all designs do that.
247 if((i+1) % 4 == 0) begin
248 CARRY0 carry_output (
268 localparam CARRY4_COUNT = (Y_WIDTH + 3) / 4;
269 localparam MAX_WIDTH = CARRY4_COUNT * 4;
270 localparam PAD_WIDTH = MAX_WIDTH - Y_WIDTH;
273 wire [MAX_WIDTH-1:0] S = {{PAD_WIDTH{1'b0}}, AA ^ BB};
275 wire [MAX_WIDTH-1:0] DI = {{PAD_WIDTH{1'b0}}, AA};
278 wire [MAX_WIDTH-1:0] O;
280 wire [MAX_WIDTH-1:0] C;
281 assign Y = O, CO = C;
284 generate for (i = 0; i < CARRY4_COUNT; i = i + 1) begin:slice