Sll may do an arithmetical shift for signed inputs, both sll and srl can take a negative shift, and do something with it in operators overloading. If You want use sll and/or sla You must do it much carefully and with full understanding what do You really do. Shiftreg <= shift_left(shiftreg, to_integer(unsigned(shift_offset))) If the shift_offset is an object of an array type, You need to convert it to integer (it would be better if to natural). Shiftreg <= shift_left(shiftreg, shift_offset) there shiftreg : unsigned(D_WIDTH-1 downto 0) or shiftreg : signed(D_WIDTH-1 downto 0) If you will pass an unsigned data to shift_left - it wil be a logical left shift. If you will pass a signed data to shift_left - it will be an arithmetic left shift. You can read about these problems there: Firstly, there are problems with these operators, so it is better to use the shift_left() function. Shiftreg(shiftreg'left-1 downto 0) <= shiftreg(shiftreg'left-2 downto 0) & '0' Įnd loop There also is the library function shift_left() and operators sll and sla. Shiftreg <= shiftreg(shiftreg'left-1 downto 0) & '0' Įnd loop or for arithmetic shift left: for i in 0 to shift_offset loop There is one more way without using either library functions or operators: for i in 0 to shift_offset loop Shiftreg <= shiftreg(shiftreg'left) & shiftreg(shiftreg'left-2-shift_offset downto 0) & data_i (if it is an arithmetical left shift) Shiftreg <= shiftreg(shiftreg'left-1-shift_offset downto 0) & data_i Shiftreg : std_logic_vector(D_WIDTH-1 downto 0) I use the concatenation operator usually. If you must use a function, use the shift_left in the library ieee.numeric_std. Ideally, you can easily shift left with regular code, which is ideal, clear, and easy to maintain.Ģ. Plus people may not know how they work which creates wasted time in either bugs from misuse or having to go look something up for code maintenance. The risk is that functions are contained in libraries that can change, conflict, or be removed. Usually, functions are only helpful if they save multiple lines of code. That's why I prefer do it manually, since it's about the same lines of code, and it's clear what is happening. While there are functions out there, like shift_left from the ieee.numeric_std library, many people may not know exactly what the library does and will have to either guess or go look it up if they come across your code. Output(15 downto 0) <= input(11 downto 0) & "0000" PurposeShifting left happens a lot in digital design. Shift Left in VHDL Quick Syntax - shift left 1-bit
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |