Skip to content

Commit 6e07bd7

Browse files
authored
registers.svh: Merge explicit and implicit macros (#117)
Merged explicit and implicit macros into `` `FF `` and `` `FFL `` for asynchronous FFs without and with load-enable, respectively. The old macros `` `FFARN `` and `` `FFLARN `` are retained for compatibility but a deprecation notice was added to them.
1 parent 245382b commit 6e07bd7

File tree

3 files changed

+61
-66
lines changed

3 files changed

+61
-66
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8+
### Changed
9+
- `registers.svh`: Merge explicit and implicit register variants into `` `FF `` and `` `FFL `` macros
810

911
## 1.21.0 - 2021-01-28
1012
### Changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ The header file `registers.svh` contains macros that expand to descriptions of r
114114
To avoid misuse of `always_ff` blocks, only the following macros shall be used to describe sequential behavior.
115115
The use of linter rules that flag explicit uses of `always_ff` in source code is encouraged.
116116

117-
| Macro | Arguments | Description |
118-
| ------------ | --------------------------------------------------------------- | ----------------------------------------------------------------------- |
119-
| `` `FF`` | `q_sig`, `d_sig`, `rst_val` | Flip-flop with asynchronous active-low reset (implicit) |
120-
| `` `FFAR`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `arst_sig` | Flip-flop with asynchronous active-high reset |
121-
| `` `FFARN`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `arstn_sig` | Flip-flop with asynchronous active-low reset |
122-
| `` `FFSR`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `rst_sig` | Flip-flop with synchronous active-high reset |
123-
| `` `FFSRN`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `rstn_sig` | Flip-flop with synchronous active-low reset |
124-
| `` `FFNR`` | `q_sig`, `d_sig`, `clk_sig` | Flip-flop without reset |
125-
| | | |
126-
| `` `FFL`` | `q_sig`, `d_sig`, `load_ena`, `rst_val` | Flip-flop with load-enable and asynchronous active-low reset (implicit) |
127-
| `` `FFLAR`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `arst_sig` | Flip-flop with load-enable and asynchronous active-high reset |
128-
| `` `FFLARN`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `arstn_sig` | Flip-flop with load-enable and asynchronous active-low reset |
129-
| `` `FFLSR`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `rst_sig` | Flip-flop with load-enable and synchronous active-high reset |
130-
| `` `FFLSRN`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `rstn_sig` | Flip-flop with load-enable and synchronous active-low reset |
131-
| `` `FFLNR`` | `q_sig`, `d_sig`, `load_ena`, `clk_sig` | Flip-flop with load-enable without reset |
117+
| Macro | Arguments | Description |
118+
| ------------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------- |
119+
| `` `FF`` | `q_sig`, `d_sig`, `rst_val`, (`clk_sig`, `arstn_sig`) | Flip-flop with asynchronous active-low reset |
120+
| `` `FFAR`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `arst_sig` | Flip-flop with asynchronous active-high reset |
121+
| `` `FFARN`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `arstn_sig` | *deprecated* Flip-flop with asynchronous active-low reset |
122+
| `` `FFSR`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `rst_sig` | Flip-flop with synchronous active-high reset |
123+
| `` `FFSRN`` | `q_sig`, `d_sig`, `rst_val`, `clk_sig`, `rstn_sig` | Flip-flop with synchronous active-low reset |
124+
| `` `FFNR`` | `q_sig`, `d_sig`, `clk_sig` | Flip-flop without reset |
125+
| | | |
126+
| `` `FFL`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, (`clk_sig`, `arstn_sig`) | Flip-flop with load-enable and asynchronous active-low reset |
127+
| `` `FFLAR`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `arst_sig` | Flip-flop with load-enable and asynchronous active-high reset |
128+
| `` `FFLARN`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `arstn_sig` | *deprecated* Flip-flop with load-enable and asynchronous active-low reset |
129+
| `` `FFLSR`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `rst_sig` | Flip-flop with load-enable and synchronous active-high reset |
130+
| `` `FFLSRN`` | `q_sig`, `d_sig`, `load_ena`, `rst_val`, `clk_sig`, `rstn_sig` | Flip-flop with load-enable and synchronous active-low reset |
131+
| `` `FFLNR`` | `q_sig`, `d_sig`, `load_ena`, `clk_sig` | Flip-flop with load-enable without reset |
132132
- *The name of the clock and reset signals for implicit variants is `clk_i` and `rst_ni`, respectively.*
133133
- *Argument suffix `_sig` indicates signal names for present and next state as well as clocks and resets.*
134134
- *Argument `rst_val` specifies the value literal to be assigned upon reset.*

include/common_cells/registers.svh

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 ETH Zurich and University of Bologna.
1+
// Copyright 2018, 2021 ETH Zurich and University of Bologna.
22
//
33
// Copyright and related rights are licensed under the Solderpad Hardware
44
// License, Version 0.51 (the "License"); you may not use this file except in
@@ -8,49 +8,53 @@
88
// this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
99
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1010
// specific language governing permissions and limitations under the License.
11+
// SPDX-License-Identifier: SHL-0.51
12+
//
13+
// Author: Stefan Mach <[email protected]>
14+
// Description: Common register defines for RTL designs
1115

12-
// Common register defines for RTL designs
1316
`ifndef COMMON_CELLS_REGISTERS_SVH_
1417
`define COMMON_CELLS_REGISTERS_SVH_
1518

1619
// Abridged Summary of available FF macros:
17-
// `FF: asynchronous active-low reset (implicit clock and reset)
20+
// `FF: asynchronous active-low reset
1821
// `FFAR: asynchronous active-high reset
19-
// `FFARN: asynchronous active-low reset
22+
// `FFARN: [deprecated] asynchronous active-low reset
2023
// `FFSR: synchronous active-high reset
2124
// `FFSRN: synchronous active-low reset
2225
// `FFNR: without reset
23-
// `FFL: load-enable and asynchronous active-low reset (implicit clock and reset)
26+
// `FFL: load-enable and asynchronous active-low reset
2427
// `FFLAR: load-enable and asynchronous active-high reset
25-
// `FFLARN: load-enable and asynchronous active-low reset
28+
// `FFLARN: [deprecated] load-enable and asynchronous active-low reset
2629
// `FFLARNC: load-enable and asynchronous active-low reset and synchronous active-high clear
2730
// `FFLSR: load-enable and synchronous active-high reset
2831
// `FFLSRN: load-enable and synchronous active-low reset
2932
// `FFLNR: load-enable without reset
3033

34+
`define REG_DFLT_CLK clk_i
35+
`define REG_DFLT_RST rst_ni
3136

32-
// Flip-Flop with asynchronous active-low reset (implicit clock and reset)
37+
// Flip-Flop with asynchronous active-low reset
3338
// __q: Q output of FF
3439
// __d: D input of FF
3540
// __reset_value: value assigned upon reset
36-
// Implicit:
37-
// clk_i: clock input
38-
// rst_ni: reset input (asynchronous, active low)
39-
`define FF(__q, __d, __reset_value) \
40-
always_ff @(posedge clk_i or negedge rst_ni) begin \
41-
if (!rst_ni) begin \
42-
__q <= (__reset_value); \
43-
end else begin \
44-
__q <= (__d); \
45-
end \
41+
// (__clk: clock input)
42+
// (__arst_n: asynchronous reset, active-low)
43+
`define FF(__q, __d, __reset_value, __clk = `REG_DFLT_CLK, __arst_n = `REG_DFLT_RST) \
44+
always_ff @(posedge (__clk) or negedge (__arst_n)) begin \
45+
if (!__arst_n) begin \
46+
__q <= (__reset_value); \
47+
end else begin \
48+
__q <= (__d); \
49+
end \
4650
end
4751

4852
// Flip-Flop with asynchronous active-high reset
4953
// __q: Q output of FF
5054
// __d: D input of FF
5155
// __reset_value: value assigned upon reset
5256
// __clk: clock input
53-
// __arst: asynchronous reset
57+
// __arst: asynchronous reset, active-high
5458
`define FFAR(__q, __d, __reset_value, __clk, __arst) \
5559
always_ff @(posedge (__clk) or posedge (__arst)) begin \
5660
if (__arst) begin \
@@ -60,27 +64,22 @@
6064
end \
6165
end
6266

67+
// DEPRECATED - use `FF instead
6368
// Flip-Flop with asynchronous active-low reset
6469
// __q: Q output of FF
6570
// __d: D input of FF
6671
// __reset_value: value assigned upon reset
6772
// __clk: clock input
68-
// __arst_n: asynchronous reset
69-
`define FFARN(__q, __d, __reset_value, __clk, __arst_n) \
70-
always_ff @(posedge (__clk) or negedge (__arst_n)) begin \
71-
if (!__arst_n) begin \
72-
__q <= (__reset_value); \
73-
end else begin \
74-
__q <= (__d); \
75-
end \
76-
end
73+
// __arst_n: asynchronous reset, active-low
74+
`define FFARN(__q, __d, __reset_value, __clk, __arst_n) \
75+
`FF(__q, __d, __reset_value, __clk, __arst_n)
7776

7877
// Flip-Flop with synchronous active-high reset
7978
// __q: Q output of FF
8079
// __d: D input of FF
8180
// __reset_value: value assigned upon reset
8281
// __clk: clock input
83-
// __reset_clk: reset input
82+
// __reset_clk: reset input, active-high
8483
`define FFSR(__q, __d, __reset_value, __clk, __reset_clk) \
8584
`ifndef VERILATOR \
8685
/``* synopsys sync_set_reset `"__reset_clk`" *``/ \
@@ -94,7 +93,7 @@
9493
// __d: D input of FF
9594
// __reset_value: value assigned upon reset
9695
// __clk: clock input
97-
// __reset_n_clk: reset input
96+
// __reset_n_clk: reset input, active-low
9897
`define FFSRN(__q, __d, __reset_value, __clk, __reset_n_clk) \
9998
`ifndef VERILATOR \
10099
/``* synopsys sync_set_reset `"__reset_n_clk`" *``/ \
@@ -117,16 +116,15 @@
117116
// __d: D input of FF
118117
// __load: load d value into FF
119118
// __reset_value: value assigned upon reset
120-
// Implicit:
121-
// clk_i: clock input
122-
// rst_ni: reset input (asynchronous, active low)
123-
`define FFL(__q, __d, __load, __reset_value) \
124-
always_ff @(posedge clk_i or negedge rst_ni) begin \
125-
if (!rst_ni) begin \
126-
__q <= (__reset_value); \
127-
end else begin \
128-
__q <= (__load) ? (__d) : (__q); \
129-
end \
119+
// (__clk: clock input)
120+
// (__arst_n: asynchronous reset, active-low)
121+
`define FFL(__q, __d, __load, __reset_value, __clk = `REG_DFLT_CLK, __arst_n = `REG_DFLT_RST) \
122+
always_ff @(posedge (__clk) or negedge (__arst_n)) begin \
123+
if (!__arst_n) begin \
124+
__q <= (__reset_value); \
125+
end else begin \
126+
__q <= (__load) ? (__d) : (__q); \
127+
end \
130128
end
131129

132130
// Flip-Flop with load-enable and asynchronous active-high reset
@@ -135,7 +133,7 @@
135133
// __load: load d value into FF
136134
// __reset_value: value assigned upon reset
137135
// __clk: clock input
138-
// __arst: asynchronous reset
136+
// __arst: asynchronous reset, active-high
139137
`define FFLAR(__q, __d, __load, __reset_value, __clk, __arst) \
140138
always_ff @(posedge (__clk) or posedge (__arst)) begin \
141139
if (__arst) begin \
@@ -145,29 +143,24 @@
145143
end \
146144
end
147145

146+
// DEPRECATED - use `FFL instead
148147
// Flip-Flop with load-enable and asynchronous active-low reset
149148
// __q: Q output of FF
150149
// __d: D input of FF
151150
// __load: load d value into FF
152151
// __reset_value: value assigned upon reset
153152
// __clk: clock input
154-
// __arst_n: asynchronous reset
153+
// __arst_n: asynchronous reset, active-low
155154
`define FFLARN(__q, __d, __load, __reset_value, __clk, __arst_n) \
156-
always_ff @(posedge (__clk) or negedge (__arst_n)) begin \
157-
if (!__arst_n) begin \
158-
__q <= (__reset_value); \
159-
end else begin \
160-
__q <= (__load) ? (__d) : (__q); \
161-
end \
162-
end
155+
`FFL(__q, __d, __load, __reset_value, __clk, __arst_n)
163156

164157
// Flip-Flop with load-enable and synchronous active-high reset
165158
// __q: Q output of FF
166159
// __d: D input of FF
167160
// __load: load d value into FF
168161
// __reset_value: value assigned upon reset
169162
// __clk: clock input
170-
// __reset_clk: reset input
163+
// __reset_clk: reset input, active-high
171164
`define FFLSR(__q, __d, __load, __reset_value, __clk, __reset_clk) \
172165
`ifndef VERILATOR \
173166
/``* synopsys sync_set_reset `"__reset_clk`" *``/ \
@@ -182,7 +175,7 @@
182175
// __load: load d value into FF
183176
// __reset_value: value assigned upon reset
184177
// __clk: clock input
185-
// __reset_n_clk: reset input
178+
// __reset_n_clk: reset input, active-low
186179
`define FFLSRN(__q, __d, __load, __reset_value, __clk, __reset_n_clk) \
187180
`ifndef VERILATOR \
188181
/``* synopsys sync_set_reset `"__reset_n_clk`" *``/ \
@@ -198,7 +191,7 @@
198191
// __clear: assign reset value into FF
199192
// __reset_value: value assigned upon reset
200193
// __clk: clock input
201-
// __arst_n: asynchronous reset
194+
// __arst_n: asynchronous reset, active-low
202195
`define FFLARNC(__q, __d, __load, __clear, __reset_value, __clk, __arst_n) \
203196
`ifndef VERILATOR \
204197
/``* synopsys sync_set_reset `"__clear`" *``/ \

0 commit comments

Comments
 (0)