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
2.Is it legal to multiply an unsigned vector with an integer? Or both operands must be of the same type?
Tricky are you sure you aren't mistaken, I just looked at the package on the IEEE site and the 1076.2-1996 package doesn't define * for unsigned/signed.numeric_std defines * for unsigned/signed * integer and integer * unisnged/signed.
natural and positive are subtypes of integer, so will work just fine.
You really need a good reference book - this is basic stuff.
https://www.doulos.com/content/products/golden_reference_guides.php
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 -- Id: A.15 function "*" (L, R: UNSIGNED) return UNSIGNED; -- Result subtype: UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0) -- Result: Performs the multiplication operation on two UNSIGNED vectors -- that may possibly be of different lengths. -- Id: A.16 function "*" (L, R: SIGNED) return SIGNED; -- Result subtype: SIGNED((L'LENGTH+R'LENGTH-1) downto 0) -- Result: Multiplies two SIGNED vectors that may possibly be of -- different lengths. -- Id: A.17 function "*" (L: UNSIGNED; R: NATURAL) return UNSIGNED; -- Result subtype: UNSIGNED((L'LENGTH+L'LENGTH-1) downto 0) -- Result: Multiplies an UNSIGNED vector, L, with a nonnegative -- INTEGER, R. R is converted to an UNSIGNED vector of -- SIZE L'LENGTH before multiplication. -- Id: A.18 function "*" (L: NATURAL; R: UNSIGNED) return UNSIGNED; -- Result subtype: UNSIGNED((R'LENGTH+R'LENGTH-1) downto 0) -- Result: Multiplies an UNSIGNED vector, R, with a nonnegative -- INTEGER, L. L is converted to an UNSIGNED vector of -- SIZE R'LENGTH before multiplication. -- Id: A.19 function "*" (L: SIGNED; R: INTEGER) return SIGNED; -- Result subtype: SIGNED((L'LENGTH+L'LENGTH-1) downto 0) -- Result: Multiplies a SIGNED vector, L, with an INTEGER, R. R is -- converted to a SIGNED vector of SIZE L'LENGTH before -- multiplication. -- Id: A.20 function "*" (L: INTEGER; R: SIGNED) return SIGNED; -- Result subtype: SIGNED((R'LENGTH+R'LENGTH-1) downto 0) -- Result: Multiplies a SIGNED vector, R, with an INTEGER, L. L is -- converted to a SIGNED vector of SIZE R'LENGTH before -- multiplication.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 -- Id: A.15 function "*" (L, R : UNRESOLVED_UNSIGNED) return UNRESOLVED_UNSIGNED; -- Result subtype: UNRESOLVED_UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0) -- Result: Performs the multiplication operation on two UNRESOLVED_UNSIGNED vectors -- that may possibly be of different lengths. -- Id: A.16 function "*" (L, R : UNRESOLVED_SIGNED) return UNRESOLVED_SIGNED; -- Result subtype: UNRESOLVED_SIGNED((L'LENGTH+R'LENGTH-1) downto 0) -- Result: Multiplies two UNRESOLVED_SIGNED vectors that may possibly be of -- different lengths. -- Id: A.17 function "*" (L : UNRESOLVED_UNSIGNED; R : NATURAL) return UNRESOLVED_UNSIGNED; -- Result subtype: UNRESOLVED_UNSIGNED((L'LENGTH+L'LENGTH-1) downto 0) -- Result: Multiplies an UNRESOLVED_UNSIGNED vector, L, with a nonnegative -- INTEGER, R. R is converted to an UNRESOLVED_UNSIGNED vector of -- SIZE L'LENGTH before multiplication. -- Id: A.18 function "*" (L : NATURAL; R : UNRESOLVED_UNSIGNED) return UNRESOLVED_UNSIGNED; -- Result subtype: UNRESOLVED_UNSIGNED((R'LENGTH+R'LENGTH-1) downto 0) -- Result: Multiplies an UNRESOLVED_UNSIGNED vector, R, with a nonnegative -- INTEGER, L. L is converted to an UNRESOLVED_UNSIGNED vector of -- SIZE R'LENGTH before multiplication. -- Id: A.19 function "*" (L : UNRESOLVED_SIGNED; R : INTEGER) return UNRESOLVED_SIGNED; -- Result subtype: UNRESOLVED_SIGNED((L'LENGTH+L'LENGTH-1) downto 0) -- Result: Multiplies an UNRESOLVED_SIGNED vector, L, with an INTEGER, R. R is -- converted to an UNRESOLVED_SIGNED vector of SIZE L'LENGTH before -- multiplication. -- Id: A.20 function "*" (L : INTEGER; R : UNRESOLVED_SIGNED) return UNRESOLVED_SIGNED; -- Result subtype: UNRESOLVED_SIGNED((R'LENGTH+R'LENGTH-1) downto 0) -- Result: Multiplies an UNRESOLVED_SIGNED vector, R, with an INTEGER, L. L is -- converted to an UNRESOLVED_SIGNED vector of SIZE R'LENGTH before -- multiplication.
function "*" (L : UNRESOLVED_UNSIGNED; R : NATURAL) return UNRESOLVED_UNSIGNED;
-- Result subtype: UNRESOLVED_UNSIGNED((L'LENGTH+L'LENGTH-1) downto 0)
-- Id: A.3
function "+" (L, R: UNSIGNED) return UNSIGNED;
-- Result subtype: UNSIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0).
-- Result: Adds two UNSIGNED vectors that may be of different lengths.
ads-ee,
post #6 is VERY helpful.
I couldn't find this package on IEEE site.
I found it on another site, but I'd like to have the original reference.
Can you please post the link ?
- - - Updated - - -
I stumbled upon this definition of the "+" function:
Can't find the scene behind it.Code:-- Id: A.3 function "+" (L, R: UNSIGNED) return UNSIGNED; -- Result subtype: UNSIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0). -- Result: Adds two UNSIGNED vectors that may be of different lengths.
I'd expect the function to take into consideration the possibility of an overflaw and the result to be defined as one bit longer than the longest of operands - yet I see the length of the result is simply defined as the length of the longest operand without any extra bits.
Am I missing something?
If you want overflow taken into consideration, then you should consider using the fixed point package instead.Can't find the scene behind it.
I'd expect the function to take into consideration the possibility of an overflaw and the result to be defined as one bit longer than the longest of operands - yet I see the length of the result is simply defined as the length of the longest operand without any extra bits.
Am I missing something?
op <= ('0' & a) + ('0' & b);
op <= resize(a, op'length) + b;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?