• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Nix flake for RPython interpreters


Commit MetaInfo

Revisiond34260f8d53fb00903e33949e55629456f7eaf16 (tree)
Time2024-04-09 05:53:34
AuthorCorbin <cds@corb...>
CommiterCorbin

Log Message

Add JIT to DIVSPL interpreter.

I only saw a minor speedup in my testing, but the assembly code is
well-structured and should do a decent job for small numbers of rules.
The number of failed guards is exponential in the number of rules, so
I'm not sure if there's any good solution.

Change Summary

Incremental Difference

--- a/divspl/divspl.py
+++ b/divspl/divspl.py
@@ -1,9 +1,12 @@
11 import sys
22
3+from rpython.jit.codewriter.policy import JitPolicy
4+from rpython.rlib.jit import JitDriver
5+
36 # This is a basic interpreter for DIVSPL, as described at
47 # https://www.promptworks.com/blog/the-fastest-fizzbuzz-in-the-west
58 # Version 0: Initial functionality
6-# Version 1: Port to RPython
9+# Version 1: Port to RPython, add JIT
710
811 def parseAssignment(line):
912 word, number = [w.strip() for w in line.rsplit("=", 1)]
@@ -12,13 +15,22 @@ def parseAssignment(line):
1215 def parse(lines):
1316 # The first line must be the range.
1417 start, stop = [int(n.strip()) for n in lines[0].split("...")]
15- assignments = [parseAssignment(line) for line in lines[1:]]
18+ # Skip empty lines, usually at EOF.
19+ assignments = [parseAssignment(line) for line in lines[1:] if line]
1620 return start, stop, assignments
1721
22+def location(stop, assignments):
23+ return "%d rules, stop at %d" % (len(assignments), stop)
24+driver = JitDriver(greens=["stop", "assignments"], reds=["i"],
25+ get_printable_location=location)
26+
1827 def run(start, stop, assignments):
19- for i in range(start, stop + 1):
28+ i = start
29+ while i <= stop:
30+ driver.jit_merge_point(stop=stop, assignments=assignments, i=i)
2031 s = [w for w, n in assignments if not i % n]
2132 print ("".join(s) if s else str(i))
33+ i += 1
2234
2335 # NB: programs should already be split into lines
2436 def main(argv):
@@ -31,6 +43,6 @@ def main(argv):
3143 return 0
3244
3345 def target(*args): return main, None
46+def jitpolicy(driver): return JitPolicy()
3447
35-if __name__ == "__main__":
36- sys.exit(main(sys.argv))
48+if __name__ == "__main__": sys.exit(main(sys.argv))
--- a/flake.nix
+++ b/flake.nix
@@ -131,7 +131,6 @@
131131 entrypoint = "divspl.py";
132132 binName = "divspl-c";
133133 binInstallName = "divspl";
134- optLevel = "2";
135134 } {
136135 pname = "divspl";
137136 version = "1";