posted on 2013-07-05 11:44:00
This will be the last post about emulation that doesn't involve graphics or disassembly of old NES games, I promise. cl-6502 0.9.5 is out and, in my testing with SBCL, pretty snappy. The book has received updates and is also available on lulu. Below is the 'Lessons Learned - Common Lisp' chapter:
Structures are much more static than classes. They also enforce their slot types. When you have a solid idea of the layout of your data and really need speed, they're ideal.
CLOS, for single-dispatch at least, is really quite fast. When I redesigned the emulator to avoid a method call for every memory read/write, my benchmark only ran ~10% faster. I eventually chose to stick with the new scheme for several reasons, performance was only a minor factor.
My second big speedup came, indirectly, from changing the arguments to the
opcode lambdas. By having the opcode only take a single argument, the CPU, I
avoided the need to destructure the opcode metadata in
step-cpu. You don't
want to destructure a list in your inner loop, no matter how readable it is!
That is, the times I found myself using it always involved computing data at
compile-time that would be stored or accessed in a later phase. E.g. I used
it to ensure that the status-bit enum was created for use by
*mode-bodies* variable was bound in time for
try to go without it if possible.
DECLAIM is for global declarations and DECLARE is for local ones. Once you've
eked out as many algorithmic gains as possible and figured out your hotspots with
the profiler, recompile your code with
(declaim (optimize speed)) to see what
is keeping the compiler from generating fast code. Letting the compiler know the
FTYPE of your most called functions and inlining a few things can make a big
This blog covers consumption, XKCD, programming, linux, Xmas, Education, injustice, Quotes, metapost, milosz, Webcomic, 2015, Uncategorized, creation, Lessig, Discrete Math, Operating Systems, ragequit, Milosz, Gapingvoid, C, Pics, Poetry, Lists, Neruda, recreation, Erlang, work, careers, Programming, poetry, apple, Project Euler, Lecture, Open Source, Books, LISP, melee, Music, Essay, goals, strangeloop, Gaming, fqa, IP Law, Butler, HTDP, Personal, Linkpost, games, heroes, rip, \"Real World\", Hardware, adulthood, Displays, MPAA, personal, Self-Learning, Linux, Programming Languages, Dad, math, Reddit, SICP, lisp, coleslaw
View content from 2007-06, 2013-06, 2015-05, 2011-07, 2010-04, 2010-09, 2009-04, 2008-04, 2009-07, 2009-09, 2008-01, 2007-12, 2012-10, 2007-08, 2008-10, 2012-01, 2011-01, 2009-11, 2008-02, 2014-01, 2009-10, 2009-05, 2015-03, 2010-01, 2013-04, 2007-10, 2011-04, 2008-07, 2010-07, 2007-11, 2008-03, 2009-06, 2011-02, 2008-11, 2013-05, 2009-08, 2015-02, 2011-09, 2008-12, 2013-03, 2011-05, 2012-04, 2012-05, 2009-12, 2009-03, 2013-01, 2012-03, 2008-06, 2007-05, 2011-08, 2014-09, 2013-09, 2012-09, 2010-10, 2009-01, 2008-05, 2009-02, 2007-07, 2010-03, 2012-08, 2010-02, 2014-07, 2012-12, 2007-09, 2012-06, 2013-07, 2008-08, 2014-11, 2011-10, 2010-05, 2010-11, 2015-01, 2013-10, 2014-05, 2011-06, 2015-09, 2008-09, 2010-08