addr_bits++;
cell->connections["\\CLK"] = RTLIL::SigSpec(RTLIL::State::Sx, 1);
- cell->connections["\\ADDR"] = children[0]->genRTLIL();
+ cell->connections["\\ADDR"] = children[0]->genWidthRTLIL(addr_bits);
cell->connections["\\DATA"] = RTLIL::SigSpec(wire);
cell->parameters["\\MEMID"] = RTLIL::Const(str);
addr_bits++;
cell->connections["\\CLK"] = RTLIL::SigSpec(RTLIL::State::Sx, 1);
- cell->connections["\\ADDR"] = children[0]->genRTLIL();
- cell->connections["\\DATA"] = children[1]->genRTLIL();
+ cell->connections["\\ADDR"] = children[0]->genWidthRTLIL(addr_bits);
+ cell->connections["\\DATA"] = children[1]->genWidthRTLIL(current_module->memories[str]->width);
cell->connections["\\EN"] = children[2]->genRTLIL();
+ if (cell->connections["\\EN"].width > 1)
+ cell->connections["\\EN"] = uniop2rtlil(this, "$reduce_bool", 1, cell->connections["\\EN"], false);
+
cell->parameters["\\MEMID"] = RTLIL::Const(str);
cell->parameters["\\ABITS"] = RTLIL::Const(addr_bits);
cell->parameters["\\WIDTH"] = RTLIL::Const(current_module->memories[str]->width);
parameter MEMID = "";
parameter SIZE = 256;
+parameter OFFSET = 0;
parameter ABITS = 8;
parameter WIDTH = 8;
for (i = 0; i < RD_PORTS; i = i+1) begin:rd
if (RD_CLK_ENABLE[i] == 0) begin:rd_noclk
always @(RD_ADDR or update_async_rd)
- RD_DATA[ (i+1)*WIDTH-1 : i*WIDTH ] <= data[ RD_ADDR[ (i+1)*ABITS-1 : i*ABITS ] ];
+ RD_DATA[ (i+1)*WIDTH-1 : i*WIDTH ] <= data[ RD_ADDR[ (i+1)*ABITS-1 : i*ABITS ] - OFFSET ];
end else
if (RD_CLK_POLARITY[i] == 1) begin:rd_posclk
always @(posedge RD_CLK[i])
- RD_DATA[ (i+1)*WIDTH-1 : i*WIDTH ] <= data[ RD_ADDR[ (i+1)*ABITS-1 : i*ABITS ] ];
+ RD_DATA[ (i+1)*WIDTH-1 : i*WIDTH ] <= data[ RD_ADDR[ (i+1)*ABITS-1 : i*ABITS ] - OFFSET ];
end else begin:rd_negclk
always @(negedge RD_CLK[i])
- RD_DATA[ (i+1)*WIDTH-1 : i*WIDTH ] <= data[ RD_ADDR[ (i+1)*ABITS-1 : i*ABITS ] ];
+ RD_DATA[ (i+1)*WIDTH-1 : i*WIDTH ] <= data[ RD_ADDR[ (i+1)*ABITS-1 : i*ABITS ] - OFFSET ];
end
end
if (WR_CLK_ENABLE[i] == 0) begin:wr_noclk
always @(WR_ADDR or WR_DATA or WR_EN) begin
if (WR_EN[i]) begin
- data[ WR_ADDR[ (i+1)*ABITS-1 : i*ABITS ] ] <= WR_DATA[ (i+1)*WIDTH-1 : i*WIDTH ];
+ data[ WR_ADDR[ (i+1)*ABITS-1 : i*ABITS ] - OFFSET ] <= WR_DATA[ (i+1)*WIDTH-1 : i*WIDTH ];
#1 -> update_async_rd;
end
end
if (RD_CLK_POLARITY[i] == 1) begin:rd_posclk
always @(posedge WR_CLK[i])
if (WR_EN[i]) begin
- data[ WR_ADDR[ (i+1)*ABITS-1 : i*ABITS ] ] <= WR_DATA[ (i+1)*WIDTH-1 : i*WIDTH ];
+ data[ WR_ADDR[ (i+1)*ABITS-1 : i*ABITS ] - OFFSET ] <= WR_DATA[ (i+1)*WIDTH-1 : i*WIDTH ];
#1 -> update_async_rd;
end
end else begin:rd_negclk
always @(negedge WR_CLK[i])
if (WR_EN[i]) begin
- data[ WR_ADDR[ (i+1)*ABITS-1 : i*ABITS ] ] <= WR_DATA[ (i+1)*WIDTH-1 : i*WIDTH ];
+ data[ WR_ADDR[ (i+1)*ABITS-1 : i*ABITS ] - OFFSET ] <= WR_DATA[ (i+1)*WIDTH-1 : i*WIDTH ];
#1 -> update_async_rd;
end
end
.B_WIDTH(A_WIDTH),
.Y_WIDTH(Y_WIDTH)
) sub (
- .A(0),
+ .A(1'b0),
.B(A),
.Y(Y)
);
// --------------------------------------------------------
-module \$shift (X, A, Y);
+module \$__shift (X, A, Y);
parameter WIDTH = 1;
parameter SHIFT = 0;
wire [WIDTH-1:0] unshifted, shifted, result;
assign unshifted = chain[WIDTH*i + WIDTH-1 : WIDTH*i];
assign chain[WIDTH*(i+1) + WIDTH-1 : WIDTH*(i+1)] = result;
- \$shift #(
+ \$__shift #(
.WIDTH(WIDTH),
.SHIFT(0 - (2 ** (i > 30 ? 30 : i)))
) sh (
wire [WIDTH-1:0] unshifted, shifted, result;
assign unshifted = chain[WIDTH*i + WIDTH-1 : WIDTH*i];
assign chain[WIDTH*(i+1) + WIDTH-1 : WIDTH*(i+1)] = result;
- \$shift #(
+ \$__shift #(
.WIDTH(WIDTH),
.SHIFT(2 ** (i > 30 ? 30 : i))
) sh (
wire [WIDTH-1:0] unshifted, shifted, result;
assign unshifted = chain[WIDTH*i + WIDTH-1 : WIDTH*i];
assign chain[WIDTH*(i+1) + WIDTH-1 : WIDTH*(i+1)] = result;
- \$shift #(
+ \$__shift #(
.WIDTH(WIDTH),
.SHIFT(0 - (2 ** (i > 30 ? 30 : i)))
) sh (
wire [WIDTH-1:0] unshifted, shifted, result;
assign unshifted = chain[WIDTH*i + WIDTH-1 : WIDTH*i];
assign chain[WIDTH*(i+1) + WIDTH-1 : WIDTH*(i+1)] = result;
- \$shift #(
+ \$__shift #(
.WIDTH(WIDTH),
.SHIFT(2 ** (i > 30 ? 30 : i))
) sh (
// --------------------------------------------------------
-module \$fulladd (A, B, C, X, Y);
+module \$__fulladd (A, B, C, X, Y);
// {X, Y} = A + B + C
input A, B, C;
// --------------------------------------------------------
-module \$alu (A, B, Cin, Y, Cout, Csign);
+module \$__alu (A, B, Cin, Y, Cout, Csign);
parameter WIDTH = 1;
genvar i;
generate
for (i = 0; i < WIDTH; i = i + 1) begin:V
- \$fulladd adder (
+ \$__fulladd adder (
.A(A[i]),
.B(B[i]),
.C(carry[i]),
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(WIDTH)) A_conv (.A(A), .Y(A_buf));
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(WIDTH)) B_conv (.A(B), .Y(B_buf));
-\$alu #(
+\$__alu #(
.WIDTH(WIDTH)
) alu (
.A(A_buf),
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(WIDTH)) A_conv (.A(A), .Y(A_buf));
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(WIDTH)) B_conv (.A(B), .Y(B_buf));
-\$alu #(
+\$__alu #(
.WIDTH(WIDTH)
) alu (
.A(A_buf),
.A_SIGNED(B_SIGNED),
.B_SIGNED(A_SIGNED),
.A_WIDTH(B_WIDTH),
- .B_WIDTH(A_WIDTH)
+ .B_WIDTH(A_WIDTH),
+ .Y_WIDTH(Y_WIDTH)
) ge_via_le (
.A(B),
.B(A),
- .Y(Y[0])
+ .Y(Y)
);
-generate
- if (Y_WIDTH > 1) begin:V
- assign Y[Y_WIDTH-1:1] = 0;
- end
-endgenerate
-
endmodule
// --------------------------------------------------------
.A_SIGNED(B_SIGNED),
.B_SIGNED(A_SIGNED),
.A_WIDTH(B_WIDTH),
- .B_WIDTH(A_WIDTH)
+ .B_WIDTH(A_WIDTH),
+ .Y_WIDTH(Y_WIDTH)
) gt_via_lt (
.A(B),
.B(A),
- .Y(Y[0])
+ .Y(Y)
);
-generate
- if (Y_WIDTH > 1) begin:V
- assign Y[Y_WIDTH-1:1] = 0;
- end
-endgenerate
-
endmodule
// --------------------------------------------------------
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
-\$alu #(
+\$__alu #(
.WIDTH(Y_WIDTH)
) alu (
.A(A_buf),
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
-\$alu #(
+\$__alu #(
.WIDTH(Y_WIDTH)
) alu (
.A(A_buf),
// --------------------------------------------------------
-module \$arraymul (A, B, Y);
+module \$__arraymul (A, B, Y);
parameter WIDTH = 8;
input [WIDTH-1:0] A, B;
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
\$pos #(.A_SIGNED(A_SIGNED && B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
-\$arraymul #(
+\$__arraymul #(
.WIDTH(Y_WIDTH)
) arraymul (
.A(A_buf),
// --------------------------------------------------------
-module \$div_mod_u (A, B, Y, R);
+module \$__div_mod_u (A, B, Y, R);
parameter WIDTH = 1;
// --------------------------------------------------------
-module \$div_mod (A, B, Y, R);
+module \$__div_mod (A, B, Y, R);
parameter A_SIGNED = 0;
parameter B_SIGNED = 0;
assign A_buf_u = A_SIGNED && B_SIGNED && A_buf[WIDTH-1] ? -A_buf : A_buf;
assign B_buf_u = A_SIGNED && B_SIGNED && B_buf[WIDTH-1] ? -B_buf : B_buf;
-\$div_mod_u #(
+\$__div_mod_u #(
.WIDTH(WIDTH)
) div_mod_u (
.A(A_buf_u),
wire [Y_WIDTH-1:0] Y_buf;
wire [Y_WIDTH-1:0] Y_div_zero;
-\$div_mod #(
+\$__div_mod #(
.A_SIGNED(A_SIGNED),
.B_SIGNED(B_SIGNED),
.A_WIDTH(A_WIDTH),
wire [Y_WIDTH-1:0] Y_buf;
wire [Y_WIDTH-1:0] Y_div_zero;
-\$div_mod #(
+\$__div_mod #(
.A_SIGNED(A_SIGNED),
.B_SIGNED(B_SIGNED),
.A_WIDTH(A_WIDTH),
\$reduce_bool #(
.A_SIGNED(A_SIGNED),
- .A_WIDTH(A_WIDTH)
+ .A_WIDTH(A_WIDTH),
+ .Y_WIDTH(1)
) A_logic (
.A(A),
.Y(A_buf)
\$reduce_bool #(
.A_SIGNED(A_SIGNED),
- .A_WIDTH(A_WIDTH)
+ .A_WIDTH(A_WIDTH),
+ .Y_WIDTH(1)
) A_logic (
.A(A),
.Y(A_buf)
\$reduce_bool #(
.A_SIGNED(B_SIGNED),
- .A_WIDTH(B_WIDTH)
+ .A_WIDTH(B_WIDTH),
+ .Y_WIDTH(1)
) B_logic (
.A(B),
.Y(B_buf)
\$reduce_bool #(
.A_SIGNED(A_SIGNED),
- .A_WIDTH(A_WIDTH)
+ .A_WIDTH(A_WIDTH),
+ .Y_WIDTH(1)
) A_logic (
.A(A),
.Y(A_buf)
\$reduce_bool #(
.A_SIGNED(B_SIGNED),
- .A_WIDTH(B_WIDTH)
+ .A_WIDTH(B_WIDTH),
+ .Y_WIDTH(1)
) B_logic (
.A(B),
.Y(B_buf)