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
Adds four widening `Bits<N>` operators in IDL:
* `` `<< `` : widening shift left. If the shift amount is a constant,
the result is `Bits<N + shamt>`. Otherwise, the result type is
`Bits<Infinite>`.
* `` `* ``: widening multiply. The result type when multiplying
`Bits<N>` * `Bits<M>` is `Bits<N + M>`
* `` `+ ``: widening add. The result type when adding `Bits<N>` +
`Bits<M>` is `Bits<max(M, N) + 1>`
* `` `- ``: widening sub. The result type when subtracting `Bits<N> +
Bits<M>` is `Bits<max(M, N) + 1>`.
Copy file name to clipboardExpand all lines: doc/idl.adoc
+40-14Lines changed: 40 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -414,6 +414,7 @@ Binary operators between operands of different bit widths will extend the smalle
414
414
415
415
The result of a binary operation is signed if both operands are signed; otherwise, the result is unsigned.
416
416
417
+
[#operators]
417
418
.IDL operators in precedence order, with 0 being highest. For an operand `i` (which may be an expression), `L(i)` is the number of bits in `i` and `typeof(i)` is the exact type of `i`
418
419
[cols="1,2,3,4"]
419
420
|===
@@ -445,9 +446,11 @@ The result of a binary operation is signed if both operands are signed; otherwis
The '$bits' cast can convert Enumeration references, Bitfields, and CSRs into a Bits<N> type.
624
626
When the casted value is an enumeration reference, the resulting type will be large enough to hold the largest value in the enumeration type, regardless of the specific reference value.
625
-
When the casted value is a CSR, the resulting type will the width of the CSR, or the maximum width when a CSR width is dynamic.
627
+
When the casted value is a CSR, the resulting type will the width of the CSR, or the maximum width when a CSR width is dynamic (changable at runtime).
626
628
When the casted value is a bitfield, the resulting type will be the width of the bitfield.
627
629
628
630
[source,idl]
@@ -659,6 +661,30 @@ The `$enum_to_a` cast will convert an enumeration type into an array of the enum
659
661
$enum_to_a(RoundingMode) # => [0, 1, 2, 3, 4]
660
662
----
661
663
664
+
=== Implicit casting
665
+
666
+
Operations involving Bits<N> type with different N involve an implicit cast to the larger bitwidth according to xref:operators[xrefstyle=short].
667
+
668
+
When the Bits<N> type is unsigned, it zero-extends to the larger width.
669
+
670
+
When the Bits<N> type is signed, it sign-extends to the larger width.
671
+
672
+
[source,idl]
673
+
----
674
+
675
+
Bits<4> a = 1;
676
+
Bits<2> b = 3;
677
+
678
+
Bits<4> c = a | b; # c = 3
679
+
Bits<4> d = a | $signed(b); # d = 0xf
680
+
681
+
Bits<4> e = a + b; # e = 4
682
+
Bits<4> f = a + $signed(b); # f = 0
683
+
684
+
Bits<4> g = $signed(a) | b; # g = 3
685
+
686
+
----
687
+
662
688
== Builtins
663
689
664
690
IDL provides a several builtins to access implicit machine state or query data structure properties.
0 commit comments