made it clear what is meant by the slice numbering being inverted
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Jul 2020 09:25:59 +0000 (10:25 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Jul 2020 09:25:59 +0000 (10:25 +0100)
see https://bugs.libre-soc.org/show_bug.cgi?id=325#c126

src/soc/consts.py

index fe29743e6858eca62c8651c180abd553ef7539b8..8ed63eabcbd5f20c499e2916b37781ff57613cee 100644 (file)
@@ -13,12 +13,15 @@ def field_slice(start, end):
     where the start and end bits use IBM conventions.  start < end.
     The range specified is inclusive on both ends.
     """
+    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:
         raise ValueError(
             "start ({}) must be less than end ({})".format(start, end)
         )
-    start = 63 - start
-    end = 63 - end
     return slice(end, start + 1)