# Finding simulator-specific range for user-defined physical type

I want to find out the maximum range for user-defined physical types like the following:

type resistance is range 0 to 1_000_000
units
Ohm;
kOhm = 1000 Ohm;
MOhm = 1000 kOhm;
end units resistance;


Documentation for physical types (VHDL LRM sections 3.1.3 and 3.1.2) says that the range is of integer type, so I could write range integer'low to integer'high which is the same as range -2_147_483_648 to 2_147_483_647. However, my simulator seems to use 64-bit arithmetic here, and range -40_000_000_000_000 to 40_000_000_000_000 also works, as does range -2**62 to 2**62 (while 2**63 does not).

Is there a canonical way to find out the simulator-supported range? If not, how would I put the empirically-found 2**62 into a constant (for externalizing such simulator-specific code)? An integer constant won't cut it :)

• To answer my last question myself, a workaround is to define e.g. constant c_simulator_physical_type_wid : positive := 64; in a package and then use it like range -2**(c_simulator_physical_type_wid-2) to 2**(c_simulator_physical_type_wid-1) (which is what my simulator will accept). – cmarqu Sep 7 '11 at 11:08
• Interestingly enough, our tool vendor didn't reply to my now months-old support request yet. :) – cmarqu Jan 4 '12 at 9:50

## 1 Answer

The VHDL language reference (LRM) dictates that user defined integer types of at least 32 bits should be supported. If you use anything larger than that, you are writing code that is not guaranteed to work on other simulators.

I'd advice against using larger ranges than what is guaranteed to be supported.

• I started out with the regular integer range, but it turns out that this is not sufficient when you want to do calculations with voltages in the microvolt range (so the primary unit needs to be nanovolt) while representing normal supply voltages as well. One could introduce coarse and fine voltages (similar to VHDL-AMS's tolerance groups) but that's more hassle than it's worth. So I decided to accept a possible simulator-dependency rather than incurring that burden or not use physical types altogether. Luckily we don't switch simulators often :) – cmarqu Sep 7 '11 at 12:26
• "Luckily we don't switch simulators often :)" True, but your customers may have a different simulator, or you may want to reuse the project in five years, when you have changed simulators. But I understand that this is the least problematic solution for you. I wonder if there are other ways to deal with this... – Philippe Sep 8 '11 at 9:54