Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

assigning a long array to a short array

Status
Not open for further replies.

shaiko

Advanced Member level 5
Joined
Aug 20, 2011
Messages
2,644
Helped
303
Reputation
608
Reaction score
297
Trophy points
1,363
Activity points
18,302
Code:
type long_array is array ( 0 to 3 ) of unsigned ( 8 downto 0 ) ;		
type short_array is array ( 0 to 3 ) of unsigned ( 7 downto 0 ) ;	

signal x : long_array ;
signal y : short_array ;

I want the lower 8 bits of each cell of array x to be assigned to the matching cells of array y.
I.E copy array x into array y while discarding the MSBs of array x.
This is what I wrote:

Code:
y <= x ( ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 ) ) ;

Modelsim compilation fails with the following message:
Slice range direction (downto) does not match slice prefix direction (to).

What's the reason?
From what I see, the slices range direction matches well...
 

What's the reason?
From what I see, the slices range direction matches well...
Code:
y <= x ( ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 ) ) ;

It looks like you have too many parentheses. I think the following is what you want, but I haven't tested it
Code:
y <= x  ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 );

Kevin Jennings
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
tried this:
Code:
y <= x ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 ) ;

The newer error says:
Cannot resolve slice name as type short_array.
 

tried this:
Code:
y <= x ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 ) ;
The newer error says:
That's because you defined both 'long_array' and 'short_array' as types instead of subtypes so you will need a type conversion function to convert from one to the other. So your choices are:
- Create a function that takes as input a 'long_array' and returns a 'short array' and keep the type definitions that you have
- Create a more general type, then make 'long_array' and 'short_array' be subtypes of the more general type. That way you don't need any type conversion function.

Example:
Code:
type array2d is array ( natural range <> ) of unsigned; -- Will need to compile with VHDL-2008 
subtype long_array is array2d( 0 to 3 ) ( 8 downto 0 );
subtype short_array is array2d( 0 to 3 ) ( 7 downto 0 );

Again, not tested.

Kevin Jennings
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Well,
Actually my code is much more general then what I wrote at first. This is how it looks now:
Code:
type type_array_unsigned is array ( natural range <> ) of unsigned ; -- defined in an external package.

An input port that uses the above custom type is defined as follows:
Code:
x : type_array_unsigned ( 0 to a - 1 ) ( b downto 0 ) ; -- a and b are entity generics.

A subtype and a corresponding signal are defined as follows:
Code:
subtype short_array_unsigned is type_array_unsigned ( 0 to a - 1 ) ( b - 1 downto 0 ) ;
signal y : short_array_unsigned ;

The rightmost bits of array input port x are assigned into array y :
Code:
y <= x ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 ) ;

Compilation fails with the following message:
(vcom-1012) Slice range direction (downto) does not match slice prefix direction (to).
 

Code:
genx : for i in x'range generate
    y(i) <= x(i)(x(0)'high - 1 downto 0);
end generate genx;
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
This works well.
Any idea as to why it fails in the prior examples? Can you point any VHDL rule violations?
 

You can only slice into a single dimension. Previously, you had two slices:

y <= x ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 ) ;

where you slice into the first array and 2nd array at the same time. That is not allowed.
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top