shaiko
Advanced Member level 5
- Joined
- Aug 20, 2011
- Messages
- 2,644
- Helped
- 303
- Reputation
- 608
- Reaction score
- 297
- Trophy points
- 1,363
- Activity points
- 18,302
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.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, 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.Does Verilog have the same limiting factor ?
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.
An std_logic_vector is useless for numbers
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 ?
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;
Code VHDL - [expand] 1 2 3 signal xyz: unsigned(32 downto 0); xyz <= decimal_string_to_unsigned("5000000000", 33);
xyz <= decimal_string_to_unsigned("5000000000", log2_unsigned (5000000000) );
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
Code VHDL - [expand] 1 2 xyz <= decimal_string_to_unsigned("5000000000", 64); xyz <= decimal_string_to_unsigned("5000000000", xyz'length);
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);
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?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?