1. Lenard Lindstrom
  2. blitter

Commits

Lenard Lindstrom  committed 13843be

Make interpreter changes to allow the JIT to assign more register variables

Within the interpreter loop, assign ``counters`` and ``advances`` values to
scalars, which can be allocated to hardware registers.

  • Participants
  • Parent commits 8c91628
  • Branches default

Comments (0)

Files changed (1)

File blit_interpreter.py

View file
         return "%d:%s %d" % (pc, name, ord(code[pc + 1]))
     return "%d:%s %d %d" %  (pc, name, ord(code[pc + 1]), ord(code[pc + 2]))
 
-ops = Operations(STOP=0,
-                 LOOP= 2,
+ops = Operations(LOOP=1,
                  NEXT=1,
-                 DADD=1,
-                 SADD=1,
-                 DADV=1,
-                 SADV=1,
+                 DADV=0,
+                 SADV=0,
                  MOVE=2,
                  DZERO=1,
-                 CSET=1)
+                 CSET=0)
 
 set_globals(ops)
 
     # Add loop tests
     for i in range(ndim):
         code.append(CSET)
-        code.append(chr(i))
         loop_stack[i] = len(code)
         code.append(LOOP)
-        code.append(chr(i))
         code.append('\x00')
 
     # Add byte copy code
     # Add loop nexts
     for i in range(ndim - 1, -1, -1):
         code.append(DADV)
-        code.append(chr(i))
         code.append(SADV)
-        code.append(chr(i + ndim & 0xFF))
         code.append(NEXT)
         code.append(chr(loop_stack[i]))
-        code[loop_stack[i] + 2] = chr(len(code))
-
-    # And, stop
-    code.append(STOP)
+        code[loop_stack[i] + 1] = chr(len(code))
     
     return ''.join(code)
 
 jitdriver = JitDriver(greens=['pc', 'code'],
-                      reds=['doffset', 'soffset',
+                      reds=['ndim', 'dim', 'counter',
+                            'dadvance', 'sadvance',
+                            'doffset', 'soffset',
                             'dst', 'src', 'shape',
                             'advances', 'counters'],
                       get_printable_location=disassemble_op)
     counters = [0] * ndim
     doffset = 0
     soffset = 0
+    dim = -1
+    counter = 0
+    advance = 0
+    dadvance = 0
+    sadvance = 0
 
     while True:
-        jitdriver.jit_merge_point(pc=pc, code=code,
+        jitdriver.jit_merge_point(pc=pc, code=code, ndim=ndim,
                                   dst=dst, src=src, shape=shape,
                                   doffset=doffset, soffset=soffset,
+                                  dim=dim, counter=counter,
+                                  dadvance=dadvance, sadvance=sadvance,
                                   advances=advances, counters=counters)
         op = code[pc]
         pc += 1
-        if op == LOOP:
-            i = ord(code[pc])
-            pc += 1
-            p = ord(code[pc])
-            pc += 1
-            if counters[i] == 0:
-                pc = p
-            else:
-                counters[i] -= 1
-        elif op == NEXT:
-            p = ord(code[pc])
-            pc += 1
-            pc = p
-            jitdriver.can_enter_jit(pc=pc, code=code,
-                                    dst=dst, src=src, shape=shape,
-                                    doffset=doffset, soffset=soffset,
-                                    advances=advances, counters=counters)
-        elif op == DADD:
-            s = ord(code[pc])
-            pc += 1
-            doffset += s
-        elif op == SADD:
-            s = ord(code[pc])
-            pc += 1
-            soffset += s
-        elif op == DADV:
-            i = ord(code[pc])
-            pc += 1
-            doffset += advances[i]
-        elif op == SADV:
-            i = ord(code[pc])
-            pc += 1
-            soffset += advances[i]
-        elif op == MOVE:
+        if op == MOVE:
             sd = ord(code[pc])
             pc += 1
             ss = ord(code[pc])
             sd = ord(code[pc])
             pc += 1
             dst[doffset + sd] = r_uchar(0)
+        elif op == LOOP:
+            p = ord(code[pc])
+            pc += 1
+            if counter == 0:
+                if dim == 0:
+                    break
+                counter = counters[dim]
+                dim -= 1
+                dadvance = advances[dim]
+                sadvance = advances[ndim + dim]
+                pc = p
+            else:
+                counter -= 1
+        elif op == NEXT:
+            pc = ord(code[pc])
+            jitdriver.can_enter_jit(pc=pc, code=code, ndim=ndim,
+                                    dst=dst, src=src, shape=shape,
+                                    doffset=doffset, soffset=soffset,
+                                    dim=dim, counter=counter,
+                                    dadvance=dadvance, sadvance=sadvance,
+                                    advances=advances, counters=counters)
+        elif op == DADV:
+            doffset += dadvance
+        elif op == SADV:
+            soffset += sadvance
         elif op == CSET:
-            i = ord(code[pc])
-            pc += 1
-            counters[i] = shape[i]
-        elif op == STOP:
-            break
+            dim += 1
+            counters[dim] = counter
+            counter = shape[dim]
+            dadvance = advances[dim]
+            sadvance = advances[ndim + dim]
         else:
             raise RuntimeError("Unknown bytecode %d at %d" % (ord(op), pc - 1))