Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

how can i have a logical shift on std_logic_vector to left or right ??

Status
Not open for further replies.

fahim1

Member level 4
Joined
Jun 4, 2015
Messages
75
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Activity points
517
hi
I want to shift a std_logic_vector to left for one and two bits ,how can I do this?
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,652
Helped
1,774
Reputation
3,554
Reaction score
1,722
Trophy points
1,393
Location
USA
Activity points
57,812

Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
signal my_sig : std_logic_vector (31 downto  0);
 
-- left by 1:
my_sig <= my_sig(30 downto 0) & '0';
 
-- right by 1:
my_sig <= '0' & my_sig(31 downto 1);
 
-- left by 2:
my_sig <= my_sig(29 downto 0) & "00";



But there are probably some shortcuts for the ranges that I don't know about.
 
  • Like
Reactions: fahim1

    fahim1

    points: 2
    Helpful Answer Positive Rating

std_match

Advanced Member level 4
Joined
Jul 9, 2010
Messages
1,163
Helped
441
Reputation
882
Reaction score
407
Trophy points
1,363
Location
Sweden
Activity points
8,929
There are shift operators in VHDL but they should not be used. See rule C_31 in this collection of mostly good coding rules:

http://www.mikrocontroller.net/attachment/21066/VHDL_Coding_eng.pdf

What is the reason for banning integer and std_ulogic for synthesizeable code?
I think integer with a range can sometimes be motivated.

I don't know why std_logic should be avoided.
std_ulogic can reduce the debugging time by detecting multiple drivers at compile time instead of simulation or synthesis.
 

K-J

Advanced Member level 2
Joined
Jan 26, 2012
Messages
658
Helped
308
Reputation
620
Reaction score
301
Trophy points
1,343
Activity points
7,053
There are shift operators in VHDL but they should not be used. See rule C_31 in this collection of mostly good coding rules:
I wouldn't classify 'Rule C_31' in the category of 'good' rules.

What is the reason for banning integer and std_ulogic for synthesizeable code?
I think integer with a range can sometimes be motivated.

I don't know why std_logic should be avoided.
std_ulogic can reduce the debugging time by detecting multiple drivers at compile time instead of simulation or synthesis.
I agree, I always use std_ulogic so I don't waste my time debugging what the compiler would catch and it also represents more closely what actual implementation will be (i.e. a singly driven signal). So that puts 'Rule_C29' in the list of rules with which I would not agree.

Perusing their list further...
C_6: It frequently muddies the waters if you insist on only std_logic/std_logic_vector types for entity ports. For the top level entity I agree (but would use ulogic), but for embedded entities I do not agree.

C_13: Not every flip flop needs to be asynchronously reset.

C_18: There is no reason to avoid use of 'buffer' mode.

C_21: Is a pointless rule. Every compliant compiler has always flagged as an error the case where an input is unconnected with no default.

C_25: I've never seen recursive code not work. It certainly doesn't come up often and sometimes the recursive version is a bit more readable, but usually that is a wash and just somebody's preference.

C_28: While their caution regarding initialization is valid, allowing use of only std_logic, std_logic_vector, signed, unsigned types will result in less readable/supportable code. Their rule is overly restrictive for preventing the described problem. Besides, they do allow for enumerated types and they will have the same issue of initializing in sim to something that might not happen in the real part.

C_30: Do not agree. It is quite good to use record types as well as arrays of types. Even rule C_9 seems to allow for record type use, just not at a top level so they are violating rule C_30 when they allow use of a record since that is a user defined type.

C_33: Do not agree, one should use variables where it is appropriate. The only drawback I see to variables and the reason that I minimize their use is that they are not wavable in a simulation after the fact. So while I can log every signal and then add any signal in the entire system to see the total history when needed to debug a problem, you can't do that with variables without restarting the sim. Without restarting, you can see only the current value of the variable, but not the history. However, this is a limitation of the tools, not anything fundamentally wrong with variables.

C_37: Nothing wrong with using procedures in RTL, but appropriate use of procedures in RTL does not come up very often.

C_39: The gymnastics required to put "x <= y and z;" inside a sequential process makes the code harder to understand, not easier.

C_40: This rule is dated. If one uses VHDL-2008, then I do not agree since you can now say 'process(all)'. If you use an earlier language revision I do agree since it is too easy to create a latch by getting the sensitivity list wrong.

C_43: Conflicts with rule C_39 and is another example of when C_39 would not be valid.

C_45: I would say one clock per architecture, not entity. But even there, the dual clock FIFO that crosses the domains needs to go 'somewhere'.

C_47: Do not agree. It depends on the protocol of the interface of the entity. Examples of interfaces that typically require a non-clocked output are the 'waitrequest' of Avalon or 'ack' of Wishbone.

So of the 54 coding rules, I would disagree with 16 of them, but would consider the list to be a fairly decent set of guidelines overall. Also, to be fair, some of these rules may have motivated by bugs with vendor tools used by ALSE...and these rules are 10 years old so even ALSE today might not necessarily agree with everything that was written at that time.

Kevin Jennings
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,466
Helped
14,044
Reputation
28,341
Reaction score
12,695
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,048
Some of the quoted coding rules are, as I think, suggested by common sense like only using named association in port maps, but others end up in negating the high level features of VHDL.

I agree that the option to use abstracted behavioral code for hardware synthesis can mislead beginners, but it's an effective means to solve complex problems and I won't give it up.
 

K-J

Advanced Member level 2
Joined
Jan 26, 2012
Messages
658
Helped
308
Reputation
620
Reaction score
301
Trophy points
1,343
Activity points
7,053
C_13: Not every flip flop needs to be asynchronously reset.
I hadn't noticed it at first, but actually, the basis for rule C_13 is contained in the flawed process template presented for C_12. What was presented was:
Code:
process (Clk, Rst) -- ONLY Clk & async Rst in the sensitivity list !
begin
    if Rst='1' then
       -- <<< all regs initialized here ! >>>
    elsif rising_edge (Clk) then
       if Enable then -- Clock enable
          -- <<< Your code here >>>
       end if; -- do NOT insert code here !
    end if; -- nor here !
end process;
However, the proper template to use is the following:
Code:
process (Clk, Rst) -- ONLY Clk & async Rst in the sensitivity list !
begin
    if rising_edge (Clk) then
       if Enable then -- Clock enable
          -- <<< Your code here >>>
       end if; -- do NOT insert code here !
    end if; -- nor here !
    if Rst='1' then
       -- <<< all regs [COLOR="#FF0000"]that happen to need an initialization[/COLOR] here ! >>>
    end if; -- nor here !
end process;
Using the template provided in C_12, yes you can have problems if you don't put every signal inside the "if Rst='1'..." branch, so you had better follow C_13's recommendation. However, no such problems exist if you simply use the proper template. In that situation, there is no reason to follow rule C_13. So add rule C_12 to the list of things that are not correct.

Kevin Jennings
 

std_match

Advanced Member level 4
Joined
Jul 9, 2010
Messages
1,163
Helped
441
Reputation
882
Reaction score
407
Trophy points
1,363
Location
Sweden
Activity points
8,929
C_18: There is no reason to avoid use of 'buffer' mode.
Before VHDL 2002, a "buffer" output can not be connected to an "out" output at the higher level. This is painful, especially if you are writing reusable IP-blocks.

In VHDL 2008 and later, an "out" output can be read so "buffer" is not needed.

It is still common to use VHDL-93 in projects, so I never use "buffer". The safe way that works with all VHDL versions is to use "out", and having an intermediate signal if you need to read the value.

- - - Updated - - -

C_37: Nothing wrong with using procedures in RTL, but appropriate use of procedures in RTL does not come up very often.
One problem with procedures is that they can hide the complexity of the required logic. The source code can look simple, but the required logic could be very complex (= large and/or slow). There can be a much better way to do it, with a slightly more complicated source code. I think procedures should only be used for synthesis if the designer has a very good understanding of the required logic.

Procedures are very useful in test benches.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,466
Helped
14,044
Reputation
28,341
Reaction score
12,695
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,048
Before VHDL 2002, a "buffer" output can not be connected to an "out" output at the higher level. This is painful, especially if you are writing reusable IP-blocks.
This is right regarding officially agreed language specification. But the 1999/2000 draft already suggested to release the restriction. And some tools ignored it since ever.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top