2011/1/31 Antoine Pitrou <span dir="ltr">&lt;<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Mon, 31 Jan 2011 13:28:39 +0100<br>
&quot;Jurjen N.E. Bos&quot; &lt;<a href="mailto:Jurjen.Bos@hetnet.nl">Jurjen.Bos@hetnet.nl</a>&gt; wrote:<br>
&gt; I just did it: my first python source code hack.<br>
&gt; I replaced the NEXTARG and PEEKARG macros in ceval.c using a cast to<br>
&gt; short pointer, and lo and behold, a crude measurement indicates one<br>
&gt; to two percent speed increase.<br>
&gt; That isn&#39;t much, but it is virtually for free!<br>
&gt;<br>
&gt; Here are the macro&#39;s I used:<br>
&gt; #define NEXTARG() (next_instr +=2, *(short*)&amp;next_instr[-2])<br>
&gt; #define PEEKARG() (*(short*)&amp;next_instr[1])<br>
<br>
</div>Some architectures forbid unaligned access, so this can&#39;t be used as-is.<br>
<br>
Regards<br>
<font color="#888888"><br>
Antoine.<br>
</font><div><div class="h5"><br>
</div></div></blockquote><div><br></div><div>WPython already addressed it ( <a href="http://code.google.com/p/wpython2/source/browse/Python/ceval.c?repo=wpython11">http://code.google.com/p/wpython2/source/browse/Python/ceval.c?repo=wpython11</a> ):</div>
<div><br></div><div>#ifdef WORDS_BIGENDIAN<br>#define NEXTOPCODE()        oparg = *next_instr++; \<br>                                                opcode = oparg &gt;&gt; 8; oparg &amp;= 0xff<br>#else<br>#define NEXTOPCODE()        oparg = *next_instr++; \<br>                                                opcode = oparg &amp; 0xff; oparg &gt;&gt;= 8<br>
#endif<br><br></div><div>Shorts alignament is also guaranted due to wordcodes ( <a href="http://wpython2.googlecode.com/files/Beyond%20Bytecode%20-%20A%20Wordcode-based%20Python.pdf">http://wpython2.googlecode.com/files/Beyond%20Bytecode%20-%20A%20Wordcode-based%20Python.pdf</a> pag.12).</div>
<div><br></div><div>Cesare</div>