4 bit & 8 bit register comparison

D

Deepu

Guest
Hi All,

Can you please provide some ides on how the comparison can be done for
the below case.

if (`CHIP.test_part_p2 != (data_compare))
$display ("FAIL");
else
$display ("PASS");

In the above case "`CHIP.test_part_p2" is 4 bit device signal while
data_compare is a 8-bit register. Also bit 2 to bit 5 in
'data_compare' register has the value that can be compared.

Example:

if `CHIP.test_part_p2 is 4'b1111, then data_compare will be 00111100

Thanks for the help..
 
On Nov 4, 3:25 am, Deepu <pradeep...@gmail.com> wrote:
Hi All,

Can you please provide some ides on how the comparison can be done for
the below case.

if (`CHIP.test_part_p2 != (data_compare))
 $display ("FAIL");
 else
 $display ("PASS");

In the above case "`CHIP.test_part_p2" is 4 bit device signal while
data_compare is a 8-bit register. Also bit 2 to bit 5 in
'data_compare' register has the value that can be compared.

Example:

if `CHIP.test_part_p2 is 4'b1111, then data_compare will be 00111100

Thanks for the help..
if data_compare is defined like:
reg [7:0] data_compare;

you can just do a bit select for the 4 bits you want.

Or even if you don't know the bit range (it could be [18:11]
for example) in the definition, but know you want the four
bits in the middle you could shift right by two and AND
the result with 4'hF to pick out the bits.

You could also pad out the left side of the comparison with the
unused bits of data_compare so those bits would always match.

Are you trying to see how many ways you can do this?

Regards,
Gabor
 
if data_compare is defined like:
reg [7:0] data_compare;
Yes, data_compare is defined this way.

you can just do a bit select for the 4 bits you want.
Actually i am trying to find a genric way to do the comparison because
somecases i have like:

if `CHIP.test_part_p3 is 4'b1111, then data_compare will be 00011110

if `CHIP.test_part_p4 is 4'b1111, then data_compare will be 01111000

if `CHIP.test_part_p5 is 2'b11, then data_compare will be 01100000
 
On Thu, 4 Nov 2010 06:50:47 -0700 (PDT), Deepu wrote:

Actually i am trying to find a genric way to do the comparison because
somecases i have like:
if `CHIP.test_part_p3 is 4'b1111, then data_compare will be 00011110
if `CHIP.test_part_p4 is 4'b1111, then data_compare will be 01111000
if `CHIP.test_part_p5 is 2'b11, then data_compare will be 01100000
It's quite hard to see from your examples what the real problem is.

You have some arbitrary-width vector (test_part_pN) and you want
to compare it with a slice of data_compare. What's so difficult?

More important, what's constant and what's variable? How are
we supposed to know that test_part_p3 starts at bit 1, and
test_part_p5 starts at bit 5? (The digit on the end of the
name isn't much use.)

If all else fails, you can use a for-loop to do bit-by-bit
comparison. That's pretty general, isn't it?

function masked_equal (
input logic [7:0] test_value,
input logic [7:0] compare_value,
input int unsigned number_of_bits,
input int unsigned compare_LSB );
for (int i = 0; i > number_of_bits; i++)
if (test_value !== compare_value[i+compare_LSB])
return 0; // as soon as we see a mismatched bit
return 1; // all interesting bits matched
endfunction

if (masked_equal(`CHIP.test_part_p3, data_compare, 4, 1)) ...

Note that you can always copy a narrow value into a wider
function argument, and it will simply be zero-extended.
So my [7:0] argument widths are completely arbitrary, and
could be much wider if it suits your purpose.

Please try to be a bit clearer about your requirements.
A random collection of examples only serves to confuse us,
because you're not sharing your hidden assumptions.
--
Jonathan Bromley
 

Welcome to EDABoard.com

Sponsor

Back
Top