Negation of "nonzero known value"

T

Tim Johnson

Guest
I need to implement an assertion statement, with pseudo-code as
follows:

assert(expr) begin
... take this branch if expr is 0 or unknown
$finish;
end

Probably dumb question: what's the simplest way to do the conditional?
The problem is handling X or Z values in 'expr'. The '$finish' is only
taken if expr is 0 or unknown. In other words, is there a simple
negative-logic version of "if(expr)"?

"if(!expr)" doesn't work because the assertion block isn't entered if
expr contains an X or Z. "if(expr == 0)" and "if(expr === 0)" are the
same.

At first sight, I need

if((expr === 0) || (!expr === X)) begin
...
end

or even

lbl: begin
if(expr)
disable lbl;
$finish;
end

Have I missed something?

Thanks - Tim
 
Tim Johnson wrote:
I need to implement an assertion statement, with pseudo-code as
follows:

assert(expr) begin
... take this branch if expr is 0 or unknown
$finish;
end

Probably dumb question: what's the simplest way to do the conditional?
The problem is handling X or Z values in 'expr'. The '$finish' is only
taken if expr is 0 or unknown. In other words, is there a simple
negative-logic version of "if(expr)"?

The simlpe negative-logic version of "if(expr)" is : "else":

if (expr)
else <your checks>

-Alex
 
On 22 Nov 2006 12:38:20 -0800, "Alex" <agnusin@gmail.com> wrote:

The simlpe negative-logic version of "if(expr)" is : "else":

if (expr)
else <your checks
Ahhh... that *is* simple :)

Thanks - Tim
 
On Wed, 22 Nov 2006 21:02:18 +0000, Tim
Johnson <tjohnson302@yahoo.com> wrote:

On 22 Nov 2006 12:38:20 -0800, <agnusin@gmail.com> wrote:

The simlpe negative-logic version of if(expr) is 'else'
It's also worth noting that the unary reduction-OR operator
takes any vector and yields a single bit that is 0, 1 or X
depending on the "non-zero-ness" of the original vector.
Thus,

if (vector) ...

gives exactly the same behaviour as

if ( | vector ) ...

But because you have only one bit, it's a little easier to find
what's going on after doing reduction-OR; you can,
for example, use a case statement:

case (|vector)
1'b0: $display("Exactly zero");
1'bx: $display("Contains X/Z bits, and possibly some zero bits");
1'b1: $display("Contains at least one 1 bit, must be nonzero");
endcase

The direct answer to your original question would therefore be:

if ( (|vector) !== 1'b1 )
$display("vector contains no 1 bit");

hth
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Welcome to EDABoard.com

Sponsor

Back
Top