Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sure I can - this is what I do now.you can cast std to unsigned and use resize, or just use '&' aggregate
Function "resize" works on types "signed" and "unsigned".
Is there a standard VHDL function that does the same on std_logic_vector?
No there isnt, because resizing a std_logic_vector wouldnt make much sense. More logical to slice it or just append/prepend a load of '0's
Of course you can write your own resize function.
Code VHDL - [expand] 1 2 3 4 5 6 7 sig1 : std_logic_vector(11 downto 0); sigN : std_logic_vector(N-1 downto 0); sig1assign : std_logic_vector(15 downto 0); sigNassign : std_logic_vector(15 downto 0); sigAassign = "0000" & sig1; sigNassign = ???? & signN; -- how do you define the 16-N width of the ???? vector?
You're example is very similar to the piece of code that made me post this question...I can actually see shaiko's reasoning behind a resize function.
Code Verilog - [expand] 1 2 3 4 5 parameter N = 12; wire [N-1:0] sigN; wire [15:0] sigNassign; // appends the correct number of 0's to the beginning of sigN to make the assignment to sigNassign exactly 16-bits. assign sigNassign = {{16-N{1'b0}}, sigN};
You can use the attribute length of the signal
sigNassign <= resize(unsigned(sigN), sigNassign'length);
It should always work.
Code VHDL - [expand] 1 2 3 4 5 6 7 sig1 : std_logic_vector(11 downto 0); sigN : std_logic_vector(N-1 downto 0); sig1assign : std_logic_vector(15 downto 0); sigNassign : std_logic_vector(15 downto 0); sigAassign = "0000" & sig1; sigNassign = ???? & signN; -- how do you define the 16-N width of the ???? vector?
So how are you supposed to deal with the variable width signN vector? I'm not sure how you define the ????. I suppose I could look in the numeric_std package, but as I don't use VHDL much and am too lazy to find the package. ;-)
This is the type of assignment I was thinking of (I think it might be the same for shaiko). Basically there isn't a more "elegant" way to do it using a single line? Now that I see this, I remember doing exactly this when I used to use VHDL regularly (It always seemed a bit hokey).or outside a process:
sigNassign(sigNassign'high downto N) <= (others => '0');
sigNassign(N-1 downto 0) <= sigN;
On a side note, it always bugged me how it seems like you have to create your own RTL language by creating a plethora of functions to get VHDL to look at least somewhat readable. I recall one design that had all the IO wrapped inside some functions that had all these cryptic cell names to signify all of it's attributes. To me that doesn't make things more readable.
IMO readability isn't for your benefit (the engineer who writes the code), but is for when you get fired/quit/layoff and the next schmuck has to take over. I've been that schmuck before trying to understand some cryptically written VHDL that was written I believe for job security by obfuscation (they must have been an idiot).
I like your SV interpretation. :grin: And unfortunately there's some truth to it. SV is a whole lot better than Verilog, but still has some curious stupidity in it that has a "design by commitee" smell to it. Still, of those three SV is the closest to usable IMO. But that is of course subject to personal taste.