Comments (8)
Just saw that H.7.4 does map SV data types to C types and found LONG_MIN to be -2147483647 in the standard.
from slang.
In the C definition, INT_MIN is -32767, but neither of the following give a warning. I increased the value to be an even larger negative number and still didn't get a warning. Is the literal value always being assumed to be 32-bit?
class C;
function f();
shortint a = -32768;
shortint b = shortint'(-32768);
endfunction
endclass
from slang.
So there's a few things happening here. First, literal integers without a base are always 32-bits (or larger; the LRM 5.7.1 says "The number of bits that make up an unsized number (which is a simple decimal number or a number with a
base specifier but no size specification) shall be at least 32.") Regardless of where it's used or what's on the lhs of an assignment, the literal itself has that type.
Second, there isn't really such a thing as a negative literal integer; the minus sign is the minus operator applied to the positive literal. That's why you're getting that warning; the lexer produces the integer token and sees that it overflows the positive bounds. The minus sign then gets applied to that overflowed value, but in two's complement negating the most negative integer like that just produces the same most negative value, so you end up with the right result anyway. I could add something to suppress the warning in this case because it's kind of unhelpful, but VCS does issue the same warning so maybe it's helpful to have parity?
Warning-[DCTL] Decimal constant too large
testbench.sv, 5
Decimal constant '2147483648' is too large as a 32bit signed constant, it
should be smaller than 2147483648.
VCS is using converted signed value '-2147483648' instead.
To make it an unsigned constant, please use sized constant format.
For the shortint case, you don't get the same warning because the integer literal is still a signed 32-bit value and it fits comfortably. You should get a Wconstant-conversion warning when assigned to a shortint because the value gets truncated, but for some reason that's not working. I'll fix that.
Finally, the C definitions for INT_MIN / LONG_MIN in specification only provide min values (that are symmetric with their positive values, in case an implementation doesn't use two's complement I guess). Actual implementations use values that match the real bounds of their types, for example with gcc on x86_64 INT_MIN is -2147483648
as you'd expect for a 32-bit signed integer. I think this detail is mostly irrelevant as far as SystemVerilog types are concerned, Annex H is just about DPI interop.
from slang.
Also LRM 11.3.3 has more light on this subject:
int IntA;
IntA = -12 / 3; // The result is -4
IntA = -'d 12 / 3; // The result is 1431655761
IntA = -'sd 12 / 3; // The result is -4
IntA = -4'sd 12 / 3; // -4'sd12 is the negative of the 4-bit
// quantity 1100, which is -4. -(-4) = 4
// The result is 1
from slang.
Thanks for the references.
from slang.
Using -32'sd214783648 does resolve the Slang (and presumably VCS) warning, but the shortint case with an explicit 16-bit signed format doesn't trigger the warning. Would you expect it to?
e.g.
shortint a = -16'sd32769;
from slang.
Yes indeed, there's a warning -Wvector-overflow which I think should trigger in this case but it's not considering the sign bit when checking.
from slang.
Issues in this thread should be fixed now.
from slang.
Related Issues (20)
- Make buffer reloading a first-class supported operation
- Improve messaging for duplicate drivers
- Add compile-time checking of $sscanf / $value$plusargs format strings
- Handle $bits of expressions that overflow a 32-bit size HOT 1
- Pattern variables are not visible from initializers in child scope
- Figure out how extern module declarations are supposed to work with libraries & configurations
- Handle the %p format specifiers in compile-time format strings
- Add a global check for overlapping net aliases
- Enforce dissimilar net type rules for implicit named port connections
- Add caching of identical instance bodies HOT 1
- Finish support for 1800-2023 LRM changes
- Port Python bindings to nanobind HOT 1
- Add a stress test for concurrently visiting the AST
- Check for blocking delays in tasks called from always_comb/_latch/_ff
- slang-netlist appends garbage at end of (short) .dot files
- Initial value of automatic function return value HOT 6
- Question: How to get the raw text of port defined type HOT 1
- Let slang ignore backslashes at the end of lines in a -f file HOT 1
- tools/netlist unittest failure for v6.0 package release HOT 4
- The bit/part-select results should be unsigned. But not in slang v3.0. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slang.