--- /dev/null
+--- branch.py.orig     2020-05-06 10:27:17.096835546 -0400
++++ branch.py  2020-05-06 10:27:40.353752508 -0400
+@@ -141,7 +141,7 @@
+             M = 32
+         if ~BO[2]:
+             CTR = CTR - 1
+-        ctr_ok = BO[2] | (CTR[M:64] != 0) ^ BO[3]
++        ctr_ok = BO[2] | SelectableInt((CTR[M:64] != 0), bits=1) ^ BO[3]
+         cond_ok = BO[0] | ~(CR[BI + 32] ^ BO[1])
+         if ctr_ok & cond_ok:
+             NIA = concat(LR[0:62], SelectableInt(value=0x0, bits=2))
 
 
 import os
 import sys
+import shutil
+import subprocess
 from soc.decoder.pseudo.pagereader import ISA
 from soc.decoder.power_pseudo import convert_to_python
 from soc.decoder.orderedset import OrderedSet
             f.write("    %s_instrs = {}\n" % pagename)
             f.write(iinf)
 
+    def patch_if_needed(self, source):
+        isadir = get_isasrc_dir()
+        fname = os.path.join(isadir, "%s.py" % source)
+        patchname = os.path.join(isadir, "%s.patch" % source)
+
+        try:
+            with open(patchname, 'r') as patch:
+                newfname = fname + '.orig'
+                shutil.copyfile(fname, newfname)
+                subprocess.check_call(['patch', fname],
+                                      stdin=patch)
+        except:
+            pass
+
+
     def write_isa_class(self):
         isadir = get_isasrc_dir()
         fname = os.path.join(isadir, "all.py")
         sources = sys.argv[1:]
     for source in sources:
         isa.write_pysource(source)
+        isa.patch_if_needed(source)
     isa.write_isa_class()