Shift arithmetic problem for noob

Discussion in 'VHDL' started by jeucomanu@virgilio.it, Nov 1, 2007.

  1. Guest

    hi everybody,

    how i can traslate this line in C

    varA = (varA<<4) + varB;

    in VHDL language????

    wrong exemple

    varA <= (varA sll 4) + varB;

    My problem is the shift "<<" i try with SHL, sll, ecc. but i cant
    compile the vhdl because there is some error.
    I have include librerie std_logic_arith "use
    IEEE.std_logic_arith.all;" but have this error:

    Operator "sll" is not defined for such operands.
    Undefined type of expression.
    Assignment target incompatible with right side. Expected type
    "std_logic_vector".

    i have tray with different type: std_logic_vector, integer, bit_vector
    but i have the same result, error on compile.

    pls, help me.

    Jeuco
    , Nov 1, 2007
    #1
    1. Advertising

  2. KJ Guest

    <> wrote in message
    news:...
    > hi everybody,
    >
    > how i can traslate this line in C
    >
    > varA = (varA<<4) + varB;
    >
    > in VHDL language????
    >
    > wrong exemple
    >
    > varA <= (varA sll 4) + varB;
    >
    > My problem is the shift "<<" i try with SHL, sll, ecc. but i cant
    > compile the vhdl because there is some error.
    > I have include librerie std_logic_arith "use
    > IEEE.std_logic_arith.all;" but have this error:
    >
    > Operator "sll" is not defined for such operands.
    > Undefined type of expression.
    > Assignment target incompatible with right side. Expected type
    > "std_logic_vector".
    >
    > i have tray with different type: std_logic_vector, integer, bit_vector
    > but i have the same result, error on compile.
    >


    Don't use std_logic_arith, use numeric_std instead.....and take a look at
    the shift_left function it does exactly what you want

    KJ
    KJ, Nov 1, 2007
    #2
    1. Advertising

  3. Andy Guest

    On Nov 1, 6:02 am, "KJ" <> wrote:
    >
    > Don't use std_logic_arith, use numeric_std instead.....and take a look at
    > the shift_left function it does exactly what you want
    >
    > KJ


    As does multiplication by a constant power of two for integer or
    numeric_std.signed/unsigned:

    varA <= varA * 2**4 + varB;

    If the length of varB is also 4 (or less), then the arithmetic will
    optimize out to just bit stuffing.

    Andy
    Andy, Nov 1, 2007
    #3
  4. Guest

    On 1 Nov, 21:40, Andy <> wrote:
    > On Nov 1, 6:02 am, "KJ" <> wrote:
    >
    >
    >
    > > Don't use std_logic_arith, use numeric_std instead.....and take a look at
    > > the shift_left function it does exactly what you want

    >
    > > KJ

    >
    > As does multiplication by a constant power of two for integer or
    > numeric_std.signed/unsigned:
    >
    > varA <= varA * 2**4 + varB;
    >
    > If the length of varB is also 4 (or less), then the arithmetic will
    > optimize out to just bit stuffing.
    >
    > Andy


    Ok, i now this trick and there are another solution for bypass the
    problem but i want know why sll don't work and resolve the problem for
    use sll or SHl?

    anybody can explain me?
    , Nov 1, 2007
    #4
  5. Mike Treseler, Nov 2, 2007
    #5
  6. Guest

    On 2 Nov, 17:22, Mike Treseler <> wrote:
    > wrote:
    > > Ok, i now this trick and there are another solution for bypass the
    > > problem but i want know why sll don't work and resolve the problem for
    > > use sll or SHl?

    >
    > > anybody can explain me?

    >
    > http://groups.google.com/groups/search?q=sll shifter po_v


    but you read what i wrote? i don't want a trick o different solution,
    i want know why i cant compile vhdl whit operator SLL or SHL
    , Nov 3, 2007
    #6
  7. KJ Guest

    <> wrote in message
    news:...
    > On 2 Nov, 17:22, Mike Treseler <> wrote:
    >> wrote:
    >> > Ok, i now this trick and there are another solution for bypass the
    >> > problem but i want know why sll don't work and resolve the problem for
    >> > use sll or SHl?

    >>
    >> > anybody can explain me?

    >>
    >> http://groups.google.com/groups/search?q=sll shifter po_v

    >
    > but you read what i wrote? i don't want a trick o different solution,
    > i want know why i cant compile vhdl whit operator SLL or SHL
    >


    Well gee, you don't post your code and you expect people to tell you why
    your code doesn't compile? The data types matter, and the error messages
    that you are getting were telling you that the data types are not correct.
    Like all other functions and procedures, 'sll' expects certain data types
    as inputs and produces certain data types as outputs. Those definitions are
    not secrets, do a search for the the function definition of 'sll' and you
    will see what data types it expects and produces.

    For some sample code that uses sll in a manner similar to how you listed in
    your code snippet at the start of the thread, see below. It compiles and
    works so look at how your code differs from it...that is a likely source of
    your error.

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;

    entity foo is
    end foo;

    architecture RTL of foo is
    signal Vara, Varb, Varc: unsigned(7 downto 0);
    begin
    Vara <= "00000001";
    Varb <= "00000010";
    Varc <= (Vara sll 4) + Varb;
    end RTL;

    KJ
    KJ, Nov 3, 2007
    #7
    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. Roberto Gallo

    Shift - byte[] buf shift

    Roberto Gallo, Jan 27, 2004, in forum: Java
    Replies:
    3
    Views:
    2,018
    Thomas Schodt
    Jan 27, 2004
  2. Wenjie
    Replies:
    3
    Views:
    1,016
    Ron Samuel Klatchko
    Jul 11, 2003
  3. Santosh Nayak

    Left Shift / Right Shift Operators

    Santosh Nayak, Nov 30, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,429
    CBFalconer
    Nov 30, 2006
  4. Sanny
    Replies:
    38
    Views:
    3,338
    Thomas Richter
    Apr 29, 2011
  5. devphylosoff

    what "shift" does, if not "$_ = shift;" ?

    devphylosoff, Nov 29, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    313
    Michele Dondi
    Dec 4, 2007
Loading...

Share This Page