Registers

SR-type latches are represented by $sr cells. These cells have input ports SET and CLR and an output port Q. They have the following parameters:

WIDTH

The width of inputs SET and CLR and output Q.

SET_POLARITY

The set input bits are active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

CLR_POLARITY

The reset input bits are active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

Both set and reset inputs have separate bits for every output bit. When both the set and reset inputs of an $sr cell are active for a given bit index, the reset input takes precedence.

D-type flip-flops are represented by $dff cells. These cells have a clock port CLK, an input port D and an output port Q. The following parameters are available for $dff cells:

WIDTH

The width of input D and output Q.

CLK_POLARITY

Clock is active on the positive edge if this parameter has the value 1'b1 and on the negative edge if this parameter is 1'b0.

D-type flip-flops with asynchronous reset are represented by $adff cells. As the $dff cells they have CLK, D and Q ports. In addition they also have a single-bit ARST input port for the reset pin and the following additional two parameters:

ARST_POLARITY

The asynchronous reset is active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

ARST_VALUE

The state of Q will be set to this value when the reset is active.

Usually these cells are generated by the proc pass using the information in the designs RTLIL::Process objects.

D-type flip-flops with synchronous reset are represented by $sdff cells. As the $dff cells they have CLK, D and Q ports. In addition they also have a single-bit SRST input port for the reset pin and the following additional two parameters:

SRST_POLARITY

The synchronous reset is active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

SRST_VALUE

The state of Q will be set to this value when the reset is active.

Note that the $adff and $sdff cells can only be used when the reset value is constant.

D-type flip-flops with asynchronous load are represented by $aldff cells. As the $dff cells they have CLK, D and Q ports. In addition they also have a single-bit ALOAD input port for the async load enable pin, a AD input port with the same width as data for the async load data, and the following additional parameter:

ALOAD_POLARITY

The asynchronous load is active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

D-type flip-flops with asynchronous set and reset are represented by $dffsr cells. As the $dff cells they have CLK, D and Q ports. In addition they also have multi-bit SET and CLR input ports and the corresponding polarity parameters, like $sr cells.

D-type flip-flops with enable are represented by $dffe, $adffe, $aldffe, $dffsre, $sdffe, and $sdffce cells, which are enhanced variants of $dff, $adff, $aldff, $dffsr, $sdff (with reset over enable) and $sdff (with enable over reset) cells, respectively. They have the same ports and parameters as their base cell. In addition they also have a single-bit EN input port for the enable pin and the following parameter:

EN_POLARITY

The enable input is active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

D-type latches are represented by $dlatch cells. These cells have an enable port EN, an input port D, and an output port Q. The following parameters are available for $dlatch cells:

WIDTH

The width of input D and output Q.

EN_POLARITY

The enable input is active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

The latch is transparent when the EN input is active.

D-type latches with reset are represented by $adlatch cells. In addition to $dlatch ports and parameters, they also have a single-bit ARST input port for the reset pin and the following additional parameters:

ARST_POLARITY

The asynchronous reset is active-high if this parameter has the value 1'b1 and active-low if this parameter is 1'b0.

ARST_VALUE

The state of Q will be set to this value when the reset is active.

D-type latches with set and reset are represented by $dlatchsr cells. In addition to $dlatch ports and parameters, they also have multi-bit SET and CLR input ports and the corresponding polarity parameters, like $sr cells.

yosys> help $adff
Simulation model (verilog)
Listing 159 simlib.v
2309module \$adff (CLK, ARST, D, Q);
2310
2311    parameter WIDTH = 0;
2312    parameter CLK_POLARITY = 1'b1;
2313    parameter ARST_POLARITY = 1'b1;
2314    parameter ARST_VALUE = 0;
2315
2316    input CLK, ARST;
2317    input [WIDTH-1:0] D;
2318    output reg [WIDTH-1:0] Q;
2319    wire pos_clk = CLK == CLK_POLARITY;
2320    wire pos_arst = ARST == ARST_POLARITY;
2321
2322    always @(posedge pos_clk, posedge pos_arst) begin
2323        if (pos_arst)
2324            Q <= ARST_VALUE;
2325        else
2326            Q <= D;
2327    end
2328
2329endmodule
yosys> help $adffe
Simulation model (verilog)
Listing 160 simlib.v
2384module \$adffe (CLK, ARST, EN, D, Q);
2385
2386    parameter WIDTH = 0;
2387    parameter CLK_POLARITY = 1'b1;
2388    parameter EN_POLARITY = 1'b1;
2389    parameter ARST_POLARITY = 1'b1;
2390    parameter ARST_VALUE = 0;
2391
2392    input CLK, ARST, EN;
2393    input [WIDTH-1:0] D;
2394    output reg [WIDTH-1:0] Q;
2395    wire pos_clk = CLK == CLK_POLARITY;
2396    wire pos_arst = ARST == ARST_POLARITY;
2397
2398    always @(posedge pos_clk, posedge pos_arst) begin
2399        if (pos_arst)
2400            Q <= ARST_VALUE;
2401        else if (EN == EN_POLARITY)
2402            Q <= D;
2403    end
2404
2405endmodule
yosys> help $adlatch
Simulation model (verilog)
Listing 161 simlib.v
2509module \$adlatch (EN, ARST, D, Q);
2510
2511    parameter WIDTH = 0;
2512    parameter EN_POLARITY = 1'b1;
2513    parameter ARST_POLARITY = 1'b1;
2514    parameter ARST_VALUE = 0;
2515
2516    input EN, ARST;
2517    input [WIDTH-1:0] D;
2518    output reg [WIDTH-1:0] Q;
2519
2520    always @* begin
2521        if (ARST == ARST_POLARITY)
2522            Q = ARST_VALUE;
2523        else if (EN == EN_POLARITY)
2524            Q = D;
2525    end
2526
2527endmodule
yosys> help $aldff
Simulation model (verilog)
Listing 162 simlib.v
2334module \$aldff (CLK, ALOAD, AD, D, Q);
2335
2336    parameter WIDTH = 0;
2337    parameter CLK_POLARITY = 1'b1;
2338    parameter ALOAD_POLARITY = 1'b1;
2339
2340    input CLK, ALOAD;
2341    input [WIDTH-1:0] AD;
2342    input [WIDTH-1:0] D;
2343    output reg [WIDTH-1:0] Q;
2344    wire pos_clk = CLK == CLK_POLARITY;
2345    wire pos_aload = ALOAD == ALOAD_POLARITY;
2346
2347    always @(posedge pos_clk, posedge pos_aload) begin
2348        if (pos_aload)
2349            Q <= AD;
2350        else
2351            Q <= D;
2352    end
2353
2354endmodule
yosys> help $aldffe
Simulation model (verilog)
Listing 163 simlib.v
2410module \$aldffe (CLK, ALOAD, AD, EN, D, Q);
2411
2412    parameter WIDTH = 0;
2413    parameter CLK_POLARITY = 1'b1;
2414    parameter EN_POLARITY = 1'b1;
2415    parameter ALOAD_POLARITY = 1'b1;
2416
2417    input CLK, ALOAD, EN;
2418    input [WIDTH-1:0] D;
2419    input [WIDTH-1:0] AD;
2420    output reg [WIDTH-1:0] Q;
2421    wire pos_clk = CLK == CLK_POLARITY;
2422    wire pos_aload = ALOAD == ALOAD_POLARITY;
2423
2424    always @(posedge pos_clk, posedge pos_aload) begin
2425        if (pos_aload)
2426            Q <= AD;
2427        else if (EN == EN_POLARITY)
2428            Q <= D;
2429    end
2430
2431endmodule
yosys> help $dff
Simulation model (verilog)
Listing 164 simlib.v
2201module \$dff (CLK, D, Q);
2202
2203    parameter WIDTH = 0;
2204    parameter CLK_POLARITY = 1'b1;
2205
2206    input CLK;
2207    input [WIDTH-1:0] D;
2208    output reg [WIDTH-1:0] Q;
2209    wire pos_clk = CLK == CLK_POLARITY;
2210
2211    always @(posedge pos_clk) begin
2212        Q <= D;
2213    end
2214
2215endmodule
yosys> help $dffe
Simulation model (verilog)
Listing 165 simlib.v
2220module \$dffe (CLK, EN, D, Q);
2221
2222    parameter WIDTH = 0;
2223    parameter CLK_POLARITY = 1'b1;
2224    parameter EN_POLARITY = 1'b1;
2225
2226    input CLK, EN;
2227    input [WIDTH-1:0] D;
2228    output reg [WIDTH-1:0] Q;
2229    wire pos_clk = CLK == CLK_POLARITY;
2230
2231    always @(posedge pos_clk) begin
2232        if (EN == EN_POLARITY) Q <= D;
2233    end
2234
2235endmodule
yosys> help $dffsr
Simulation model (verilog)
Listing 166 simlib.v
2241module \$dffsr (CLK, SET, CLR, D, Q);
2242
2243    parameter WIDTH = 0;
2244    parameter CLK_POLARITY = 1'b1;
2245    parameter SET_POLARITY = 1'b1;
2246    parameter CLR_POLARITY = 1'b1;
2247
2248    input CLK;
2249    input [WIDTH-1:0] SET, CLR, D;
2250    output reg [WIDTH-1:0] Q;
2251
2252    wire pos_clk = CLK == CLK_POLARITY;
2253    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2254    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2255
2256    genvar i;
2257    generate
2258        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2259            always @(posedge pos_set[i], posedge pos_clr[i], posedge pos_clk)
2260                if (pos_clr[i])
2261                    Q[i] <= 0;
2262                else if (pos_set[i])
2263                    Q[i] <= 1;
2264                else
2265                    Q[i] <= D[i];
2266        end
2267    endgenerate
2268
2269endmodule
yosys> help $dffsre
Simulation model (verilog)
Listing 167 simlib.v
2274module \$dffsre (CLK, SET, CLR, EN, D, Q);
2275
2276    parameter WIDTH = 0;
2277    parameter CLK_POLARITY = 1'b1;
2278    parameter SET_POLARITY = 1'b1;
2279    parameter CLR_POLARITY = 1'b1;
2280    parameter EN_POLARITY = 1'b1;
2281
2282    input CLK, EN;
2283    input [WIDTH-1:0] SET, CLR, D;
2284    output reg [WIDTH-1:0] Q;
2285
2286    wire pos_clk = CLK == CLK_POLARITY;
2287    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2288    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2289
2290    genvar i;
2291    generate
2292        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2293            always @(posedge pos_set[i], posedge pos_clr[i], posedge pos_clk)
2294                if (pos_clr[i])
2295                    Q[i] <= 0;
2296                else if (pos_set[i])
2297                    Q[i] <= 1;
2298                else if (EN == EN_POLARITY)
2299                    Q[i] <= D[i];
2300        end
2301    endgenerate
2302
2303endmodule
yosys> help $dlatch
Simulation model (verilog)
Listing 168 simlib.v
2490module \$dlatch (EN, D, Q);
2491
2492    parameter WIDTH = 0;
2493    parameter EN_POLARITY = 1'b1;
2494
2495    input EN;
2496    input [WIDTH-1:0] D;
2497    output reg [WIDTH-1:0] Q;
2498
2499    always @* begin
2500        if (EN == EN_POLARITY)
2501            Q = D;
2502    end
2503
2504endmodule
yosys> help $dlatchsr
Simulation model (verilog)
Listing 169 simlib.v
2533module \$dlatchsr (EN, SET, CLR, D, Q);
2534
2535    parameter WIDTH = 0;
2536    parameter EN_POLARITY = 1'b1;
2537    parameter SET_POLARITY = 1'b1;
2538    parameter CLR_POLARITY = 1'b1;
2539
2540    input EN;
2541    input [WIDTH-1:0] SET, CLR, D;
2542    output reg [WIDTH-1:0] Q;
2543
2544    wire pos_en = EN == EN_POLARITY;
2545    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2546    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2547
2548    genvar i;
2549    generate
2550        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2551            always @*
2552                if (pos_clr[i])
2553                    Q[i] = 0;
2554                else if (pos_set[i])
2555                    Q[i] = 1;
2556                else if (pos_en)
2557                    Q[i] = D[i];
2558        end
2559    endgenerate
2560
2561endmodule
yosys> help $sdff
Simulation model (verilog)
Listing 170 simlib.v
2359module \$sdff (CLK, SRST, D, Q);
2360
2361    parameter WIDTH = 0;
2362    parameter CLK_POLARITY = 1'b1;
2363    parameter SRST_POLARITY = 1'b1;
2364    parameter SRST_VALUE = 0;
2365
2366    input CLK, SRST;
2367    input [WIDTH-1:0] D;
2368    output reg [WIDTH-1:0] Q;
2369    wire pos_clk = CLK == CLK_POLARITY;
2370    wire pos_srst = SRST == SRST_POLARITY;
2371
2372    always @(posedge pos_clk) begin
2373        if (pos_srst)
2374            Q <= SRST_VALUE;
2375        else
2376            Q <= D;
2377    end
2378
2379endmodule
yosys> help $sdffce
Simulation model (verilog)
Listing 171 simlib.v
2462module \$sdffce (CLK, SRST, EN, D, Q);
2463
2464    parameter WIDTH = 0;
2465    parameter CLK_POLARITY = 1'b1;
2466    parameter EN_POLARITY = 1'b1;
2467    parameter SRST_POLARITY = 1'b1;
2468    parameter SRST_VALUE = 0;
2469
2470    input CLK, SRST, EN;
2471    input [WIDTH-1:0] D;
2472    output reg [WIDTH-1:0] Q;
2473    wire pos_clk = CLK == CLK_POLARITY;
2474    wire pos_srst = SRST == SRST_POLARITY;
2475
2476    always @(posedge pos_clk) begin
2477        if (EN == EN_POLARITY) begin
2478            if (pos_srst)
2479                Q <= SRST_VALUE;
2480            else
2481                Q <= D;
2482        end
2483    end
2484
2485endmodule
yosys> help $sdffe
Simulation model (verilog)
Listing 172 simlib.v
2436module \$sdffe (CLK, SRST, EN, D, Q);
2437
2438    parameter WIDTH = 0;
2439    parameter CLK_POLARITY = 1'b1;
2440    parameter EN_POLARITY = 1'b1;
2441    parameter SRST_POLARITY = 1'b1;
2442    parameter SRST_VALUE = 0;
2443
2444    input CLK, SRST, EN;
2445    input [WIDTH-1:0] D;
2446    output reg [WIDTH-1:0] Q;
2447    wire pos_clk = CLK == CLK_POLARITY;
2448    wire pos_srst = SRST == SRST_POLARITY;
2449
2450    always @(posedge pos_clk) begin
2451        if (pos_srst)
2452            Q <= SRST_VALUE;
2453        else if (EN == EN_POLARITY)
2454            Q <= D;
2455    end
2456
2457endmodule
yosys> help $sr
Simulation model (verilog)
Listing 173 simlib.v
2151module \$sr (SET, CLR, Q);
2152
2153    parameter WIDTH = 0;
2154    parameter SET_POLARITY = 1'b1;
2155    parameter CLR_POLARITY = 1'b1;
2156
2157    input [WIDTH-1:0] SET, CLR;
2158    output reg [WIDTH-1:0] Q;
2159
2160    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2161    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2162
2163    genvar i;
2164    generate
2165        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2166            always @*
2167                if (pos_clr[i])
2168                    Q[i] <= 0;
2169                else if (pos_set[i])
2170                    Q[i] <= 1;
2171        end
2172    endgenerate
2173
2174endmodule