Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8870339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:42:00+00:00 2026-06-14T17:42:00+00:00

I was wondering if integer overflow is defined in VHDL. I wasn’t able to

  • 0

I was wondering if integer overflow is defined in VHDL. I wasn’t able to find anything in the 2002 Specification.

As an example (Note, this might not compile, it’s just a generic example…):

entity foo is port (
    clk : std_logic
);
end entity;

architecture rtl of foo is
    signal x : integer range 0 to 2 := 0;
begin
    process (clk)
    begin
        if rising_edge(clk) then
            x <= x + 1;
        end if;
    end process;
end architecture;

It’s clear that x will go from 0 to 1, and then to 2. Is it defined what will happen on the next increment? Is that undefined behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:42:02+00:00Added an answer on June 14, 2026 at 5:42 pm

    for a test bench for rtl of foo in ghdl:

    ghdl -r foo_tb –wave=foo_tb.ghw
    ./foo_tb:error: bound check failure at foo_tb.vhdl:15
    ./foo_tb:error: simulation failed

    I added a context clause to Bill’s foo entity and architecture:

    library ieee;
    use ieee.std_logic_1164.all;
    
    entity foo is port (
    

    Line 15 is the signal assignment to x:

                x <= x + 1;
    

    This is a simulation error (occurs at runtime).

    From IEEE 1076-1993:

    7.2.4 Adding operators

    The adding operators + and – are predefined for any numeric type and have their conventional mathematical meaning.

    This means the result of the "+" operator can be outside the subtype constraint of x. Note that a function declared to provide an overload for the "+" is not allowed to specify the result subtype. (The returned value may be an object declared with a subtype indication, which can define the value range or an array length).

    and 12.6.2 Propagation of signal values

    In order to update a signal during a given simulation cycle, the kernel process first determines the driving and effective values of that signal. The kernel process then updates the variable containing the current value of the signal with the newly determined effective value, as follows:

    a) If S is a signal of some type that is not an array type, the effective value of S is used to update the current value of S. A check is made that the effective value of S belongs to the subtype of S. An error occurs if this subtype check fails. Finally, the effective value of S is assigned to the variable representing the current value of the signal.

    If the result of the addition doesn’t match the subtype constraint of the target x it will generate an error. That subtype constraint is provided by the object x declaration which provides a subtype indication for an integer (the range).

    A run-time error causes the simulation to terminate for an LRM compliant implementation.

    Without a standardized format for error reporting ghdl does not provide the current simulation time. That can be found be examining the produced waveform:

    foo_tb.png

    The waveform quite being updated after 20 ns. The next scheduled event:

    library ieee;
    use ieee.std_logic_1164.all;
    
    entity foo_tb is
    end entity;
    
    architecture foo of foo_tb is
        signal clk: std_logic := '0';
    begin
    DUT:
        entity work.foo
            port map (
                clk => clk
            );
            
    CLOCK:
        process
        begin
            wait for 5 ns;
            clk <= not clk;
            if now > 30 ns then
                wait;
            end if;
        end process;
        
    end architecture;
    

    would have been the rising edge of clk at 25 ns.

    So this tells us how a constrained integer produces an overflow error.

    What about an integer without a subtype constraint:

    architecture fum of foo is
        signal x : integer := INTEGER'HIGH - 2;
    begin
        process (clk)
        begin
            if rising_edge(clk) then
                x <= x + 1;
            end if;
        end process;
    end architecture;
    

    We define x as an unconstrained integer set it’s default value where we expect x to overflow.

    Package standard explicity declares INTEGER "+":

    --  function "+"      (anonymous, anonymous: INTEGER) return INTEGER;
    

    The expected result is outside the range of INTEGER if as we see "+" has it’s ordinary mathematical meaning.

    However, from the implementation dependent declaration in package standard:

    type integer is range -2147483648 to 2147483647;
    

    and simulation:

    foo_tb_wrap_around.png

    We see the value of x wrap around.

    The assignment of the "+" operator result violated no constraint:

    3 Types:

    The set of possible values for an object of a given type can be subjected to a condition that is called a constraint (the case where the constraint imposes no restriction is also included); a value is said to satisfy a constraint if it satisfies the corresponding condition. A subtype is a type together with a constraint. A value is said to belong to a subtype of a given type if it belongs to the type and satisfies the constraint; the given type is called the base type of the subtype. A type is a subtype of itself; such a subtype is said to be unconstrained (it corresponds to a condition that imposes no restriction). The base type of a type is the type itself.

    In our second architecture and there is no constraint but there are no possible values outside the declared range for type INTEGER. The value instead rolls over.

    The semantics for VHDL have been constructed to not require detection here and this matches mathematical operations on single dimensional arrays of elements representing binary bits (hardware).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just wondering how disastrous integer overflow really is. Take the following example
I am just wondering whether differences will stay correct through an overflow. As example,
Just wondering if this and other related functions like those Integer is one of
Was reading the PHP manual on integer overflow in the manual and was wondering:
This must be quite basic, but I was wondering how to add an integer
I am wondering if we can use index to access List For example: List<Integer>
I was wondering how to initialise an integer array such that it's size and
I was wondering what the easiest way is to convert an integer to the
I was wondering, what would be the best way to validate an integer. I'd
Wondering what the best / good way of doing this would be in jQuery.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.