add bit-wise OR and AND
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 15:12:56 +0000 (16:12 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 15:12:56 +0000 (16:12 +0100)
libreriscv
src/soc/decoder/power_pseudo.py
src/soc/decoder/pseudo/lexer.py
src/soc/decoder/pseudo/parser.py
src/soc/decoder/selectable_int.py

index 620efa218f922eba23b19189109bec785a624a82..df8dbe52a4a201d4e23e50de5ffd84c01b54cb57 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 620efa218f922eba23b19189109bec785a624a82
+Subproject commit df8dbe52a4a201d4e23e50de5ffd84c01b54cb57
index 78add9ef67ec672b91bb97138267122739209356..07715f6eba64d39a67f7349cd0d4569833443fd2 100644 (file)
@@ -73,6 +73,10 @@ cmpi = """
 RA[0:1] <- 0b11
 """
 
+cmpi = """
+in_range <-  (x | y) & (a | b)
+in_range <-  (x + y) - (a + b)
+"""
 
 #code = testreg
 #code = cnttzd
index 992ab7b638a95c46704de2c860381c9b42e8c404..86b04efd77868bddc8a0989393a25eefd99dbfc3 100644 (file)
@@ -252,6 +252,8 @@ class PowerLexer:
         'MULT',
         'DIV',
         'APPEND',
+        'BITOR',
+        'BITAND',
         'RETURN',
         'WS',
         'NEWLINE',
@@ -300,6 +302,8 @@ class PowerLexer:
     t_COMMA = r','
     t_SEMICOLON = r';'
     t_APPEND = r'\|\|'
+    t_BITOR = r'\|'
+    t_BITAND = r'\&'
 
     # Ply nicely documented how to do this.
 
index 8ce1b8c2e3322d2b9ba42a51e139f00822c7afbd..e752aff8207666735ba223ab98d0b5a342c74945 100644 (file)
@@ -95,6 +95,8 @@ def make_eq_compare(arg):
     return ast.Compare(left, [ast.Eq()], [right])
 
 binary_ops = {
+    "&": ast.BitAnd(),
+    "|": ast.BitOr(),
     "+": ast.Add(),
     "-": ast.Sub(),
     "*": ast.Mult(),
@@ -128,6 +130,7 @@ def check_concat(node): # checks if the comparison is already a concat
 class PowerParser:
 
     precedence = (
+        ("left", "BITOR", "BITAND"),
         ("left", "EQ", "GT", "LT", "LE", "GE", "LTU", "GTU"),
         ("left", "PLUS", "MINUS"),
         ("left", "MULT", "DIV"),
@@ -338,6 +341,8 @@ class PowerParser:
                       | comparison GTU comparison
                       | comparison LT comparison
                       | comparison GT comparison
+                      | comparison BITOR comparison
+                      | comparison BITAND comparison
                       | PLUS comparison
                       | MINUS comparison
                       | comparison APPEND comparison
index 5a18833017de2956eb54b786758b0b0bc579700d..05cf2b21604ce75f461412c0393ba16e141d8226 100644 (file)
@@ -102,7 +102,7 @@ class SelectableInt:
             assert other.bits == self.bits
             other = other.value
         if isinstance(other, int):
-            return other <= self.value
+            return onebit(other <= self.value)
         assert False
 
     def __gt__(self, other):
@@ -110,7 +110,7 @@ class SelectableInt:
             assert other.bits == self.bits
             other = other.value
         if isinstance(other, int):
-            return other > self.value
+            return onebit(other > self.value)
         assert False
 
     def __lt__(self, other):
@@ -118,7 +118,7 @@ class SelectableInt:
             assert other.bits == self.bits
             other = other.value
         if isinstance(other, int):
-            return other < self.value
+            return onebit(other < self.value)
         assert False
 
     def __eq__(self, other):
@@ -126,26 +126,29 @@ class SelectableInt:
             assert other.bits == self.bits
             other = other.value
         if isinstance(other, int):
-            return other == self.value
+            return onebit(other == self.value)
         assert False
 
     def __repr__(self):
         return "SelectableInt(value={:x}, bits={})".format(self.value,
                                                            self.bits)
 
+def onebit(bit):
+    return SelectableInt(1 if bit else 0, 1)
+
 def selectltu(lhs, rhs):
     """ less-than (unsigned)
     """
     if isinstance(rhs, SelectableInt):
         rhs = rhs.value
-    return lhs.value < rhs
+    return onebit(lhs.value < rhs)
 
 def selectgtu(lhs, rhs):
     """ greater-than (unsigned)
     """
     if isinstance(rhs, SelectableInt):
         rhs = rhs.value
-    return lhs.value > rhs
+    return onebit(lhs.value > rhs)
 
 
 # XXX this probably isn't needed...