Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > sla and sra shifts

Thread Tools

sla and sra shifts

ohaqqi ohaqqi is offline
Junior Member
Join Date: Oct 2006
Posts: 7
A <= A sla to_integer(signed(B)) when (CODE = "10010");

gives errors:

** Error: alu16.vhd(73): No feasible entries for infix operator "sla".
** Error: alu16.vhd(73): Type error resolving infix expression "sla".

I have included 1164 and numeric_std libraries. Is this not the correct format for sla?
Reply With Quote
joris joris is offline
Senior Member
Join Date: Jan 2009
Posts: 152
I came across the same problem. The reason is, the shift operators are only defined on bitvectors.

It isn't very hard to get around this though, as VHDL allows to overload functions - and operators can be seen as function calls.
To define a "sll" for std_logic_vector:
  function "sll"(val : std_logic_vector; shift : integer) return std_logic_vector is
    variable ret : std_logic_vector(val'range) := val;
    if (shift /= 0) then
      for i in 1 to shift loop
        ret := ret(val'high - 1 downto val'low) & '0';
      end loop;
    end if;
    return ret;
That one assumes the most significant bit is at the high index. Perhaps it isn't the prettiest way of doing this but it works;

Then to have a "sll" shift, depending on a variable: (yes this is silly but it's really needed! It's recognised as an idiom, at least by Xilinx)
  function "sll"(val, shift : std_logic_vector) return std_logic_vector is
    variable sel : std_logic_vector(4 downto 0) := shift(4 downto 0);
    case sel is
      when "00000" => return (val sll 0);
      when "00001" => return (val sll 1);
      when "00010" => return (val sll 2);
      -- etc   
      when others  => return (val sll 31); -- "11111"
    end case;
Let me know if there's a better way of doing that.

One page, seems to suggest the expected functionality of sla is really to shift the left-most (least significant bit) like sra does with most significant bit. I don't really see why one would want that but it's trivial to adapt the code for such sla operator.
(I can't post the URL as a new member, the forum seems to forbid to avoid spammers)
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ror and sla in vhdl sri4ever VHDL 1 09-27-2011 04:29 AM
Re: IP SLA and HSRP - Please help Darren Green Cisco 1 04-30-2008 07:33 AM
qos policy and ip sla integration max Cisco 0 02-07-2008 08:55 AM
python and bit shifts and byte order, oh my! Reid Nichol Python 11 09-11-2004 09:08 AM
Poor Mans NIMH Battery Pack and SLA Battery Pack ajacobs2 Digital Photography 0 08-19-2003 12:42 PM