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 180 simlib.v
2423module \$adff (CLK, ARST, D, Q);
2424
2425    parameter WIDTH = 0;
2426    parameter CLK_POLARITY = 1'b1;
2427    parameter ARST_POLARITY = 1'b1;
2428    parameter ARST_VALUE = 0;
2429
2430    input CLK, ARST;
2431    input [WIDTH-1:0] D;
2432    output reg [WIDTH-1:0] Q;
2433    wire pos_clk = CLK == CLK_POLARITY;
2434    wire pos_arst = ARST == ARST_POLARITY;
2435
2436    always @(posedge pos_clk, posedge pos_arst) begin
2437        if (pos_arst)
2438            Q <= ARST_VALUE;
2439        else
2440            Q <= D;
2441    end
2442
2443endmodule
yosys> help $adffe
Simulation model (verilog)
Listing 181 simlib.v
2498module \$adffe (CLK, ARST, EN, D, Q);
2499
2500    parameter WIDTH = 0;
2501    parameter CLK_POLARITY = 1'b1;
2502    parameter EN_POLARITY = 1'b1;
2503    parameter ARST_POLARITY = 1'b1;
2504    parameter ARST_VALUE = 0;
2505
2506    input CLK, ARST, EN;
2507    input [WIDTH-1:0] D;
2508    output reg [WIDTH-1:0] Q;
2509    wire pos_clk = CLK == CLK_POLARITY;
2510    wire pos_arst = ARST == ARST_POLARITY;
2511
2512    always @(posedge pos_clk, posedge pos_arst) begin
2513        if (pos_arst)
2514            Q <= ARST_VALUE;
2515        else if (EN == EN_POLARITY)
2516            Q <= D;
2517    end
2518
2519endmodule
yosys> help $adlatch
Simulation model (verilog)
Listing 182 simlib.v
2623module \$adlatch (EN, ARST, D, Q);
2624
2625    parameter WIDTH = 0;
2626    parameter EN_POLARITY = 1'b1;
2627    parameter ARST_POLARITY = 1'b1;
2628    parameter ARST_VALUE = 0;
2629
2630    input EN, ARST;
2631    input [WIDTH-1:0] D;
2632    output reg [WIDTH-1:0] Q;
2633
2634    always @* begin
2635        if (ARST == ARST_POLARITY)
2636            Q = ARST_VALUE;
2637        else if (EN == EN_POLARITY)
2638            Q = D;
2639    end
2640
2641endmodule
yosys> help $aldff
Simulation model (verilog)
Listing 183 simlib.v
2448module \$aldff (CLK, ALOAD, AD, D, Q);
2449
2450    parameter WIDTH = 0;
2451    parameter CLK_POLARITY = 1'b1;
2452    parameter ALOAD_POLARITY = 1'b1;
2453
2454    input CLK, ALOAD;
2455    input [WIDTH-1:0] AD;
2456    input [WIDTH-1:0] D;
2457    output reg [WIDTH-1:0] Q;
2458    wire pos_clk = CLK == CLK_POLARITY;
2459    wire pos_aload = ALOAD == ALOAD_POLARITY;
2460
2461    always @(posedge pos_clk, posedge pos_aload) begin
2462        if (pos_aload)
2463            Q <= AD;
2464        else
2465            Q <= D;
2466    end
2467
2468endmodule
yosys> help $aldffe
Simulation model (verilog)
Listing 184 simlib.v
2524module \$aldffe (CLK, ALOAD, AD, EN, D, Q);
2525
2526    parameter WIDTH = 0;
2527    parameter CLK_POLARITY = 1'b1;
2528    parameter EN_POLARITY = 1'b1;
2529    parameter ALOAD_POLARITY = 1'b1;
2530
2531    input CLK, ALOAD, EN;
2532    input [WIDTH-1:0] D;
2533    input [WIDTH-1:0] AD;
2534    output reg [WIDTH-1:0] Q;
2535    wire pos_clk = CLK == CLK_POLARITY;
2536    wire pos_aload = ALOAD == ALOAD_POLARITY;
2537
2538    always @(posedge pos_clk, posedge pos_aload) begin
2539        if (pos_aload)
2540            Q <= AD;
2541        else if (EN == EN_POLARITY)
2542            Q <= D;
2543    end
2544
2545endmodule
yosys> help $dff
Simulation model (verilog)
Listing 185 simlib.v
2315module \$dff (CLK, D, Q);
2316
2317    parameter WIDTH = 0;
2318    parameter CLK_POLARITY = 1'b1;
2319
2320    input CLK;
2321    input [WIDTH-1:0] D;
2322    output reg [WIDTH-1:0] Q;
2323    wire pos_clk = CLK == CLK_POLARITY;
2324
2325    always @(posedge pos_clk) begin
2326        Q <= D;
2327    end
2328
2329endmodule
yosys> help $dffe
Simulation model (verilog)
Listing 186 simlib.v
2334module \$dffe (CLK, EN, D, Q);
2335
2336    parameter WIDTH = 0;
2337    parameter CLK_POLARITY = 1'b1;
2338    parameter EN_POLARITY = 1'b1;
2339
2340    input CLK, EN;
2341    input [WIDTH-1:0] D;
2342    output reg [WIDTH-1:0] Q;
2343    wire pos_clk = CLK == CLK_POLARITY;
2344
2345    always @(posedge pos_clk) begin
2346        if (EN == EN_POLARITY) Q <= D;
2347    end
2348
2349endmodule
yosys> help $dffsr
Simulation model (verilog)
Listing 187 simlib.v
2355module \$dffsr (CLK, SET, CLR, D, Q);
2356
2357    parameter WIDTH = 0;
2358    parameter CLK_POLARITY = 1'b1;
2359    parameter SET_POLARITY = 1'b1;
2360    parameter CLR_POLARITY = 1'b1;
2361
2362    input CLK;
2363    input [WIDTH-1:0] SET, CLR, D;
2364    output reg [WIDTH-1:0] Q;
2365
2366    wire pos_clk = CLK == CLK_POLARITY;
2367    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2368    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2369
2370    genvar i;
2371    generate
2372        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2373            always @(posedge pos_set[i], posedge pos_clr[i], posedge pos_clk)
2374                if (pos_clr[i])
2375                    Q[i] <= 0;
2376                else if (pos_set[i])
2377                    Q[i] <= 1;
2378                else
2379                    Q[i] <= D[i];
2380        end
2381    endgenerate
2382
2383endmodule
yosys> help $dffsre
Simulation model (verilog)
Listing 188 simlib.v
2388module \$dffsre (CLK, SET, CLR, EN, D, Q);
2389
2390    parameter WIDTH = 0;
2391    parameter CLK_POLARITY = 1'b1;
2392    parameter SET_POLARITY = 1'b1;
2393    parameter CLR_POLARITY = 1'b1;
2394    parameter EN_POLARITY = 1'b1;
2395
2396    input CLK, EN;
2397    input [WIDTH-1:0] SET, CLR, D;
2398    output reg [WIDTH-1:0] Q;
2399
2400    wire pos_clk = CLK == CLK_POLARITY;
2401    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2402    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2403
2404    genvar i;
2405    generate
2406        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2407            always @(posedge pos_set[i], posedge pos_clr[i], posedge pos_clk)
2408                if (pos_clr[i])
2409                    Q[i] <= 0;
2410                else if (pos_set[i])
2411                    Q[i] <= 1;
2412                else if (EN == EN_POLARITY)
2413                    Q[i] <= D[i];
2414        end
2415    endgenerate
2416
2417endmodule
yosys> help $dlatch
Simulation model (verilog)
Listing 189 simlib.v
2604module \$dlatch (EN, D, Q);
2605
2606    parameter WIDTH = 0;
2607    parameter EN_POLARITY = 1'b1;
2608
2609    input EN;
2610    input [WIDTH-1:0] D;
2611    output reg [WIDTH-1:0] Q;
2612
2613    always @* begin
2614        if (EN == EN_POLARITY)
2615            Q = D;
2616    end
2617
2618endmodule
yosys> help $dlatchsr
Simulation model (verilog)
Listing 190 simlib.v
2647module \$dlatchsr (EN, SET, CLR, D, Q);
2648
2649    parameter WIDTH = 0;
2650    parameter EN_POLARITY = 1'b1;
2651    parameter SET_POLARITY = 1'b1;
2652    parameter CLR_POLARITY = 1'b1;
2653
2654    input EN;
2655    input [WIDTH-1:0] SET, CLR, D;
2656    output reg [WIDTH-1:0] Q;
2657
2658    wire pos_en = EN == EN_POLARITY;
2659    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2660    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2661
2662    genvar i;
2663    generate
2664        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2665            always @*
2666                if (pos_clr[i])
2667                    Q[i] = 0;
2668                else if (pos_set[i])
2669                    Q[i] = 1;
2670                else if (pos_en)
2671                    Q[i] = D[i];
2672        end
2673    endgenerate
2674
2675endmodule
yosys> help $sdff
Simulation model (verilog)
Listing 191 simlib.v
2473module \$sdff (CLK, SRST, D, Q);
2474
2475    parameter WIDTH = 0;
2476    parameter CLK_POLARITY = 1'b1;
2477    parameter SRST_POLARITY = 1'b1;
2478    parameter SRST_VALUE = 0;
2479
2480    input CLK, SRST;
2481    input [WIDTH-1:0] D;
2482    output reg [WIDTH-1:0] Q;
2483    wire pos_clk = CLK == CLK_POLARITY;
2484    wire pos_srst = SRST == SRST_POLARITY;
2485
2486    always @(posedge pos_clk) begin
2487        if (pos_srst)
2488            Q <= SRST_VALUE;
2489        else
2490            Q <= D;
2491    end
2492
2493endmodule
yosys> help $sdffce
Simulation model (verilog)
Listing 192 simlib.v
2576module \$sdffce (CLK, SRST, EN, D, Q);
2577
2578    parameter WIDTH = 0;
2579    parameter CLK_POLARITY = 1'b1;
2580    parameter EN_POLARITY = 1'b1;
2581    parameter SRST_POLARITY = 1'b1;
2582    parameter SRST_VALUE = 0;
2583
2584    input CLK, SRST, EN;
2585    input [WIDTH-1:0] D;
2586    output reg [WIDTH-1:0] Q;
2587    wire pos_clk = CLK == CLK_POLARITY;
2588    wire pos_srst = SRST == SRST_POLARITY;
2589
2590    always @(posedge pos_clk) begin
2591        if (EN == EN_POLARITY) begin
2592            if (pos_srst)
2593                Q <= SRST_VALUE;
2594            else
2595                Q <= D;
2596        end
2597    end
2598
2599endmodule
yosys> help $sdffe
Simulation model (verilog)
Listing 193 simlib.v
2550module \$sdffe (CLK, SRST, EN, D, Q);
2551
2552    parameter WIDTH = 0;
2553    parameter CLK_POLARITY = 1'b1;
2554    parameter EN_POLARITY = 1'b1;
2555    parameter SRST_POLARITY = 1'b1;
2556    parameter SRST_VALUE = 0;
2557
2558    input CLK, SRST, EN;
2559    input [WIDTH-1:0] D;
2560    output reg [WIDTH-1:0] Q;
2561    wire pos_clk = CLK == CLK_POLARITY;
2562    wire pos_srst = SRST == SRST_POLARITY;
2563
2564    always @(posedge pos_clk) begin
2565        if (pos_srst)
2566            Q <= SRST_VALUE;
2567        else if (EN == EN_POLARITY)
2568            Q <= D;
2569    end
2570
2571endmodule
yosys> help $sr
Simulation model (verilog)
Listing 194 simlib.v
2265module \$sr (SET, CLR, Q);
2266
2267    parameter WIDTH = 0;
2268    parameter SET_POLARITY = 1'b1;
2269    parameter CLR_POLARITY = 1'b1;
2270
2271    input [WIDTH-1:0] SET, CLR;
2272    output reg [WIDTH-1:0] Q;
2273
2274    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2275    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2276
2277    genvar i;
2278    generate
2279        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2280            always @*
2281                if (pos_clr[i])
2282                    Q[i] <= 0;
2283                else if (pos_set[i])
2284                    Q[i] <= 1;
2285        end
2286    endgenerate
2287
2288endmodule