Logical OR

R

Rob

Guest
Hello,

I have a question about how the following line of code would be
synthesized. I realize this is an "error" but I'm trying to
understand what the outcome would be.

For this example:
rd_addr_ch2_pos2 is a 16 bit constant value of some number, lets say
0x01AE.
(rd_addr_ch2 == wr_addr_ch1_pos); lets say this equates to 0

Would the OR equation be:

0000 0001 1010 1110
0000 0000 0000 0000
--------------------------------
0000 0001 1010 1110

If so, how does the If condition look a this result?

if ((rd_addr_ch2 == wr_addr_ch1_pos) || (rd_addr_ch2_pos2))

Thank you,
Rob
 
On Wed, 7 Jan 2009 10:47:05 -0800 (PST), Rob
<robnstef@frontiernet.net> wrote:

Hello,

I have a question about how the following line of code would be
synthesized. I realize this is an "error" but I'm trying to
understand what the outcome would be.

For this example:
rd_addr_ch2_pos2 is a 16 bit constant value of some number, lets say
0x01AE.
(rd_addr_ch2 == wr_addr_ch1_pos); lets say this equates to 0

Would the OR equation be:

0000 0001 1010 1110
0000 0000 0000 0000
--------------------------------
0000 0001 1010 1110

If so, how does the If condition look a this result?

if ((rd_addr_ch2 == wr_addr_ch1_pos) || (rd_addr_ch2_pos2))
If I understand you correctly you have a typo where you meant
"if (foo == bar)" but you typed "if (foo || bar)" and you want to know
how the latter will be synthesized. If so, the "or" condition is
implemented by converting foo and bar to their logical values ie an
expression is true if any of its bits is set so a different way of
typing your second condition is:
if ( (|foo) || (|bar) )
so all bits of foo are or'ed to make a single bit expression, the same
to bar and then the resulting two expressions are or'ed again. To make
a long story short, if any bits are set in the two vectors, the if
branch will take, if all are zero, the else branch will take.
Muzaffer Kal

DSPIA INC.
ASIC/FPGA Design Services
http://www.dspia.com
 
On Jan 7, 3:03 pm, Muzaffer Kal <k...@dspia.com> wrote:
On Wed, 7 Jan 2009 10:47:05 -0800 (PST), Rob



robns...@frontiernet.net> wrote:
Hello,

I have a question about how the following line of code would be
synthesized.  I realize this is an "error" but I'm trying to
understand what the outcome would be.

For this example:
rd_addr_ch2_pos2 is a 16 bit constant value of some number, lets say
0x01AE.
(rd_addr_ch2 == wr_addr_ch1_pos); lets say this equates to 0

Would the OR equation be:

0000 0001 1010 1110
0000 0000 0000 0000
--------------------------------
0000 0001 1010 1110

If so, how does the If condition look a this result?

if ((rd_addr_ch2 == wr_addr_ch1_pos) || (rd_addr_ch2_pos2))

If I understand you correctly you have a typo where you meant
"if (foo == bar)" but you typed "if (foo || bar)" and you want to know
how the latter will be synthesized. If so, the "or" condition is
implemented by converting foo and bar to their logical values ie an
expression is true if any of its bits is set so a different way of
typing your second condition is:
if ( (|foo) || (|bar) )
so all bits of foo are or'ed to make a single bit expression, the same
to bar and then the resulting two expressions are or'ed again. To make
a long story short, if any bits are set in the two vectors, the if
branch will take, if all are zero, the else branch will take.
Muzaffer Kal

DSPIA INC.
ASIC/FPGA Design Serviceshttp://www.dspia.com
No my mistake was that the second condition should have been as
follows:

if ((rd_addr_ch2 == wr_addr_ch1_pos) || (rd_addr_ch2 =rd_addr_ch2_pos2))

So since in my original design rd_addr_ch2_pos2 would definitely have
1's in it , the IF branch would have always been taken. This leads me
to my next question. What would the outcome be if both branches of an
IF statement (the IF and the ELSE) are true?

Thank you,
Rob
 
On Wed, 7 Jan 2009 13:16:21 -0800 (PST), Rob
<robnstef@frontiernet.net> wrote:

On Jan 7, 3:03 pm, Muzaffer Kal <k...@dspia.com> wrote:
On Wed, 7 Jan 2009 10:47:05 -0800 (PST), Rob
....
If so, how does the If condition look a this result?

if ((rd_addr_ch2 == wr_addr_ch1_pos) || (rd_addr_ch2_pos2))

No my mistake was that the second condition should have been as
follows:

if ((rd_addr_ch2 == wr_addr_ch1_pos) || (rd_addr_ch2 ==
rd_addr_ch2_pos2))

So since in my original design rd_addr_ch2_pos2 would definitely have
1's in it , the IF branch would have always been taken.
Or rd_addr_ch2_pos2 could be all zero and
rd_addr_ch2 != wr_addr_ch1_pos then you still take the else branch.

This leads me
to my next question. What would the outcome be if both branches of an
IF statement (the IF and the ELSE) are true?
No such thing ;-) There is only one condition which gets evaluated and
when true IF branch gets executed, when false ELSE branch gets
executed.
If this were quantum computing, a condition and its inverse could be
true simultaneously but then you'd have to ask the cat to decide what
to do: to live or not to live, that's the question ...

Muzaffer Kal

DSPIA INC.
ASIC/FPGA Design Services
http://www.dspia.com
 

Welcome to EDABoard.com

Sponsor

Back
Top