+ Post New Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 22
  1. #1
    Advanced Member level 5
    Points: 12,974, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,595
    Helped
    302 / 302
    Points
    12,974
    Level
    27

    VHDL highest possible integer

    A VHDL integer is defined from range -2147483648 to +2147483647.
    What if we want to use higher values and still use base 10 numbers to describe our hardware ?
    Is it possible to extand this value ?

  2. #2
    Full Member level 2
    Points: 984, Level: 7

    Join Date
    Mar 2012
    Posts
    133
    Helped
    21 / 21
    Points
    984
    Level
    7

    Re: VHDL highest possible integer

    As far as I know, it is limited to 32-bit and cannot be extended.
    Can you tell us more on what you are trying to do?


    1 members found this post helpful.

  3. #3
    Advanced Member level 2
    Points: 5,197, Level: 17

    Join Date
    Jan 2012
    Posts
    658
    Helped
    310 / 310
    Points
    5,197
    Level
    17

    Re: VHDL highest possible integer

    Quote Originally Posted by shaiko View Post
    A VHDL integer is defined from range -2147483648 to +2147483647.
    What if we want to use higher values and still use base 10 numbers to describe our hardware ?
    Is it possible to extand this value ?
    No you cannot extend the range of integers. You would have to use type signed and forego any calls to the 'to_integer()' function. That would get you up to 2^(2^31) range.

    Kevin Jennings


    1 members found this post helpful.

  4. #4
    Advanced Member level 5
    Points: 12,974, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,595
    Helped
    302 / 302
    Points
    12,974
    Level
    27

    Re: VHDL highest possible integer

    Does Verilog have the same limiting factor ?



    •   AltAdvertisment

        
       

  5. #5
    Advanced Member level 3
    Points: 6,342, Level: 18
    Achievements:
    Created Blog entry 7 years registered

    Join Date
    Dec 2011
    Location
    Fremont, CA, USA
    Posts
    770
    Helped
    351 / 351
    Points
    6,342
    Level
    18
    Blog Entries
    4

    Re: VHDL highest possible integer

    Quote Originally Posted by shaiko View Post
    Does Verilog have the same limiting factor ?
    No, Verilog does not have the concept of an integer range, only bit widths. An integer type is a short-cut for reg signed [31:0]. SystemVerilog as longint, which is a 64-bit integer. Please note that many system functions assume 32-bit integers, so you need to be aware of that if it matters for what you are trying to do.
    Dave Rich
    Senior Verification Consultant
    Mentor Graphics Corporation


    1 members found this post helpful.

  6. #6
    Full Member level 1
    Points: 1,487, Level: 8
    ravics's Avatar
    Join Date
    Sep 2010
    Location
    Shangri-la
    Posts
    116
    Helped
    4 / 4
    Points
    1,487
    Level
    8

    Re: VHDL highest possible integer

    I think its integer range is limited to (2**31)-1, cannot exceed the range.
    I blog on FPGA Blog - Tumblr & FPGAConcepts - Wordpress



    •   AltAdvertisment

        
       

  7. #7
    Full Member level 1
    Points: 1,124, Level: 7

    Join Date
    Feb 2011
    Location
    Noida
    Posts
    115
    Helped
    4 / 4
    Points
    1,124
    Level
    7

    Re: VHDL highest possible integer

    I think VHDL integer can be extended by using "range" keyword. you can use following code:

    SIGNAL integer_1 : integer range 0 to 64;

    You can also use the above example for natural also.



    •   AltAdvertisment

        
       

  8. #8
    Advanced Member level 5
    Points: 37,355, Level: 47
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,793
    Helped
    1991 / 1991
    Points
    37,355
    Level
    47

    Re: VHDL highest possible integer

    Quote Originally Posted by er.akhilkumar View Post
    I think VHDL integer can be extended by using "range" keyword. you can use following code:

    SIGNAL integer_1 : integer range 0 to 64;

    You can also use the above example for natural also.

    You cannot extend it beyond the limits already specified. Also, natural is a subtype of integer, so cannot
    be extended.



  9. #9
    Full Member level 1
    Points: 1,124, Level: 7

    Join Date
    Feb 2011
    Location
    Noida
    Posts
    115
    Helped
    4 / 4
    Points
    1,124
    Level
    7

    Re: VHDL highest possible integer

    Yes you are write TrickyDicky, I mistakenly wrote.



  10. #10
    Advanced Member level 1
    Points: 4,716, Level: 16
    Achievements:
    7 years registered

    Join Date
    Dec 2007
    Location
    Bangalore, India
    Posts
    494
    Helped
    65 / 65
    Points
    4,716
    Level
    16

    Re: VHDL highest possible integer

    If you ever want to use more range, you should stick with SLV data type. You can have any number of bit width upto 256 bits.



  11. #11
    Advanced Member level 5
    Points: 37,355, Level: 47
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,793
    Helped
    1991 / 1991
    Points
    37,355
    Level
    47

    Re: VHDL highest possible integer

    A std_logic_vector is useless for numbers - it is not a numerical type. You want unsigned or signed, and there is no limit on the bit-width, and neither is there with SLV



  12. #12
    Advanced Member level 1
    Points: 4,716, Level: 16
    Achievements:
    7 years registered

    Join Date
    Dec 2007
    Location
    Bangalore, India
    Posts
    494
    Helped
    65 / 65
    Points
    4,716
    Level
    16

    Re: VHDL highest possible integer

    An std_logic_vector is useless for numbers
    What do you mean?. It is not numeral type,okay. But it can be used for numbers, B'coz numbers are data too.As for as I know, integer is a data type which can be used for easier numeral calculations and it is only the compiler that differentiates, but whether it is integer\SLV, it is all same in hardware...


    Also, I doubt if the synthesizer might synthesize bit width more than 256 bits though. Because I remember when I was working with Xilinx XST 8.2i, I received error about using bit wdith more than 256 bits in SLV. I think Xilinx uses VHDL-93
    Are you sure according to VHDL std?.



  13. #13
    Advanced Member level 5
    Points: 37,355, Level: 47
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,793
    Helped
    1991 / 1991
    Points
    37,355
    Level
    47

    Re: VHDL highest possible integer

    The VHDL standard has no limit on the width on any bus, other than the restrictions of the natural type. Why would it?
    Std_logic_vector is declared
    type std_logic_vector is array(natural range <>) of std_logic;

    so you can have a signal like this:
    signal my_slv : std_logic_vector(0 to natural'high);

    The limit you hit is a Xilinx compiler limit, not a VHDL one.

    As for std_logic_vectors and numbers - yes it could be a number, but a std_logic_vector is just a collection of bits, and it was never intedned to be treated as a number. You should use signed/unsigned type instead.


    1 members found this post helpful.

  14. #14
    Advanced Member level 3
    Points: 6,802, Level: 19
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    882
    Helped
    353 / 353
    Points
    6,802
    Level
    19

    Re: VHDL highest possible integer

    Quote Originally Posted by shaiko View Post
    A VHDL integer is defined from range -2147483648 to +2147483647.
    What if we want to use higher values and still use base 10 numbers to describe our hardware ?
    Is it possible to extand this value ?
    You can skip integers and write a function that takes a string and the wanted bit width as input and returns unsigned or signed. With this method you can use base 10 without a size limit.

    If you can accept hexadecimal instead of base 10 there is a simpler solution.
    There is no size limit for the x"<hex number>" notation.


    1 members found this post helpful.

  15. #15
    Advanced Member level 5
    Points: 12,974, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,595
    Helped
    302 / 302
    Points
    12,974
    Level
    27

    Re: VHDL highest possible integer

    std_match,

    Please post an example of such a function



  16. #16
    Advanced Member level 3
    Points: 6,802, Level: 19
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    882
    Helped
    353 / 353
    Points
    6,802
    Level
    19

    Re: VHDL highest possible integer

    Code VHDL - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
     
    function decimal_string_to_unsigned(decimal_string: string; wanted_bitwidth: positive) return unsigned is
      variable tmp_unsigned: unsigned(wanted_bitwidth-1 downto 0) := (others => '0');
      variable character_value: integer;
    begin
      for string_pos in decimal_string'range loop
        case decimal_string(string_pos) is
          when '0' => character_value := 0;
          when '1' => character_value := 1;
          when '2' => character_value := 2;
          when '3' => character_value := 3;
          when '4' => character_value := 4;
          when '5' => character_value := 5;
          when '6' => character_value := 6;
          when '7' => character_value := 7;
          when '8' => character_value := 8;
          when '9' => character_value := 9;
          when others => report("Illegal number") severity failure;
        end case;
        tmp_unsigned := resize(tmp_unsigned * 10, wanted_bitwidth);
        tmp_unsigned := tmp_unsigned + character_value;
      end loop;
      return tmp_unsigned;
    end decimal_string_to_unsigned;

    Use it like this:
    Code VHDL - [expand]
    1
    2
    3
    
    signal xyz: unsigned(32 downto 0);
     
    xyz <= decimal_string_to_unsigned("5000000000", 33);


    1 members found this post helpful.

  17. #17
    Advanced Member level 5
    Points: 12,974, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,595
    Helped
    302 / 302
    Points
    12,974
    Level
    27

    Re: VHDL highest possible integer

    Can I also use it like that ?

    Code:
    xyz <= decimal_string_to_unsigned("5000000000", log2_unsigned (5000000000) );
    This will eliminate the need to input the vector length of the integer string



    •   AltAdvertisment

        
       

  18. #18
    Advanced Member level 3
    Points: 6,802, Level: 19
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    882
    Helped
    353 / 353
    Points
    6,802
    Level
    19

    Re: VHDL highest possible integer

    Quote Originally Posted by shaiko View Post
    Can I also use it like that ?

    Code:
    xyz <= decimal_string_to_unsigned("5000000000", log2_unsigned (5000000000) );
    This will eliminate the need to input the vector length of the integer string
    You don't have to use the exact size as the argument. Normally you know the size you are dealing with.

    This is OK:

    Code VHDL - [expand]
    1
    2
    
    xyz <= decimal_string_to_unsigned("5000000000", 64);
    xyz <= decimal_string_to_unsigned("5000000000", xyz'length);

    If you want the minimum width to hold a number, you need to write a new version of log2_unsigned that also take a string as input.
    It should be rather straighforward. You an use decimal_string_to_unsigned as a template.
    You can use a very large internal tmp_unsigned and at the end look for the leftmost '1'.

    If you call it "decimal_string_bits_needed" you need to to something like this:
    Code VHDL - [expand]
    1
    2
    3
    4
    
    constant my_large_number: string := "5000000000";
    signal xyz: unsigned(decimal_string_bits_needed(my_large_number)-1 downto 0);
     
    xyz <= decimal_string_to_unsigned(my_large_number, xyz'length);

    One good improvement to "decimal_string_to_unsigned" is get an error or warning if the number doesn't fit in the specified number of bits.


    1 members found this post helpful.

  19. #19
    Advanced Member level 5
    Points: 12,974, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,595
    Helped
    302 / 302
    Points
    12,974
    Level
    27

    Re: VHDL highest possible integer

    If you want the minimum width to hold a number, you need to write a new version of log2_unsigned that also take a string as input.
    Why?
    Why can't I use the original log function?



  20. #20
    Advanced Member level 3
    Points: 6,802, Level: 19
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    882
    Helped
    353 / 353
    Points
    6,802
    Level
    19

    Re: VHDL highest possible integer

    Quote Originally Posted by shaiko View Post
    Why?
    Why can't I use the original log function?
    The input to the original function is probably integer or a subtype of integer, so it doesn't work for the numbers we are discussing now.



--[[ ]]--