sla and sra shifts

Discussion in 'VHDL' started by ohaqqi, Oct 18, 2006.

  1. ohaqqi

    ohaqqi

    Joined:
    Oct 15, 2006
    Messages:
    6
    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?
    ohaqqi, Oct 18, 2006
    #1
    1. Advertising

  2. ohaqqi

    joris

    Joined:
    Jan 29, 2009
    Messages:
    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:
    Code:
      function "sll"(val : std_logic_vector; shift : integer) return std_logic_vector is
        variable ret : std_logic_vector(val'range) := val;
      begin
        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;
      end;
    
    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)
    Code:
      function "sll"(val, shift : std_logic_vector) return std_logic_vector is
        variable sel : std_logic_vector(4 downto 0) := shift(4 downto 0);
      begin
        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;
      end;
    
    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)
    joris, Jan 29, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reid Nichol
    Replies:
    11
    Views:
    1,161
    Francesco Bochicchio
    Sep 11, 2004
  2. gamehack

    Bit shifts and endianness

    gamehack, Jan 5, 2006, in forum: C Programming
    Replies:
    72
    Views:
    6,813
    Dave Thompson
    Jan 11, 2006
  3. Dave

    shifts and masks

    Dave, Jun 3, 2006, in forum: C Programming
    Replies:
    4
    Views:
    438
    Malcolm
    Jun 4, 2006
  4. Dave

    replace bitfields with shifts and masks

    Dave, Jun 4, 2006, in forum: C Programming
    Replies:
    3
    Views:
    305
    Chris Torek
    Jun 4, 2006
  5. sri4ever

    ror and sla in vhdl

    sri4ever, Sep 27, 2011, in forum: VHDL
    Replies:
    1
    Views:
    1,684
    sri4ever
    Sep 27, 2011
Loading...

Share This Page