modulo function

Discussion in 'VHDL' started by qharz, May 18, 2009.

  1. qharz

    qharz Guest

    Hi
    I am quite fresh with vhdl and i have a problem. How to realize modulo
    function using signals not variables?
    For example: modulo_signal <= sample_signal mod 65536;

    Best regards,
    qharz
    qharz, May 18, 2009
    #1
    1. Advertising

  2. Re: modulo function

    On May 18, 11:39 pm, "qharz" <> wrote:
    > Hi
    > I am quite fresh with vhdl and i have a problem. How to realize modulo
    > function using signals not variables?
    > For example: modulo_signal <= sample_signal mod 65536;
    >
    > Best regards,
    > qharz


    If you need to calculate mod 2^n it is as simple as just using the
    array slice containing the data you seek.
    You know x mod m gives you the rest of the division of x/m. If m is
    2^n, you simply need to take the lower n bits of the array to get your
    result.

    x / m for m = 2^n is x >> m, the rest is then the part shifted away,
    or x - (( x >> m ) << m), or if x is an std_logic_vector( ? downto 0),
    result <= x( n - 1 downto 0);

    Hope that helps,
    Andreas Wallner
    AndreasWallner, May 19, 2009
    #2
    1. Advertising

  3. qharz

    qharz Guest

    Re: modulo function


    > x / m for m = 2^n is x >> m, the rest is then the part shifted away,
    > or x - (( x >> m ) << m), or if x is an std_logic_vector( ? downto 0),
    > result <= x( n - 1 downto 0);
    >

    It helps,
    Thank You very much

    qharz
    qharz, May 19, 2009
    #3
  4. qharz

    Andy Guest

    Re: modulo function

    On May 18, 4:39 pm, "qharz" <> wrote:
    > Hi
    > I am quite fresh with vhdl and i have a problem. How to realize modulo
    > function using signals not variables?
    > For example: modulo_signal <= sample_signal mod 65536;
    >
    > Best regards,
    > qharz


    As long as the signal data types are either integer,
    numeric_std.signed or .unsigned, your example will work just fine.
    Numeric_std defines the modulo operator with .unsigned, .signed or
    integer RH operands. It is also directly synthesizable so long as the
    RH operand is a static (i.e. value is known at synthesis time),
    integral power of two, which simplifies to simply a slice operation.
    For the purposes of synthesis, "static" also includes such things as
    for-loop indices, since loops are unrolled anyway.

    Andy
    Andy, May 19, 2009
    #4
    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. Christian Kruggel

    General modulo-question

    Christian Kruggel, Jul 7, 2003, in forum: Java
    Replies:
    1
    Views:
    429
    Brad BARCLAY
    Jul 7, 2003
  2. Replies:
    1
    Views:
    651
    Darryl L. Pierce
    May 20, 2004
  3. Tjerk Wolterink

    [xsl] sort & modulo

    Tjerk Wolterink, Apr 21, 2005, in forum: XML
    Replies:
    3
    Views:
    549
    Dimitre Novatchev
    Apr 22, 2005
  4. silentlights

    Fast Division/Modulo Operation

    silentlights, Apr 16, 2004, in forum: C Programming
    Replies:
    8
    Views:
    962
    Dik T. Winter
    Apr 23, 2004
  5. Murph
    Replies:
    4
    Views:
    519
    Ben Jones
    Dec 6, 2006
Loading...

Share This Page