From 02d18dca18c0736de135158436eed3b7d64bbed7 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 24 Jul 2020 16:03:31 +0100 Subject: [PATCH] returned field_slice to original, and added comments see https://bugs.libre-soc.org/show_bug.cgi?id=325#c134 --- src/soc/consts.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/soc/consts.py b/src/soc/consts.py index 8ed63eab..40512121 100644 --- a/src/soc/consts.py +++ b/src/soc/consts.py @@ -8,21 +8,22 @@ def botchify(bekls, lekls): # Can't think of a better place to put these functions. # Return an arbitrary subfield of a larger field. -def field_slice(start, end): +def field_slice(msb0_start, msb0_end, field_width=64): """Answers with a subfield slice of the signal r ("register"), - where the start and end bits use IBM conventions. start < end. + where the start and end bits use IBM conventions. msb0_start < msb0_end. The range specified is inclusive on both ends. + field_width specifies the total number of bits (not bits-1) """ - start = 63 - start - end = 63 - end - # XXX must do the endian-reversing BEFORE doing the comparison - # if done after, that instead asserts that (after modification) - # start *MUST* be greater than end! - if start >= end: + if msb0_start >= msb0_end: raise ValueError( "start ({}) must be less than end ({})".format(start, end) ) - return slice(end, start + 1) + # sigh. MSB0 (IBM numbering) is inverted. converting to python + # we *swap names* so as not to get confused by having "end, start" + end = (field_width-1) - msb0_start + start = (field_width-1) - msb0_end + + return slice(start, end + 1) def field(r, start, end=None): -- 2.30.2