P
Pulzar
Guest
Let's say that you have a module that contains some memory storage, X*Y
bits large:
reg[X-1:0] RAM[Y-1:0];
X and Y are parameters of the module. Now, you have an index into the
memory that's one-hot encoded, so it is Y bits wide:
input[Y-1:0] index;
You'd like to output the appropriate piece of data, using something
like this...:
wire[X-1:0] oData =
(index[0]) ? RAM[0] :
(index[1]) ? RAM[1] :
(index[2]) ? ...
or through a similar case statement. Now, writing that out assumes a
constant value of Y. Is there a way to write that piece of logic using
the Y parameter so that the module can be truly parametrized?
Obviously, I could write a funciton that will convert one-hot to an
unsigned integer and then write
assign oData = RAM[unsigned_index];
....but synthesizing something like that would produce a less optimal
logic than a parallel case statement using the one-hot encoded index.
Any thoughts?
Stan
bits large:
reg[X-1:0] RAM[Y-1:0];
X and Y are parameters of the module. Now, you have an index into the
memory that's one-hot encoded, so it is Y bits wide:
input[Y-1:0] index;
You'd like to output the appropriate piece of data, using something
like this...:
wire[X-1:0] oData =
(index[0]) ? RAM[0] :
(index[1]) ? RAM[1] :
(index[2]) ? ...
or through a similar case statement. Now, writing that out assumes a
constant value of Y. Is there a way to write that piece of logic using
the Y parameter so that the module can be truly parametrized?
Obviously, I could write a funciton that will convert one-hot to an
unsigned integer and then write
assign oData = RAM[unsigned_index];
....but synthesizing something like that would produce a less optimal
logic than a parallel case statement using the one-hot encoded index.
Any thoughts?
Stan