[SOLVED] Problem with array of register.

Status
Not open for further replies.

ismailov-e

Member level 1
Joined
Jan 26, 2015
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
295
Hi everybody!!
I have a stuck to compare a portion of bytes of two registers.
I have a 2 register with 20 byts of width. The value of 1st registers always changes by loop. I want to compare only some portion of two register(let it be 64 bit, 8byte). But the length of comparing bits is variable(can change value). If i use a loop variable in indeces, the bag accur as it is a not a constant.
In this case i want to use only first 63 bits. Now "pattlen = 63"

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
initial begin
 if (state == C) begin
  pattlen = (countp*8)-1;
  for (i = 5; i < 15; i = i + 1)begin
    for (k = 0; k < 4; k = k + 1)begin
    buffshift[167:160] = slv_reg[i][(k*8)+:8];
    buffshift[159:0] = buffshift[167:8];
    if (buffpatt[pattlen:0] == buffshift[pattlen:0])
    wordcount = wordcount + 1;
    $display("%b %d",buffshift,wordcount);
    end
  end
end
//state = D;
end


I cant use bit-slice as the right site should be constant

Code Verilog - [expand]
1
if (buffpatt[0+:pattlen] == buffshift[0+:pattlen])

 

You'll have a another iteration loop that performs a bit-wise compare.

It should be noted that if the code is intended for synthesis, the variable length compare translates to a huge amount of combinatorial logic.
 
Lopps in Verilog and VHDL represent replication spacially, which is not the same as a temporal repeatition. Hence, loops when synthsized into logic or elaborated for simulation must have a constant for the number of itterations.

Ask yourself hoow can this circuit be realized if the circuit has to change the amount of logic that exists on the fly?

This is the saame reason you can't use a varable width for a bitslice as it implies dynamically generated logic.

Another observation is you seem to be trying to decode some state variable in an initial block. Initial blocks are only executeed once at time 0. As your state machine can't execute in 0 ns, that if compare will fail and none of the for loop logic will used.

You have to step back and not attempt to implement this as a software program, but think of what hardware logic gates and registers you need.
 

Thank you gays all of you!!
I solve the problem with bitwise operation.
if ((buffpatt & buffshift) == buffpatt)
then
wordcount = wordcount + 1;
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…