What is the correct way to implement clock gating in RTL?
The clock strobe signal should only be switched when the latch is closed, otherwise there is the possibility of failures and problems with metastability. For an active high latch, the strobe signal must switch to the falling edge of the clock. Edge increase for active low latches.
Typically, you would have to have an edge-sensitive latch_update_en flop to prevent interference on the gate signal.
always_ff @(negedge clk) latch_update_en <= next_latch_update_en; always_comb gated_clk = (* clock_gating = "clk" *) clk & latch_update_en; always_latch if(gated_clk) latch_data <= new_data;
Reminder: if you have a latch only deign: front trigger shutters are only master / slave latches
always_latch if (clk) sync_latch_update_en <= next_latch_update_en; always_latch if (!clk) latch_update_en <= sync_latch_update_en;
Does the tool have a difficult time in synthesis, if clk directly "and" - in the always_comb block with a different permission signal?
Most synthesis has problems with direct I-synchronization. It is not always intuitive how to use gating. A synthesizer often has many AND logic elements in the library to select, each of which has different slope, skew, and load values, which is very important for input combinations. Although functionally the same, A & B will get different time results, then B & A
Initiating an explicit cell from a synthesizer library narrows the possibilities for knowing and predicting behavior. The predefined clock strobe cell also has the attributes used by the synthesizer. Attributes include synchronization information for balancing the clock tree (placing a buffer in the design to manage loads and parasites).
Some synthesizers support setting tag attributes in RTL (ex: // synthesis attributes or (* attributes *) ) instead of having to explicitly create a cell instance. There is no standard on how to do this; refer to the user manual.
What is the purpose of using a custom clock strobe cell?
A user cell is a specific cell in the synthesis library with information about time synchronization, load balancing, and other attributes. Using this information, the synthesizer knows where and how to add or calibrate the buffer delay in the clock tree. This ensures that the fleet with closed gates does not see the front of the clock before the flop.
_____ _____ IN -------------|DQ|-----|DQ|--- OUT | | | | |\ |\ | | | | +-| >| >---|> | +-|> | | |/ |/ |_____| | |_____| | ___ | CLK -+-| \ | | & )-------------+ BALANCED CLOCK : correct data sampled GATE --|___/
Without an indication, a closed flop may receive a delayed clock. Beveling will result in incorrect data being selected.
_____ _____ IN -------------|DQ|-----|DQ|--- OUT | | | | | | | | +----------|> | +-|> | | |_____| | |_____| | ___ | CLK -+-| \ |\ |\ | | & )---| >| >----+ UNBALANCED CLOCK : wrong data sampled GATE --|___/ |/ |/