You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Make non-suffixed integer literal type resolution conform to C
* Update integer literal tests
* Clean up integer literal implementation a bit
* Update docs on integer literals
* Clean up docs update
* Clean up docs update
* Add comment on INT64_MIN edge case
* Fixed failing test, fixed formatting and cleaned up code
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Copy file name to clipboardexpand all lines: docs/64bit-type-support.md
+31-10
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,8 @@ Slang 64-bit Type Support
5
5
6
6
* Not all targets support 64 bit types, or all 64 bit types
7
7
* 64 bit integers generally require later APIs/shader models
8
-
* When specifying 64 bit literals *always* use the type suffixes (ie `L`, `ULL`, `LL`)
8
+
* When specifying 64 bit floating-point literals *always* use the type suffixes (ie `L`)
9
+
* An integer literal will be interpreted as 64 bits if it cannot fit in a 32 bit value.
9
10
* GPU target/s generally do not support all double intrinsics
10
11
* Typically missing are trascendentals (sin, cos etc), logarithm and exponential functions
11
12
* CUDA is the exception supporting nearly all double intrinsics
@@ -28,7 +29,7 @@ This also applies to vector and matrix versions of these types.
28
29
29
30
Unfortunately if a specific target supports the type or the typical HLSL intrinsic functions (such as sin/cos/max/min etc) depends very much on the target.
30
31
31
-
Special attention has to be made with respect to literal 64 bit types. By default float and integer literals if they do not have an explicit suffix are assumed to be 32 bit. There is a variety of reasons for this design choice - the main one being around by default behavior of getting good performance. The suffixes required for 64 bit types are as follows
32
+
Special attention has to be made with respect to literal 64 bit types. By default float literals if they do not have an explicit suffix are assumed to be 32 bit. There is a variety of reasons for this design choice - the main one being around by default behavior of getting good performance. The suffixes required for 64 bit types are as follows
32
33
33
34
```
34
35
// double - 'l' or 'L'
@@ -40,27 +41,47 @@ double b = 1.34e-200;
40
41
// int64_t - 'll' or 'LL' (or combination of upper/lower)
41
42
42
43
int64_t c = -5436365345345234ll;
43
-
// WRONG!: This is the same as d = int64_t(int32_t(-5436365345345234)) which means d ! = -5436365345345234LL.
44
-
// Will produce a warning.
45
-
int64_t d = -5436365345345234;
46
44
47
45
int64_t e = ~0LL; // Same as 0xffffffffffffffff
48
-
// Does produce the same result as 'e' because equivalent int64_t(~int32_t(0))
49
-
int64_t f = ~0;
50
46
51
47
// uint64_t - 'ull' or 'ULL' (or combination of upper/lower)
52
48
53
49
uint64_t g = 0x8000000000000000ull;
54
-
// WRONG!: This is the same as h = uint64_t(uint32_t(0x8000000000000000)) which means h = 0
55
-
// Will produce a warning.
56
-
uint64_t h = 0x8000000000000000u;
57
50
58
51
uint64_t i = ~0ull; // Same as 0xffffffffffffffff
59
52
uint64_t j = ~0; // Equivalent to 'i' because uint64_t(int64_t(~int32_t(0)));
60
53
```
61
54
62
55
These issues are discussed more on issue [#1185](https://github.com/shader-slang/slang/issues/1185)
63
56
57
+
The type of a decimal non-suffixed integer literal is the first integer type from the list [`int`, `int64_t`]
58
+
which can represent the specified literal value. If the value cannot fit, the literal is represented as an `uint64_t`
59
+
and a warning is given.
60
+
The type of a hexadecimal non-suffixed integer literal is the first type from the list [`int`, `uint`, `int64_t`, `uint64_t`]
61
+
that can represent the specified literal value. A non-suffixed integer literal will be 64 bit if it cannot fit in 32 bits.
62
+
```
63
+
// Same as int64_t a = int(1), the value can fit into a 32 bit integer.
64
+
int64_t a = 1;
65
+
66
+
// Same as int64_t b = int64_t(2147483648), the value cannot fit into a 32 bit integer.
67
+
int64_t b = 2147483648;
68
+
69
+
// Same as int64_t c = uint64_t(18446744073709551615), the value is larger than the maximum value of a signed 64 bit
70
+
// integer, and is interpreted as an unsigned 64 bit integer. Warning is given.
71
+
uint64_t c = 18446744073709551615;
72
+
73
+
// Same as uint64_t = int(0x7FFFFFFF), the value can fit into a 32 bit integer.
74
+
uint64_t d = 0x7FFFFFFF;
75
+
76
+
// Same as uint64_t = int64_t(0x7FFFFFFFFFFFFFFF), the value cannot fit into an unsigned 32 bit integer but
77
+
// can fit into a signed 64 bit integer.
78
+
uint64_t e = 0x7FFFFFFFFFFFFFFF;
79
+
80
+
// Same as uint64_t = uint64_t(0xFFFFFFFFFFFFFFFF), the value cannot fit into a signed 64 bit integer, and
Copy file name to clipboardexpand all lines: docs/user-guide/02-conventional-features.md
+5-2
Original file line number
Diff line number
Diff line change
@@ -39,8 +39,11 @@ The following integer types are provided:
39
39
40
40
All targets support the 32-bit `int` and `uint` types, but support for the other types depends on the capabilities of each target platform.
41
41
42
-
Integer literals can be both decimal and hexadecimal, and default to the `int` type.
43
-
A literal can be explicitly made unsigned with a `u` suffix.
42
+
Integer literals can be both decimal and hexadecimal. An integer literal can be explicitly made unsigned
43
+
with a `u` suffix, and explicitly made 64-bit with the `ll` suffix. The type of a decimal non-suffixed integer literal is the first integer type from
44
+
the list [`int`, `int64_t`] which can represent the specified literal value. If the value cannot fit, the literal is represented as
45
+
an `uint64_t` and a warning is given. The type of hexadecimal non-suffixed integer literal is the first type from the list
46
+
[`int`, `uint`, `int64_t`, `uint64_t`] that can represent the specified literal value. For more information on 64 bit integer literals see the documentation on [64 bit type support](../64bit-type-support.md).
tests/diagnostics/int-literal.slang(6): warning 39999: integer literal '0x800000000' too large for type 'int' truncated to '0'
4
-
int c0 = 0x800000000;
5
-
^~~~~~~~~~~
6
-
tests/diagnostics/int-literal.slang(18): warning 39999: integer literal '0xfffffffff' too large for type 'int' truncated to '-1'
7
-
int c4 = -0xfffffffff;
8
-
^~~~~~~~~~~
3
+
tests/diagnostics/int-literal.slang(29): warning 39999: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
4
+
uint64_t d0 = 18446744073709551615;
5
+
^~~~~~~~~~~~~~~~~~~~
6
+
tests/diagnostics/int-literal.slang(32): warning 39999: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
7
+
uint64_t d1 = -9223372036854775809;
8
+
^~~~~~~~~~~~~~~~~~~
9
+
tests/diagnostics/int-literal.slang(39): warning 39999: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
0 commit comments