bug 1034: add crbinlog and crternlogi, rename crbinlog to crfbinlog
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 25 Jan 2024 17:28:05 +0000 (17:28 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 25 Jan 2024 17:28:05 +0000 (17:28 +0000)
12 files changed:
openpower/isa/bitmanip.mdwn
openpower/isatables/RM-1P-2S1D.csv
openpower/isatables/fields.text
openpower/isatables/minor_22.csv
openpower/isatables/minor_5.csv
src/openpower/decoder/isa/caller.py
src/openpower/decoder/power_decoder2.py
src/openpower/decoder/power_enums.py
src/openpower/decoder/power_svp64.py
src/openpower/insndb/asm.py
src/openpower/sv/sv_analysis.py
src/openpower/test/bitmanip/bitmanip_cases.py

index 0c2d735eb58cf7ab664c3f144d90c205058f7a13..ae11d5342dd760e51c002ee3e4c34561d364ac39 100644 (file)
@@ -75,7 +75,7 @@ Special registers altered:
 
 CRB-Form
 
-* crternlogi BF,BFA,BFB,TLI,msk
+* crfternlogi BF,BFA,BFB,TLI,msk
 
 Pseudo-code:
 
@@ -95,11 +95,26 @@ Special Registers Altered:
 
      CR field BF
 
+# Condition Register Field Ternary Bitwise Logic Immediate
+
+CRB-Form
+
+* crternlogi BT,BA,BB,TLI
+
+Pseudo-code:
+
+    idx <- CR[BT+32] || CR[BA+32] || CR[BB+32]
+    CR[4*BF+32] <- TLI[7-idx]
+
+Special Registers Altered:
+
+     CR field BF
+
 # Condition Register Field Dynamic Binary Logic
 
 CRB-Form
 
-* crbinlog BF,BFA,BFB,msk
+* crfbinlog BF,BFA,BFB,msk
 
 Pseudo-code:
 
@@ -134,6 +149,24 @@ Special registers altered:
 
     CR field BF
 
+# Condition Register Dynamic Binary Logic
+
+X-Form
+
+* crbinlog BT,BA,BFB
+
+Pseudo-code:
+
+    a <- CR[BT+32]
+    b <- CR[BA]
+    lut <- CR[4*BFB+32:4*BFB+35]
+    idx <- CR[BT+32] || CR[BA+32]
+    CR[BT+32] <- lut[3-idx]
+
+Special registers altered:
+
+    CR[BT+32]
+
 # Add With Shift By Immediate
 
 Z23-Form
index 79f1952a9d36c356720230ad63b98032f93fa21a..bd27cc2979ee520d3fc1874b6d60f35985252bd6 100644 (file)
@@ -7,8 +7,9 @@ crand,CROP,,1P,EXTRA3,NO,d:BT,s:BA,s:BB,0,0,0,0,0,BA_BB,BT,0
 creqv,CROP,,1P,EXTRA3,NO,d:BT,s:BA,s:BB,0,0,0,0,0,BA_BB,BT,0
 crorc,CROP,,1P,EXTRA3,NO,d:BT,s:BA,s:BB,0,0,0,0,0,BA_BB,BT,0
 cror,CROP,,1P,EXTRA3,NO,d:BT,s:BA,s:BB,0,0,0,0,0,BA_BB,BT,0
-crbinlog,CROP,,1P,EXTRA3,NO,d:BF,s:BFA,s:BFB,0,0,0,0,0,BFA_BFB_BF,BF,0
-crternlogi,CROP,,1P,EXTRA3,NO,d:BF,s:BFA,s:BFB,0,0,0,0,0,BFA_BFB_BF,BF,0
+crfbinlog,CROP,,1P,EXTRA3,NO,d:BF,s:BFA,s:BFB,0,0,0,0,0,BFA_BFB_BF,BF,0
+crbinlog,CROP,,1P,EXTRA3,NO,d:BT,s:BA,s:BFB,0,0,0,0,0,BA_BFB,BT,0
+crfternlogi,CROP,,1P,EXTRA3,NO,d:BF,s:BFA,s:BFB,0,0,0,0,0,BFA_BFB_BF,BF,0
 cmp,CROP,,1P,EXTRA3,NO,d:BF,s:RA,s:RB,0,RA,RB,0,0,0,BF,0
 cmpl,CROP,,1P,EXTRA3,NO,d:BF,s:RA,s:RB,0,RA,RB,0,0,0,BF,0
 cmprb,CROP,,1P,EXTRA3,NO,d:BF,s:RA,s:RB,0,RA,RB,0,0,0,BF,0
index a36e42f42f0cba72dc4c37b78de7caf9cf70451d..b5b263e8c48b1b480fa38e06011f10de0240ac5d 100644 (file)
     | PO   |    FRS        |  RA         |  RB         |   XO |  / |
     | PO   |  FRSp         |  RA         |  RB         |   XO |  / |
     | PO   |     BT        |  ///        |  ///        |   XO |Rc  |
+    | PO   |     BT        |   BA        | BFB //      |   XO | 1  |
     | PO   |     ///       |  RA         |  RB         |   XO |  / |
     | PO   |     ///       |  ///        |  RB         |   XO |  / |
     | PO   |     ///       |  ///        |  ///        |   XO |  / |
     BA (11:15)
         Field used to specify a bit in the CR to be used as
         a source.
-        Formats: XL
+        Formats: XL, X
     BB (16:20)
          Field used to specify a bit in the CR to be used as
          a source.
     BFB (16:18)
          Field used to specify one of the CR fields
          to be used as a source.
-         Formats: CRB
+         Formats: CRB, X
     BH (19:20)
          Field used to specify a hint in the Branch Condi-
          tional to Link Register and Branch Conditional to
     BT (6:10)
          Field used to specify a bit in the CR or in the
          FPSCR to be used as a target.
-         Formats: XL
+         Formats: XL, X
     BX,B (30,16:20)
         Fields that are concatenated to specify a VSR to
         be used as a source.
index 3f0588682f784c97c4eb0e43120d0cd6cb81ca34..b8faabc3766f14035ef22efa5adf05e33dce06f0 100644 (file)
@@ -42,5 +42,6 @@ opcode,unit,internal op,in1,in2,in3,out,CR in,CR out,inv A,inv out,cry in,cry ou
 -----01011-,ALU,OP_FISHMV,FRS,CONST_UI,NONE,FRS,NONE,NONE,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,fishmv,DX,,1,unofficial until submitted and approved/renumbered by the opf isa wg
 0101110110-,ALU,OP_BMAT,RA,NONE,NONE,RT,NONE,NONE,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,gbbd,X,,1,unofficial until submitted and approved/renumbered by the opf isa wg
 ------00001,SHIFT_ROT,OP_BINLOG,RA,RB,RC,RT,NONE,NONE,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,binlog,BM2,,1,unofficial until submitted and approved/renumbered by the opf isa wg
------001001,CR,OP_CRBINLOG,NONE,NONE,NONE,NONE,BFA_BFB_BF,BF,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,crbinlog,CRB,,1,unofficial until submitted and approved/renumbered by the opf isa wg
+-----001001,CR,OP_CRFBINLOG,NONE,NONE,NONE,NONE,BFA_BFB_BF,BF,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,crfbinlog,CRB,,1,unofficial until submitted and approved/renumbered by the opf isa wg
+00001011101,CR,OP_CRBINLOG,NONE,NONE,NONE,NONE,BA_BFB,BT,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,crbinlog,X,,1,unofficial until submitted and approved/renumbered by the opf isa wg
 
index 80f575ed9584f84c810bf681b7398631ffe36370..bb110567773289bca18cfd7eca14416bb74ea97d 100644 (file)
@@ -1,6 +1,6 @@
 opcode,unit,internal op,in1,in2,in3,out,CR in,CR out,inv A,inv out,cry in,cry out,ldst len,BR,sgn ext,upd,rsrv,32b,sgn,rc,lk,sgl pipe,comment,form,CONDITIONS,unofficial,comment2
 --------00-,SHIFT_ROT,OP_TERNLOG,RA,RB,RT,RT,NONE,CR0,0,0,ZERO,0,NONE,0,0,0,0,0,0,RC_ONLY,0,0,ternlogi,TLI,,1,unofficial until submitted and approved/renumbered by the opf isa wg
---------01-,CR,OP_CRTERNLOG,NONE,NONE,NONE,NONE,BFA_BFB_BF,BF,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,crternlogi,CRB,,1,unofficial until submitted and approved/renumbered by the opf isa wg
+--------010,CR,OP_CRFTERNLOG,NONE,NONE,NONE,NONE,BFA_BFB_BF,BF,0,0,ZERO,0,NONE,0,0,0,0,0,0,NONE,0,0,crfternlogi,CRB,,1,unofficial until submitted and approved/renumbered by the opf isa wg
 ------00100,ALU,OP_MADDSUBRS,RA,CONST_SH,RB,RT,NONE,NONE,0,0,ZERO,0,NONE,0,0,0,0,1,0,NONE,0,0,maddsubrs,A,,1,unofficial until submitted and approved/renumbered by the opf isa wg
 ------01100,ALU,OP_MADDRS,RA,CONST_SH,RB,RT,NONE,NONE,0,0,ZERO,0,NONE,0,0,0,0,1,0,NONE,0,0,maddrs,A,,1,unofficial until submitted and approved/renumbered by the opf isa wg
 ------10100,ALU,OP_MSUBRS,RA,CONST_SH,RB,RT,NONE,NONE,0,0,ZERO,0,NONE,0,0,0,0,1,0,NONE,0,0,msubrs,A,,1,unofficial until submitted and approved/renumbered by the opf isa wg
index b72a9eff9378132e02b8c16b5368ef0654d0e088..2544c61a0333d8f5c192fbe9c603fcc127a257aa 100644 (file)
@@ -2275,7 +2275,8 @@ class ISACaller(ISACallerHelper, ISAFPHelpers, StepLoop):
                        "brh", "brw", "brd",
                        'setvl', 'svindex', 'svremap', 'svstep',
                        'svshape', 'svshape2',
-                       'binlog', 'crbinlog', 'crternlogi', 'ternlogi',
+                       'binlog', 'crbinlog', 'crfbinlog',
+                       'crternlogi', 'crfternlogi', 'ternlogi',
                        'bmask', 'cprop', 'gbbd',
                        'absdu', 'absds', 'absdacs', 'absdacu', 'avgadd',
                        'fmvis', 'fishmv', 'pcdec', "maddedu", "divmod2du",
index 9e3bca4aa345b1ed676f15e6d9d67da6af44fddb..51a2e3343d66ede4614bc11e5a00cd16836a56fa 100644 (file)
@@ -661,6 +661,13 @@ class DecodeCRIn(Elaboratable):
                 comb += self.cr_bitfield_b.ok.eq(1)
                 comb += self.cr_bitfield_o.data.eq(self.dec.FormCRB.BF)
                 comb += self.cr_bitfield_o.ok.eq(1)
+            with m.Case(CRInSel.BA_BFB):
+                comb += self.cr_bitfield.data.eq(self.dec.BA[2:5])
+                comb += self.cr_bitfield.ok.eq(1)
+                comb += self.cr_bitfield_b.data.eq(self.dec.FormCRB.BFB)
+                comb += self.cr_bitfield_b.ok.eq(1)
+                comb += self.cr_bitfield_o.data.eq(self.dec.FormCRB.BF)
+                comb += self.cr_bitfield_o.ok.eq(1)
             with m.Case(CRInSel.BC):
                 comb += self.cr_bitfield.data.eq(self.dec.BC[2:5])
                 comb += self.cr_bitfield.ok.eq(1)
index 7d5ce4af07e8b629b1a20cc50fa1dbd63fd0dc58..28c2018913fc3e7561004ddf7be617568cabb74e 100644 (file)
@@ -749,8 +749,8 @@ _insns = [
     "cprop", # AV bitmanip
     "crand", "crandc", "creqv",
     "crnand", "crnor", "cror", "crorc", "crxor",
-    "crbinlog", # binary bitmanip
-    "crternlogi", # ternary bitmanip
+    "crbinlog", "crfbinlog", # binary bitmanip (field and CR bit)
+    "crternlogi", "crfternlogi", # ternary bitmanip (field and CR bit)
     "darn",
     "dcbf", "dcbst", "dcbt", "dcbtst", "dcbz",
     "divd", "divde", "divdeo", "divdeu",
@@ -972,6 +972,8 @@ class MicrOp(Enum):
     OP_CRTERNLOG = 113
     OP_BINLOG = 114
     OP_CRBINLOG = 115
+    OP_CRFBINLOG = 116
+    OP_CRFTERNLOG = 117
 
 
 class SelType(Enum):
@@ -1146,6 +1148,7 @@ class CRInSel(Enum):
     CR1 = 7
     BA = 8
     BFA_BFB_BF = 9
+    BA_BFB = 10 # maaamma miiia... definitely time for CRin1/2 in CSV...
 
     def __str__(self):
         return self.name
index cfa338055c3adde07c22c7f4713dd79b7c50cad2..9a635f8ac85399184ba27b7e947729ea935aee30 100644 (file)
@@ -160,8 +160,15 @@ class SVP64RM:
                 # BF is marked as a dest but is actually also src
                 index1 = svp64_src.get('BFA', None)
                 index2 = svp64_src.get('BFB', None)
-                index3 = svp64_dest.get('BF', None) # read-modify-write
-                entry['sv_cr_in'] = "Idx_%d_%d_%d" % (index1, index2, index3)
+                # long story, a kludge should allow the 3rd source to be id'd
+                #index3 = svp64_dest.get('BF', None) # read-modify-write
+                entry['sv_cr_in'] = "Idx_%d_%d" % (index1, index2)
+            elif cr_in == 'BA_BFB':
+                # three indices, BT and BA are 5-bit source, BFB is 3-bit
+                # BF is marked as a dest but is actually also src
+                index1 = svp64_src.get('BA', None)
+                index2 = svp64_src.get('BFB', None)
+                entry['sv_cr_in'] = "Idx_%d_%d" % (index1, index2)
 
             # CRout a lot easier.  ignore WHOLE_REG for now
             cr_out = entry['CR out']
index 0d7f8c06d0b4cd0ee539b05a91c18ce8025c7910..8f6ad336d8c6c8e09bb6d21faa47dbd5775c4db1 100644 (file)
@@ -85,6 +85,7 @@ class SVP64Asm:
 
         # identify if it is a word instruction
         record = DB[opcode]
+        #log("record", record)
         if record is not None:
             insn = WordInstruction.assemble(record=record, arguments=fields)
             yield from insn.disassemble(record=record, style=Style.LEGACY)
@@ -101,6 +102,7 @@ class SVP64Asm:
         v30b_op = opmodes.pop(0)    # first is the v3.0B
 
         record = DB[v30b_op]
+        #log("record v30b", record)
         if record is not None:
             insn = SVP64Instruction.assemble(record=record,
                 arguments=fields, specifiers=opmodes)
@@ -309,8 +311,9 @@ if __name__ == '__main__':
     ]
     lst = [
         #"sv.cmp/ff=gt *0,*1,*2,0",
-        "dsld 5,4,5,3",
-
+        #"dsld 5,4,5,3",
+        "crfbinlog 3,4,5,15",
+        #"crbinlog 3,4,5",
     ]
     isa = SVP64Asm(lst, macros=macros)
     log("list:\n", "\n\t".join(list(isa)))
index b0e2ae4aae3aebc0906798a8a380aa34102dc24a..cc011e0a2d13ec302a28771d2167ee34f0585126 100644 (file)
@@ -546,10 +546,14 @@ def extra_classifier(insn_name, value, name, res, regs):
 
     elif value == 'RM-1P-2S1D':
         res['Etype'] = 'EXTRA3'  # RM EXTRA3 type
-        if insn_name in ['crbinlog', 'crternlogi']:
+        if insn_name in ['crfbinlog', 'crfternlogi']:
             res['0'] = 'd:BF'  # BF: Rdest1_EXTRA3
             res['1'] = 's:BFA'  # BFA: Rsrc1_EXTRA3
             res['2'] = 's:BFB'  # BFB: Rsrc2_EXTRA3
+        elif insn_name == 'crbinlog':
+            res['0'] = 'd:BT'  # BT: Rdest1_EXTRA3
+            res['1'] = 's:BA'  # BA: Rsrc1_EXTRA3
+            res['2'] = 's:BFB'  # BFB: Rsrc2_EXTRA3
         elif insn_name.startswith('cr'):
             res['0'] = 'd:BT'  # BT: Rdest1_EXTRA3
             res['1'] = 's:BA'  # BA: Rsrc1_EXTRA3
index a84bd2fb04065fdac59bd0a58891c19968ca02b3..eacdfeb88b8ca647fad93b70fa52eb8f9e86c7c6 100644 (file)
@@ -18,6 +18,36 @@ def bmatflip(ra):
     return result
 
 
+def crfbinlog(bf, bfa, bfb, mask):
+    lut = bfb
+    expected = bf&~mask # start at BF, mask overwrites masked bits only
+    checks = (bfa, bf) # LUT positions 1<<0=bfa 1<<1=bf
+    for i in range(4):
+        lut_index = 0
+        for j, check in enumerate(checks):
+            if check & (1<<i):
+                lut_index |= 1<<j
+        maskbit = (mask >> i) & 0b1
+        if (lut & (1<<lut_index)) and maskbit:
+            expected |= 1<<i
+    return expected
+
+
+def ternlogi(rc, rt, ra, rb, imm):
+    expected = 0
+    for i in range(64):
+        lut_index = 0
+        if rb & 2 ** i:
+            lut_index |= 2 ** 0
+        if ra & 2 ** i:
+            lut_index |= 2 ** 1
+        if rt & 2 ** i:
+            lut_index |= 2 ** 2
+        if imm & 2 ** lut_index:
+            expected |= 2 ** i
+    return expected
+
+
 class BitManipTestCase(TestAccumulatorBase):
     def case_gbbd(self):
         lst = ["gbbd 0, 1"]
@@ -32,8 +62,8 @@ class BitManipTestCase(TestAccumulatorBase):
 
         self.add_case(Program(lst, bigendian), initial_regs, expected=e)
 
-    def do_case_crternlogi(self, bf, bfa, bfb, imm, mask):
-        lst = [f"crternlogi 3,4,5,%d,%d" % (imm, mask)]
+    def do_case_crfternlogi(self, bf, bfa, bfb, imm, mask):
+        lst = [f"crfternlogi 3,4,5,%d,%d" % (imm, mask)]
         # set up CR
         bf %= 2 ** 4
         bfa %= 2 ** 4
@@ -64,24 +94,24 @@ class BitManipTestCase(TestAccumulatorBase):
         self.add_case(Program(lst, bigendian), initial_regs=None, expected=e,
                                        initial_cr=initial_cr)
 
-    def case_crternlogi_0(self):
-        self.do_case_crternlogi(0b1111,
+    def case_crfternlogi_0(self):
+        self.do_case_crfternlogi(0b1111,
                                 0b1100,
                                 0b1010,
                                 0x80, 0b1111)
 
-    def case_crternlogi_random(self):
+    def case_crfternlogi_random(self):
         for i in range(100):
-            rc = bool(hash_256(f"crternlogi rc {i}") & 1)
-            imm = hash_256(f"crternlogi imm {i}") & 0xFF
-            bf = hash_256(f"crternlogi bf {i}") % 2 ** 4
-            bfa = hash_256(f"crternlogi bfa {i}") % 2 ** 4
-            bfb = hash_256(f"crternlogi bfb {i}") % 2 ** 4
-            msk = hash_256(f"crternlogi msk {i}") % 2 ** 4
-            self.do_case_crternlogi(bf, bfa, bfb, imm, msk)
+            rc = bool(hash_256(f"crfternlogi rc {i}") & 1)
+            imm = hash_256(f"crfternlogi imm {i}") & 0xFF
+            bf = hash_256(f"crfternlogi bf {i}") % 2 ** 4
+            bfa = hash_256(f"crfternlogi bfa {i}") % 2 ** 4
+            bfb = hash_256(f"crfternlogi bfb {i}") % 2 ** 4
+            msk = hash_256(f"crfternlogi msk {i}") % 2 ** 4
+            self.do_case_crfternlogi(bf, bfa, bfb, imm, msk)
 
-    def do_case_crbinlog(self, bf, bfa, bfb, mask):
-        lst = ["crbinlog 3,4,5,%d" % mask]
+    def do_case_crfbinlog(self, bf, bfa, bfb, mask):
+        lst = ["crfbinlog 3,4,5,%d" % mask]
         # set up CR
         bf %= 2 ** 4
         bfa %= 2 ** 4
@@ -97,34 +127,24 @@ class BitManipTestCase(TestAccumulatorBase):
 
         lst = list(SVP64Asm(lst, bigendian))
         e = ExpectedState(pc=4)
-        expected = bf&~mask # start at BF, mask overwrites masked bits only
-        checks = (bfa, bf) # LUT positions 1<<0=bfa 1<<1=bf
-        for i in range(4):
-            lut_index = 0
-            for j, check in enumerate(checks):
-                if check & (1<<i):
-                    lut_index |= 1<<j
-            maskbit = (mask >> i) & 0b1
-            if (lut & (1<<lut_index)) and maskbit:
-                expected |= 1<<i
-        e.crregs[3] = expected
+        e.crregs[3] = crfbinlog(bf, bfa, bfb, mask)
         e.crregs[4] = bfa
         e.crregs[5] = bfb
         self.add_case(Program(lst, bigendian), initial_regs=None, expected=e,
                                        initial_cr=initial_cr)
 
-    def case_crbinlog_0(self):
-        self.do_case_crbinlog(0b1111,
-                              0b1100,
-                              0x8, 0b1111)
+    def case_crfbinlog_0(self):
+        self.do_case_crfbinlog(0b1111,
+                               0b1100,
+                               0x8, 0b1111)
 
-    def case_crbinlog_random(self):
+    def case_crfbinlog_random(self):
         for i in range(100):
-            bf = hash_256(f"crbinlog bf {i}") % 2 ** 4
-            bfa = hash_256(f"crbinlog bfa {i}") % 2 ** 4
-            bfb = hash_256(f"crbinlog bfb {i}") % 2 ** 4
-            msk = hash_256(f"crbinlog msk {i}") % 2 ** 4
-            self.do_case_crbinlog(bf, bfa, bfb, msk)
+            bf = hash_256(f"crfbinlog bf {i}") % 2 ** 4
+            bfa = hash_256(f"crfbinlog bfa {i}") % 2 ** 4
+            bfb = hash_256(f"crfbinlog bfb {i}") % 2 ** 4
+            msk = hash_256(f"crfbinlog msk {i}") % 2 ** 4
+            self.do_case_crfbinlog(bf, bfa, bfb, msk)
 
     def do_case_ternlogi(self, rc, rt, ra, rb, imm):
         rc_dot = "." if rc else ""