expression size

R

romi

Guest
In the expression below, I'm wondering if 'a' is supposed to be
expanded to 32 bits before the ~ is applied to 'a' or after. I
thought that the parenthesis would force the ~ to be done on the 1 bit
value prior to the expansion to 32 bit for the equality.


logic a,b;
assign b = (~a) == 1;


If a=0, should be b be 0 or 1?

Thanks
 
On Fri, 20 Jun 2008 11:52:40 -0700 (PDT), romi <weberrm@gmail.com>
wrote:

In the expression below, I'm wondering if 'a' is supposed to be
expanded to 32 bits before the ~ is applied to 'a' or after. I
thought that the parenthesis would force the ~ to be done on the 1 bit
value prior to the expansion to 32 bit for the equality.

logic a,b;
assign b = (~a) == 1;

If a=0, should be b be 0 or 1?
False (0). The parentheses don't affect the fact that
"~a" is a context-determined expression, so "a" is widened
to the width of integer before the expression is evaluated.

By contrast, if you had hidden the ~a in a _concatenation_
then it would have been self-determined and the negation
would be done in 1-bit width, so your result would be true:

assign c = {~a} == 1; // yields TRUE if a==0

--
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.
 
Jonathan Bromley wrote:
On Fri, 20 Jun 2008 11:52:40 -0700 (PDT), romi <weberrm@gmail.com
wrote:

In the expression below, I'm wondering if 'a' is supposed to be
expanded to 32 bits before the ~ is applied to 'a' or after. I
thought that the parenthesis would force the ~ to be done on the 1 bit
value prior to the expansion to 32 bit for the equality.

logic a,b;
assign b = (~a) == 1;

If a=0, should be b be 0 or 1?

False (0). The parentheses don't affect the fact that
"~a" is a context-determined expression, so "a" is widened
to the width of integer before the expression is evaluated.

By contrast, if you had hidden the ~a in a _concatenation_
then it would have been self-determined and the negation
would be done in 1-bit width, so your result would be true:

assign c = {~a} == 1; // yields TRUE if a==0

Using the logical operator probably makes more sense here:

assign c = !a == 1; // yields TRUE if a==0
 

Welcome to EDABoard.com

Sponsor

Back
Top