1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<h2 class="chapter">Compilation of Lisp to Native Code</h2> <p>In addition to the byte-compilation, described in <a href="byte-compilation">the previous chapter</a>, Emacs can also optionally compile Lisp function definitions into a true compiled code, known as <em>native code</em>. This feature uses the <samp>libgccjit</samp> library, which is part of the GCC distribution, and requires that Emacs be built with support for using that library. It also requires to have GCC and Binutils (the assembler and linker) available on your system for you to be able to native-compile Lisp code. </p> <p>To determine whether the current Emacs process can produce and load natively-compiled Lisp code, call <code>native-comp-available-p</code> (see <a href="native_002dcompilation-functions">Native-Compilation Functions</a>). </p> <p>Unlike byte-compiled code, natively-compiled Lisp code is executed directly by the machine’s hardware, and therefore runs at full speed that the host CPU can provide. The resulting speedup generally depends on what the Lisp code does, but is usually 2.5 to 5 times faster than the corresponding byte-compiled code. </p> <p>Since native code is generally incompatible between different systems, the natively-compiled code is <em>not</em> transportable from one machine to another, it can only be used on the same machine where it was produced or on very similar ones (having the same CPU and run-time libraries). The transportability of natively-compiled code is the same as that of shared libraries (<samp>.so</samp> or <samp>.dll</samp> files). </p> <p>Libraries of natively-compiled code include crucial dependencies on Emacs Lisp primitives (see <a href="what-is-a-function">What Is a Function</a>) and their calling conventions, and thus Emacs usually won’t load natively-compiled code produced by earlier or later Emacs versions; native compilation of the same Lisp code by a different Emacs version will usually produce a natively-compiled library under a unique file name that only that version of Emacs will be able to load. However, the use of unique file names allows to have in the same directory several versions of the same Lisp library natively-compiled by several different versions of Emacs. </p> <p>A non-<code>nil</code> file-local variable binding of <code>no-byte-compile</code> (see <a href="byte-compilation">Byte Compilation</a>) also disables the native compilation of that file. In addition, a similar variable <code>no-native-compile</code> disables just the native compilation of the file. If both <code>no-byte-compile</code> and <code>no-native-compile</code> are specified, the former takes precedence. </p> <table class="menu" border="0" cellspacing="0"> <tr>
<td align="left" valign="top">• <a href="native_002dcompilation-functions" accesskey="1">Native-Compilation Functions</a>
</td>
<td> </td>
<td align="left" valign="top">Functions to natively-compile Lisp. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="native_002dcompilation-variables" accesskey="2">Native-Compilation Variables</a>
</td>
<td> </td>
<td align="left" valign="top">Variables controlling native compilation. </td>
</tr> </table><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Native-Compilation.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Native-Compilation.html</a>
</p>
</div>
|