[9d04bd]: impnotes / bytecode-design.html Maximize Restore History

Download this file

bytecode-design.html    37 lines (36 with data), 10.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>37.7. Bytecode Design</title><link rel="stylesheet" href="impnotes.css" type="text/css" /><link rev="made" href="mailto:clisp-list@lists.sourceforge.net" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot_8465" /><link rel="home" href="index.html" title="Implementation Notes for GNU CLISP" /><link rel="up" href="bytecode.html" title="Chapter 37. The CLISP bytecode specification" /><link rel="prev" href="compiler-introspection.html" title="37.6. Examining compiled closures" /><link rel="next" href="appendices.html" title="Part V. Appendices" /><link rel="copyright" href="legalese.html" title="Legal Status of the CLISP Implementation Notes" /><meta name="date" content="'generated: 2009-07-28 12:48:49-04:00'" /><link rel="author" title="Authors" href="index.html#authors" /><link rel="contents" title="Table of Contents" href="index.html" /><link rel="glossary" href="glossary.html" /><link rel="help" href="faq.html#faq-help" title="How do I ask for help?" /><link rel="home" title="Home" href="http://clisp.cons.org" /><link rel="index" href="idx.html" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">37.7. Bytecode Design</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="compiler-introspection.html">Prev</a> </td><th width="60%" align="center">Chapter 37. The <span class="command"><strong>CLISP</strong></span> bytecode specification</th><td width="20%" align="right"> <a accesskey="n" href="appendices.html">Next</a></td></tr></table><hr /></div><div class="section" title="37.7. Bytecode Design"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="bytecode-design"></a>37.7. Bytecode Design</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="bytecode-design.html#byte-when-add-q">37.7.1. When to add a new bytecode?</a></span></dt><dt><span class="section"><a href="bytecode-design.html#byte-jmptail-q">37.7.2. Why JMPTAIL?</a></span></dt></dl></div><p>This section offers some insight into bytecode design in the form
of questions and answers.</p><div class="section" title="37.7.1. When to add a new bytecode?"><div class="titlepage"><div><div><h3 class="title"><a id="byte-when-add-q"></a>37.7.1. When to add a new bytecode?</h3></div></div></div><div class="abstract" title="Question:"><p class="title"><b>Question:</b></p><p>Does it make sense to define a new bytecode instruction for
<a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/mac_restart-case.html" target="_top"><code class="function">RESTART-CASE</code></a>? Why? Why not?</p></div><div class="simplesect" title="Answer: Is it speed critical?"><div class="titlepage"><div><div><h4 class="title"><a id="byte-when-add-a"></a>Answer: Is it speed critical?</h4></div></div></div><p><a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/mac_restart-case.html" target="_top"><code class="function">RESTART-CASE</code></a> is a glorified <a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/speope_letcm_letst.html" target="_top"><code class="function">LET</code></a> binding
for <code class="varname">SYSTEM::*ACTIVE-RESTARTS*</code> and could well profit
from a separate bytecode: it would make it non-<a class="" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/glo_c.html#cons">cons</a>ing[3].
(Remember that <a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/syscla_restart.html" target="_top"><code class="classname">RESTART</code></a>s have dynamic extent and therefore do not
really need to be heap allocated.)</p><p>The reason <a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/mac_handler-bind.html" target="_top"><code class="function">HANDLER-BIND</code></a> has its own bytecodes and
<a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/mac_restart-case.html" target="_top"><code class="function">RESTART-CASE</code></a> does not is that <a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/mac_handler-bind.html" target="_top"><code class="function">HANDLER-BIND</code></a> can occur in inner
computation loops, whereas <a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/mac_restart-case.html" target="_top"><code class="function">RESTART-CASE</code></a> occurs only as part of
user-interface programming and therefore not in inner loops where its
consing could hurt much.</p></div></div><div class="section" title="37.7.2. Why JMPTAIL?"><div class="titlepage"><div><div><h3 class="title"><a id="byte-jmptail-q"></a>37.7.2. Why <a class="link" href="instr-set.html#instr-jump" title="37.5.5. Instructions for control flow, jumps">JMPTAIL</a>?</h3></div></div></div><div class="abstract" title="Question:"><p class="title"><b>Question:</b></p><p>Consider this function and its disassembly:
</p><pre class="programlisting">
(defun foo (x y) (if (or (= x 0) (= y 0)) (+ x y) (foo y (1- x))))
(<a class="ulink" href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_disassemble.html" target="_top"><code class="function">DISASSEMBLE</code></a> 'foo)
8 (LOAD&amp;PUSH 1)
9 (LOAD&amp;DEC&amp;PUSH 3)
11 (JMPTAIL 2 5 L0)</pre><p>
Why are the arguments pushed onto the <a href="vm.html" class="olink"><code class="literal">STACK</code></a>, just to be popped off of
it during the <span class="byte"><code class="literal">JMPTAIL</code></span>?
Why not a sequence of <span class="byte"><code class="literal">LOAD</code></span>,
<span class="byte"><code class="literal">STORE</code></span> and
<span class="byte"><code class="literal">SKIP</code></span> instructions
followed by a <span class="byte"><code class="literal">JMP</code></span>?
</p></div><div class="simplesect" title="Answer: This is a shortcut for the most common use"><div class="titlepage"><div><div><h4 class="title"><a id="byte-jmptail-a"></a>Answer: This is a shortcut for the most common use</h4></div></div></div><p>Using <span class="byte"><code class="literal">JMPTAIL</code></span> requires 3
instructions, <span class="byte"><code class="literal">JMP</code></span> requires more.
When <span class="byte"><code class="literal">JMPTAIL</code></span> needs to be called, we
usually have some stuff close to the top of the <a href="vm.html" class="olink"><code class="literal">STACK</code></a> which will
become the new arguments, and some junk between these new arguments
and the closure object. <span class="byte"><code class="literal">JMPTAIL</code></span>
removes the junk. <span class="byte"><code class="literal">JMPTAIL</code></span> is a
convenient shortcut which shortens the bytecode - because typically
one would really have to clean-up the <a href="vm.html" class="olink"><code class="literal">STACK</code></a> by hand or make the
calculations in <a class="clisp-cvs" href="http://clisp.cvs.sourceforge.net/*checkout*/clisp/clisp/src/compiler.lisp"><code class="filename">src/compiler.lisp</code></a>
more complicated.</p></div></div></div><div class="bookinfo"><hr /><table width="100%" summary="impnotes meta info"><th><td align="left">These notes document <a class="ulink" href="http://clisp.cons.org" target="_top"><span class="command"><strong>CLISP</strong></span></a> version 2.48</td><td align="right">Last modified: 2009-07-28</td></th></table></div><div class="custom-footer"><hr /><table width="100%"><tr><td align="left"><a href="http://clisp.cons.org"><img src="clisp.png" width="48" height="48" alt="[CLISP home]" /></a></td><td align="center"><a href="https://sourceforge.net/donate/index.php?group_id=1355"><img src="http://images.sourceforge.net/images/project-support.jpg" width="88" height="32" alt="[Support CLISP]" /></a></td><td align="right"><a href="https://sourceforge.net/projects/clisp"><img width="120" height="30" alt="[SourceForge]" src="http://sflogo.sourceforge.net/sflogo.php?group_id=1355&amp;type=12&amp;page=bytecode-design" /></a></td></tr></table></div><hr /><form method="get" action="http://www.google.com/custom" target="_top"><table width="100%" border="0"><tr><td nowrap="nowrap" align="center"><input type="hidden" name="domains" value="clisp.cons.org;clisp.podval.org;www.lisp.org" /><label for="sbi" style="display: none">Enter your search terms</label><input type="text" name="q" size="50" maxlength="255" id="sbi" value="37.7. Bytecode Design" /><label for="sbb" style="display: none">Submit search form</label><input type="submit" name="sa" value="Google Search" id="sbb" /></td></tr><tr><td nowrap="nowrap" align="center"><input type="radio" name="sitesearch" value="" checked="1" id="ss0" /><label for="ss0" title="Search the Web"><small>Web</small></label><input type="radio" name="sitesearch" value="clisp.cons.org" id="ss1" /><label for="ss1" title="Search clisp.cons.org"><small>clisp.cons.org</small></label><input type="radio" name="sitesearch" value="clisp.podval.org" id="ss2" /><label for="ss2" title="Search clisp.podval.org"><small>clisp.podval.org</small></label><input type="radio" name="sitesearch" value="www.lisp.org" id="ss3" /><label for="ss3" title="Search www.lisp.org"><small>www.lisp.org</small></label><input type="hidden" name="client" value="pub-4445255502750357" /><input type="hidden" name="forid" value="1" /><input type="hidden" name="ie" value="UTF-8" /><input type="hidden" name="oe" value="UTF-8" /><input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:000000;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:48;LW:48;L:http://clisp.cons.org/clisp.png;S:http://clisp.cons.org;FORID:1" /><input type="hidden" name="hl" value="en" /></td></tr></table></form><hr /><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="compiler-introspection.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bytecode.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="appendices.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">37.6. Examining compiled closures </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Part V. Appendices</td></tr></table></div></body></html>