cornell-brg / pymtl

Python-based hardware modeling framework
BSD 3-Clause "New" or "Revised" License
234 stars 83 forks source link

A minor bug (or functional extensions) of range select #143

Open jsn1993 opened 8 years ago

jsn1993 commented 8 years ago

See this code fragment:

bit = Bits(8, 12)
left = Bits(16, 0)
right = Bits(16, 8)
bit [ left : right ]

Then in Bits.py line 296, "ones = (1 << nbits) - 1" will raise an error because nbits should be an integer.

The semantics are to capture bit [ 0 : 8 ], but the type of nbits ("nbits = stop - start" in line 284) after this subtraction is still Bits.

I think it is useful to cast nbits to integer here because in some circumstances programmers may get the left and right range from an input port and may forget to cast Bits to integer.

Suggestion: nbits = stop - start --> nbits= (int)(stop-start)