-
Notifications
You must be signed in to change notification settings - Fork 813
/
Copy pathprim_assert_standard_macros.svh
107 lines (94 loc) · 6.6 KB
/
prim_assert_standard_macros.svh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
// Macro bodies included by prim_assert.sv for tools that support full SystemVerilog and SVA syntax.
// See prim_assert.sv for documentation for each of the macros.
`define ASSERT_I(__name, __prop) \
__name: assert (__prop) \
else begin \
`ASSERT_ERROR(__name) \
end
// Formal tools will ignore the initial construct, so use static assertion as a workaround.
// This workaround terminates design elaboration if the __prop predict is false.
// It calls $fatal() with the first argument equal to 2, it outputs the statistics about the memory
// and CPU time.
`define ASSERT_INIT(__name, __prop) \
`ifdef FPV_ON \
if (!(__prop)) $fatal(2, "Fatal static assertion [%s]: (%s) is not true.", \
(__name), (__prop)); \
`else \
initial begin \
__name: assert (__prop) \
else begin \
`ASSERT_ERROR(__name) \
end \
end \
`endif
`define ASSERT_INIT_NET(__name, __prop) \
initial begin \
// When a net is assigned with a value, the assignment is evaluated after \
// initial in Xcelium. Add 1ps delay to check value after the assignment is \
// completed. \
#1ps; \
__name: assert (__prop) \
else begin \
`ASSERT_ERROR(__name) \
end \
end \
`define ASSERT_FINAL(__name, __prop) \
`ifndef FPV_ON \
final begin \
__name: assert (__prop || $test$plusargs("disable_assert_final_checks")) \
else begin \
`ASSERT_ERROR(__name) \
end \
end \
`endif
`define ASSERT_AT_RESET(__name, __prop, __rst = `ASSERT_DEFAULT_RST) \
// `__rst` is active-high for these macros, so trigger on its posedge. \
// The values inside the property are sampled just before the trigger, \
// which is necessary to make the evaluation of `__prop` on a reset edge \
// meaningful. On any reset posedge at the start of time, `__rst` itself \
// is unknown, and at that time `__prop` is likely not initialized either, \
// so this assertion does not evaluate `__prop` when `__rst` is unknown. \
// \
// This extra behaviour is not used for FPV, because Jasper doesn't support \
// it and instead prints the WNL038 warning. Avoid the check and warning \
// message in this case. \
`ifndef FPV_ON \
__name: assert property (@(posedge __rst) $isunknown(__rst) || (__prop)) \
`else \
__name: assert property (@(posedge __rst) (__prop)) \
`endif \
else begin \
`ASSERT_ERROR(__name) \
end
`define ASSERT_AT_RESET_AND_FINAL(__name, __prop, __rst = `ASSERT_DEFAULT_RST) \
`ASSERT_AT_RESET(AtReset_``__name``, __prop, __rst) \
`ASSERT_FINAL(Final_``__name``, __prop)
`define ASSERT(__name, __prop, __clk = `ASSERT_DEFAULT_CLK, __rst = `ASSERT_DEFAULT_RST) \
__name: assert property (@(posedge __clk) disable iff ((__rst) !== '0) (__prop)) \
else begin \
`ASSERT_ERROR(__name) \
end
`define ASSERT_NEVER(__name, __prop, __clk = `ASSERT_DEFAULT_CLK, __rst = `ASSERT_DEFAULT_RST) \
__name: assert property (@(posedge __clk) disable iff ((__rst) !== '0) not (__prop)) \
else begin \
`ASSERT_ERROR(__name) \
end
`define ASSERT_KNOWN(__name, __sig, __clk = `ASSERT_DEFAULT_CLK, __rst = `ASSERT_DEFAULT_RST) \
`ifndef FPV_ON \
`ASSERT(__name, !$isunknown(__sig), __clk, __rst) \
`endif
`define COVER(__name, __prop, __clk = `ASSERT_DEFAULT_CLK, __rst = `ASSERT_DEFAULT_RST) \
__name: cover property (@(posedge __clk) disable iff ((__rst) !== '0) (__prop));
`define ASSUME(__name, __prop, __clk = `ASSERT_DEFAULT_CLK, __rst = `ASSERT_DEFAULT_RST) \
__name: assume property (@(posedge __clk) disable iff ((__rst) !== '0) (__prop)) \
else begin \
`ASSERT_ERROR(__name) \
end
`define ASSUME_I(__name, __prop) \
__name: assume (__prop) \
else begin \
`ASSERT_ERROR(__name) \
end