Skip to content

Commit 3867623

Browse files
committed
docs/reference: describe out-of-bounds behavior of bit_select/word_select.
1 parent 2dea83c commit 3867623

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

amaranth/hdl/_ast.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,12 @@ def bit_select(self, offset, width):
10561056
"""Part-select with bit granularity.
10571057
10581058
Selects a constant width, variable offset part of :pc:`self`, where parts with successive
1059-
offsets overlap by :pc:`width - 1` bits. When :pc:`offset` is a constant integer, this
1060-
operation is equivalent to :pc:`self[offset:offset + width]`.
1059+
offsets overlap by :pc:`width - 1` bits. Bits above the most significant bit of :pc:`self`
1060+
may be selected; they are equal to zero if :pc:`self` is unsigned, to :pc:`self[-1]` if
1061+
:pc:`self` is signed, and assigning to them does nothing.
1062+
1063+
When :pc:`offset` is a constant integer and :pc:`offset + width <= len(self)`,
1064+
this operation is equivalent to :pc:`self[offset:offset + width]`.
10611065
10621066
Parameters
10631067
----------
@@ -1086,8 +1090,12 @@ def word_select(self, offset, width):
10861090
"""Part-select with word granularity.
10871091
10881092
Selects a constant width, variable offset part of :pc:`self`, where parts with successive
1089-
offsets are adjacent but do not overlap. When :pc:`offset` is a constant integer, this
1090-
operation is equivalent to :pc:`self[offset * width:(offset + 1) * width]`.
1093+
offsets are adjacent but do not overlap. Bits above the most significant bit of :pc:`self`
1094+
may be selected; they are equal to zero if :pc:`self` is unsigned, to :pc:`self[-1]` if
1095+
:pc:`self` is signed, and assigning to them does nothing.
1096+
1097+
When :pc:`offset` is a constant integer and :pc:`width:(offset + 1) * width <= len(self)`,
1098+
this operation is equivalent to :pc:`self[offset * width:(offset + 1) * width]`.
10911099
10921100
Parameters
10931101
----------

0 commit comments

Comments
 (0)