[pypy-svn] r63282 - in pypy/branch/pyjitpl5-PyGirl/pypy: jit/tl lang/gameboy lang/gameboy/profiling
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Mar 24 17:34:01 CET 2009
Author: cfbolz
Date: Tue Mar 24 17:33:59 2009
New Revision: 63282
Added:
pypy/branch/pyjitpl5-PyGirl/pypy/jit/tl/gbjit.py (contents, props changed)
pypy/branch/pyjitpl5-PyGirl/pypy/jit/tl/gbjit_child.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cartridge.py
pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cpu.py
pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py
Log:
try to rewrite gameboy implementation to be more jit-friendly. also write a file
that lets one see better what is going on with the jit.
Added: pypy/branch/pyjitpl5-PyGirl/pypy/jit/tl/gbjit.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5-PyGirl/pypy/jit/tl/gbjit.py Tue Mar 24 17:33:59 2009
@@ -0,0 +1,64 @@
+"""
+A file that invokes translation of PyGirl with the JIT enabled.
+"""
+
+import py, os
+
+from pypy.config.translationoption import set_opt_level, get_combined_translation_config
+from pypy.lang.gameboy.profiling.gameboy_profiling_implementation import GameBoyProfiler
+from pypy.rpython.annlowlevel import llhelper, llstr, hlstr
+from pypy.rpython.lltypesystem.rstr import STR
+from pypy.rpython.lltypesystem import lltype
+from pypy.translator.goal import unixcheckpoint
+
+config = get_combined_translation_config(translating=True)
+config.translation.backendopt.inline_threshold = 0
+set_opt_level(config, level='1')
+print config
+
+import sys, pdb, time
+
+ROM_PATH = str(py.magic.autopath().dirpath().dirpath().dirpath())+"/lang/gameboy/rom"
+
+gameBoy = GameBoyProfiler()
+# an infinite loop
+filename = ROM_PATH+"/rom3/rom3.gb"
+gameBoy.load_cartridge_file(str(filename), verify=False)
+gameBoy.reset()
+
+def entry_point():
+ execution_seconds = 600
+
+ start = time.time()
+ gameBoy.mainLoop(execution_seconds)
+ print time.time() - start
+ return 0
+
+def test_run_translation():
+ from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
+ from pypy.rpython.test.test_llinterp import get_interpreter
+
+ # first annotate, rtype, and backendoptimize PyPy
+ try:
+ interp, graph = get_interpreter(entry_point, [], backendopt=True,
+ config=config)
+ except Exception, e:
+ print '%s: %s' % (e.__class__, e)
+ pdb.post_mortem(sys.exc_info()[2])
+ raise
+
+ # parent process loop: spawn a child, wait for the child to finish,
+ # print a message, and restart
+ unixcheckpoint.restartable_point(auto='run')
+
+ from pypy.jit.tl.gbjit_child import run_child
+ run_child(globals(), locals())
+
+
+if __name__ == '__main__':
+ import sys
+ if len(sys.argv) > 1:
+ # debugging: run the code directly
+ entry_point()
+ else:
+ test_run_translation()
Added: pypy/branch/pyjitpl5-PyGirl/pypy/jit/tl/gbjit_child.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5-PyGirl/pypy/jit/tl/gbjit_child.py Tue Mar 24 17:33:59 2009
@@ -0,0 +1,30 @@
+from pypy.conftest import option
+from pypy.rpython.lltypesystem import lltype
+from pypy.jit.metainterp import warmspot
+from pypy.jit.metainterp.policy import ManualJitPolicy
+
+from pypy.translator.backendopt.support import find_calls_from
+
+class GbJitPolicy(ManualJitPolicy):
+ def look_inside_function(self, func):
+ if "update_clock" in func.func_name:
+ return False
+ if "ll_int2hex" in func.func_name:
+ return False
+ return True # XXX for now
+
+def run_child(glob, loc):
+ import sys, pdb
+ interp = loc['interp']
+ graph = loc['graph']
+ interp.malloc_check = False
+
+ #def returns_null(T, *args, **kwds):
+ # return lltype.nullptr(T)
+ #interp.heap.malloc_nonmovable = returns_null # XXX
+
+ print 'warmspot.jittify_and_run() started...'
+ policy = GbJitPolicy(interp.typer.annotator.translator)
+ option.view = True
+ warmspot.jittify_and_run(interp, graph, [], policy=policy,
+ listops=True)
Modified: pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cartridge.py
==============================================================================
--- pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cartridge.py (original)
+++ pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cartridge.py Tue Mar 24 17:33:59 2009
@@ -31,6 +31,7 @@
return constants.CATRIDGE_TYPE_MAPPING[cartridge_type](rom, ram, clock)
else:
raise InvalidMemoryBankTypeError("Unsupported memory bank controller (0x"+hex(cartridge_type)+")")
+create_bank_controller._look_inside_me_ = False
def map_to_byte( string):
mapped = [0]*len(string)
@@ -307,6 +308,7 @@
hex(self.max_rom_bank_size)))
self.rom = buffer
self.rom_size = self.rom_bank_size * banks - 1
+ set_rom._look_inside_me_ = False
def set_ram(self, buffer):
@@ -317,6 +319,7 @@
hex(self.max_ram_bank_size)))
self.ram = buffer
self.ram_size = constants.RAM_BANK_SIZE * banks - 1
+ set_rom._look_inside_me_ = False
def read(self, address):
@@ -334,8 +337,8 @@
#return 0xFF
raise Exception("RAM is not Enabled")
#return 0xFF
- raise InvalidMemoryAccessException("MBC: Invalid address, out of range: %s"
- % hex(address))
+ raise InvalidMemoryAccessException#("MBC: Invalid address, out of range: %s"
+ # % hex(address))
def write(self, address, data):
raise InvalidMemoryAccessException("MBC: Invalid write access")
Modified: pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cpu.py (original)
+++ pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/cpu.py Tue Mar 24 17:33:59 2009
@@ -20,7 +20,7 @@
DEBUG_INSTRUCTION_COUNTER = 1
-jitdriver = JitDriver(greens = ['pc'], reds=['af', 'bc', 'de', 'hl', 'sp'])
+jitdriver = JitDriver(greens = ['pc'], reds=['self'], virtualizables=['self'])
class CPU(object):
"""
@@ -28,6 +28,9 @@
Central Unit Processor_a (Sharp LR35902 CPU)
"""
+ _virtualizable2_ = True
+ _always_virtual_ = 'b c bc d e de h l hl hli pc sp a flag af interrupt rom'.split()
+
def __init__(self, interrupt, memory):
assert isinstance(interrupt, Interrupt)
self.interrupt = interrupt
@@ -176,8 +179,8 @@
self.cycles += ticks
self.handle_pending_interrupts()
while self.cycles > 0:
+ jitdriver.jit_merge_point(pc=self.pc.value, self=self)
opcode = self.fetch(use_cycles=False)
- jitdriver.jit_merge_point(pc=self.pc.value)
self.execute(opcode)
def emulate_step(self):
@@ -290,7 +293,6 @@
self.pc.set(address, use_cycles=use_cycles) # 1 cycle
if use_cycles:
self.cycles += 1
- jitdriver.can_enter_jit(pc=self.pc.value)
def load(self, getCaller, setCaller):
# 1 cycle
@@ -659,9 +661,12 @@
def jump(self):
# JP nnnn, 4 cycles
- self.pc.set(self.fetch_double_address()) # 1+2 cycles
+ oldpc = self.pc.value
+ newpc = self.fetch_double_address()
+ self.pc.set(newpc) # 1+2 cycles
self.cycles -= 1
- jitdriver.can_enter_jit(pc=self.pc.value)
+ if oldpc >= newpc:
+ jitdriver.can_enter_jit(pc=self.pc.value, self=self)
def conditional_jump(self, cc):
# JP cc,nnnn 3,4 cycles
@@ -672,9 +677,11 @@
def relative_jump(self):
# JR +nn, 3 cycles
- self.pc.add(process_2s_complement(self.fetch())) # 3 + 1 cycles
+ increment = process_2s_complement(self.fetch())
+ self.pc.add(increment) # 3 + 1 cycles
self.cycles += 1
- jitdriver.can_enter_jit(pc=self.pc.value)
+ if increment <= 0:
+ jitdriver.can_enter_jit(pc=self.pc.value, self=self)
def relative_conditional_jump(self, cc):
# JR cc,+nn, 2,3 cycles
@@ -697,7 +704,6 @@
def ret(self):
# RET 4 cycles
self.double_register_inverse_call(CPUPopCaller(self), self.pc)
- jitdriver.can_enter_jit(pc=self.pc.value)
def conditional_return(self, cc):
# RET cc 2,5 cycles
Modified: pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py
==============================================================================
--- pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py (original)
+++ pypy/branch/pyjitpl5-PyGirl/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py Tue Mar 24 17:33:59 2009
@@ -28,7 +28,7 @@
self.sound_driver = SoundDriver()
def mainLoop(self, execution_seconds):
- self.reset()
+ #self.reset()
self.is_running = True
for i in range(int(execution_seconds * FPS)):
self.emulate_cycle()
More information about the Pypy-commit
mailing list