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. When both set and reset are active, the state and output is undefined.

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 193 simlib.v
2454module \$adff (CLK, ARST, D, Q);
2455
2456    parameter WIDTH = 0;
2457    parameter CLK_POLARITY = 1'b1;
2458    parameter ARST_POLARITY = 1'b1;
2459    parameter ARST_VALUE = 0;
2460
2461    input CLK, ARST;
2462    input [WIDTH-1:0] D;
2463    output reg [WIDTH-1:0] Q;
2464    wire pos_clk = CLK == CLK_POLARITY;
2465    wire pos_arst = ARST == ARST_POLARITY;
2466
2467    always @(posedge pos_clk, posedge pos_arst) begin
2468        if (pos_arst)
2469            Q <= ARST_VALUE;
2470        else
2471            Q <= D;
2472    end
2473
2474endmodule
yosys> help $adffe
Simulation model (verilog)
Listing 194 simlib.v
2529module \$adffe (CLK, ARST, EN, D, Q);
2530
2531    parameter WIDTH = 0;
2532    parameter CLK_POLARITY = 1'b1;
2533    parameter EN_POLARITY = 1'b1;
2534    parameter ARST_POLARITY = 1'b1;
2535    parameter ARST_VALUE = 0;
2536
2537    input CLK, ARST, EN;
2538    input [WIDTH-1:0] D;
2539    output reg [WIDTH-1:0] Q;
2540    wire pos_clk = CLK == CLK_POLARITY;
2541    wire pos_arst = ARST == ARST_POLARITY;
2542
2543    always @(posedge pos_clk, posedge pos_arst) begin
2544        if (pos_arst)
2545            Q <= ARST_VALUE;
2546        else if (EN == EN_POLARITY)
2547            Q <= D;
2548    end
2549
2550endmodule
yosys> help $adlatch
Simulation model (verilog)
Listing 195 simlib.v
2654module \$adlatch (EN, ARST, D, Q);
2655
2656    parameter WIDTH = 0;
2657    parameter EN_POLARITY = 1'b1;
2658    parameter ARST_POLARITY = 1'b1;
2659    parameter ARST_VALUE = 0;
2660
2661    input EN, ARST;
2662    input [WIDTH-1:0] D;
2663    output reg [WIDTH-1:0] Q;
2664
2665    always @* begin
2666        if (ARST == ARST_POLARITY)
2667            Q = ARST_VALUE;
2668        else if (EN == EN_POLARITY)
2669            Q = D;
2670    end
2671
2672endmodule
yosys> help $aldff
Simulation model (verilog)
Listing 196 simlib.v
2479module \$aldff (CLK, ALOAD, AD, D, Q);
2480
2481    parameter WIDTH = 0;
2482    parameter CLK_POLARITY = 1'b1;
2483    parameter ALOAD_POLARITY = 1'b1;
2484
2485    input CLK, ALOAD;
2486    input [WIDTH-1:0] AD;
2487    input [WIDTH-1:0] D;
2488    output reg [WIDTH-1:0] Q;
2489    wire pos_clk = CLK == CLK_POLARITY;
2490    wire pos_aload = ALOAD == ALOAD_POLARITY;
2491
2492    always @(posedge pos_clk, posedge pos_aload) begin
2493        if (pos_aload)
2494            Q <= AD;
2495        else
2496            Q <= D;
2497    end
2498
2499endmodule
yosys> help $aldffe
Simulation model (verilog)
Listing 197 simlib.v
2555module \$aldffe (CLK, ALOAD, AD, EN, D, Q);
2556
2557    parameter WIDTH = 0;
2558    parameter CLK_POLARITY = 1'b1;
2559    parameter EN_POLARITY = 1'b1;
2560    parameter ALOAD_POLARITY = 1'b1;
2561
2562    input CLK, ALOAD, EN;
2563    input [WIDTH-1:0] D;
2564    input [WIDTH-1:0] AD;
2565    output reg [WIDTH-1:0] Q;
2566    wire pos_clk = CLK == CLK_POLARITY;
2567    wire pos_aload = ALOAD == ALOAD_POLARITY;
2568
2569    always @(posedge pos_clk, posedge pos_aload) begin
2570        if (pos_aload)
2571            Q <= AD;
2572        else if (EN == EN_POLARITY)
2573            Q <= D;
2574    end
2575
2576endmodule
yosys> help $dff
Simulation model (verilog)
Listing 198 simlib.v
2346module \$dff (CLK, D, Q);
2347
2348    parameter WIDTH = 0;
2349    parameter CLK_POLARITY = 1'b1;
2350
2351    input CLK;
2352    input [WIDTH-1:0] D;
2353    output reg [WIDTH-1:0] Q;
2354    wire pos_clk = CLK == CLK_POLARITY;
2355
2356    always @(posedge pos_clk) begin
2357        Q <= D;
2358    end
2359
2360endmodule
yosys> help $dffe
Simulation model (verilog)
Listing 199 simlib.v
2365module \$dffe (CLK, EN, D, Q);
2366
2367    parameter WIDTH = 0;
2368    parameter CLK_POLARITY = 1'b1;
2369    parameter EN_POLARITY = 1'b1;
2370
2371    input CLK, EN;
2372    input [WIDTH-1:0] D;
2373    output reg [WIDTH-1:0] Q;
2374    wire pos_clk = CLK == CLK_POLARITY;
2375
2376    always @(posedge pos_clk) begin
2377        if (EN == EN_POLARITY) Q <= D;
2378    end
2379
2380endmodule
yosys> help $dffsr
Simulation model (verilog)
Listing 200 simlib.v
2386module \$dffsr (CLK, SET, CLR, D, Q);
2387
2388    parameter WIDTH = 0;
2389    parameter CLK_POLARITY = 1'b1;
2390    parameter SET_POLARITY = 1'b1;
2391    parameter CLR_POLARITY = 1'b1;
2392
2393    input CLK;
2394    input [WIDTH-1:0] SET, CLR, D;
2395    output reg [WIDTH-1:0] Q;
2396
2397    wire pos_clk = CLK == CLK_POLARITY;
2398    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2399    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2400
2401    genvar i;
2402    generate
2403        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2404            always @(posedge pos_set[i], posedge pos_clr[i], posedge pos_clk)
2405                if (pos_clr[i])
2406                    Q[i] <= 0;
2407                else if (pos_set[i])
2408                    Q[i] <= 1;
2409                else
2410                    Q[i] <= D[i];
2411        end
2412    endgenerate
2413
2414endmodule
yosys> help $dffsre
Simulation model (verilog)
Listing 201 simlib.v
2419module \$dffsre (CLK, SET, CLR, EN, D, Q);
2420
2421    parameter WIDTH = 0;
2422    parameter CLK_POLARITY = 1'b1;
2423    parameter SET_POLARITY = 1'b1;
2424    parameter CLR_POLARITY = 1'b1;
2425    parameter EN_POLARITY = 1'b1;
2426
2427    input CLK, EN;
2428    input [WIDTH-1:0] SET, CLR, D;
2429    output reg [WIDTH-1:0] Q;
2430
2431    wire pos_clk = CLK == CLK_POLARITY;
2432    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2433    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2434
2435    genvar i;
2436    generate
2437        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2438            always @(posedge pos_set[i], posedge pos_clr[i], posedge pos_clk)
2439                if (pos_clr[i])
2440                    Q[i] <= 0;
2441                else if (pos_set[i])
2442                    Q[i] <= 1;
2443                else if (EN == EN_POLARITY)
2444                    Q[i] <= D[i];
2445        end
2446    endgenerate
2447
2448endmodule
yosys> help $dlatch
Simulation model (verilog)
Listing 202 simlib.v
2635module \$dlatch (EN, D, Q);
2636
2637    parameter WIDTH = 0;
2638    parameter EN_POLARITY = 1'b1;
2639
2640    input EN;
2641    input [WIDTH-1:0] D;
2642    output reg [WIDTH-1:0] Q;
2643
2644    always @* begin
2645        if (EN == EN_POLARITY)
2646            Q = D;
2647    end
2648
2649endmodule
yosys> help $dlatchsr
Simulation model (verilog)
Listing 203 simlib.v
2678module \$dlatchsr (EN, SET, CLR, D, Q);
2679
2680    parameter WIDTH = 0;
2681    parameter EN_POLARITY = 1'b1;
2682    parameter SET_POLARITY = 1'b1;
2683    parameter CLR_POLARITY = 1'b1;
2684
2685    input EN;
2686    input [WIDTH-1:0] SET, CLR, D;
2687    output reg [WIDTH-1:0] Q;
2688
2689    wire pos_en = EN == EN_POLARITY;
2690    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2691    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2692
2693    genvar i;
2694    generate
2695        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2696            always @*
2697                if (pos_clr[i])
2698                    Q[i] = 0;
2699                else if (pos_set[i])
2700                    Q[i] = 1;
2701                else if (pos_en)
2702                    Q[i] = D[i];
2703        end
2704    endgenerate
2705
2706endmodule
yosys> help $sdff
Simulation model (verilog)
Listing 204 simlib.v
2504module \$sdff (CLK, SRST, D, Q);
2505
2506    parameter WIDTH = 0;
2507    parameter CLK_POLARITY = 1'b1;
2508    parameter SRST_POLARITY = 1'b1;
2509    parameter SRST_VALUE = 0;
2510
2511    input CLK, SRST;
2512    input [WIDTH-1:0] D;
2513    output reg [WIDTH-1:0] Q;
2514    wire pos_clk = CLK == CLK_POLARITY;
2515    wire pos_srst = SRST == SRST_POLARITY;
2516
2517    always @(posedge pos_clk) begin
2518        if (pos_srst)
2519            Q <= SRST_VALUE;
2520        else
2521            Q <= D;
2522    end
2523
2524endmodule
yosys> help $sdffce
Simulation model (verilog)
Listing 205 simlib.v
2607module \$sdffce (CLK, SRST, EN, D, Q);
2608
2609    parameter WIDTH = 0;
2610    parameter CLK_POLARITY = 1'b1;
2611    parameter EN_POLARITY = 1'b1;
2612    parameter SRST_POLARITY = 1'b1;
2613    parameter SRST_VALUE = 0;
2614
2615    input CLK, SRST, EN;
2616    input [WIDTH-1:0] D;
2617    output reg [WIDTH-1:0] Q;
2618    wire pos_clk = CLK == CLK_POLARITY;
2619    wire pos_srst = SRST == SRST_POLARITY;
2620
2621    always @(posedge pos_clk) begin
2622        if (EN == EN_POLARITY) begin
2623            if (pos_srst)
2624                Q <= SRST_VALUE;
2625            else
2626                Q <= D;
2627        end
2628    end
2629
2630endmodule
yosys> help $sdffe
Simulation model (verilog)
Listing 206 simlib.v
2581module \$sdffe (CLK, SRST, EN, D, Q);
2582
2583    parameter WIDTH = 0;
2584    parameter CLK_POLARITY = 1'b1;
2585    parameter EN_POLARITY = 1'b1;
2586    parameter SRST_POLARITY = 1'b1;
2587    parameter SRST_VALUE = 0;
2588
2589    input CLK, SRST, EN;
2590    input [WIDTH-1:0] D;
2591    output reg [WIDTH-1:0] Q;
2592    wire pos_clk = CLK == CLK_POLARITY;
2593    wire pos_srst = SRST == SRST_POLARITY;
2594
2595    always @(posedge pos_clk) begin
2596        if (pos_srst)
2597            Q <= SRST_VALUE;
2598        else if (EN == EN_POLARITY)
2599            Q <= D;
2600    end
2601
2602endmodule
yosys> help $sr
Simulation model (verilog)
Listing 207 simlib.v
2296module \$sr (SET, CLR, Q);
2297
2298    parameter WIDTH = 0;
2299    parameter SET_POLARITY = 1'b1;
2300    parameter CLR_POLARITY = 1'b1;
2301
2302    input [WIDTH-1:0] SET, CLR;
2303    output reg [WIDTH-1:0] Q;
2304
2305    wire [WIDTH-1:0] pos_set = SET_POLARITY ? SET : ~SET;
2306    wire [WIDTH-1:0] pos_clr = CLR_POLARITY ? CLR : ~CLR;
2307
2308    genvar i;
2309    generate
2310        for (i = 0; i < WIDTH; i = i+1) begin:bitslices
2311            always @*
2312                if (pos_clr[i])
2313                    Q[i] <= 0;
2314                else if (pos_set[i])
2315                    Q[i] <= 1;
2316        end
2317    endgenerate
2318
2319endmodule