<story><title>A CPU is a compiler</title><url>https://outerproduct.net/boring/2023-03-22_cpu-compiler-gc-ohmy.html</url></story><parent_chain><item><author>PaulHoule</author><text>An advanced interpreter has many features of a compiler.&lt;p&gt;For instance there is the kind of simple interpreter that I know how to write off the top of my head which evaluates the nodes of an expression tree which is horribly inefficient.&lt;p&gt;Then there is something like Python which &amp;quot;compiles&amp;quot; code to bytecode which is then interpreted by a &amp;quot;virtual machine&amp;quot;.  That kind of system admits very complex optimizations about as far you as can imagine,  including compiling some of the bytecode all the way to machine code the way PyPy or the JVM does it.&lt;p&gt;Note most interpretations of the Intel architectures break complex instructions up into RISC-like &amp;quot;micro-ops&amp;quot;,  which is a bit like bytecode interpretation.&lt;p&gt;One of the biggest concerns in a modern CPU is that memory accesses are very slow relative to a CPU cycle so you want to be executing a large number of instructions at a time to hide the latency of memory access.  Intel&amp;#x27;s failed Itanium had the compiler try to explicitly schedule this but it didn&amp;#x27;t work because the compiler can&amp;#x27;t know ahead of time (for general purpose code) what is in what level of the cache and what isn&amp;#x27;t -- and in a worse case scenario this can hang up not only one instruction but many other instructions that depend on the result of that instruction,  ether because they really depend on the result or because the CPU gets hung up.  The CPU, on the other hand, does know,  and can be opportunistic about taking advantage of available parallelism.</text></item></parent_chain><comment><author>PaulDavisThe1st</author><text>&amp;gt; An advanced interpreter has many features of a compiler.&lt;p&gt;There&amp;#x27;s a historical line from a CS great (I am not sure who) that goes something like:&lt;p&gt;When you first start writing software, you will not understand the difference between an interpreter and a compiler. After you&amp;#x27;ve been writing software for a certain amount of time, you will never confuse an interpreter and a compiler. But after you&amp;#x27;ve been writing software for a bit longer than that, you will again not understand what the difference between them really is.</text></comment>
<story><title>A CPU is a compiler</title><url>https://outerproduct.net/boring/2023-03-22_cpu-compiler-gc-ohmy.html</url></story><parent_chain><item><author>PaulHoule</author><text>An advanced interpreter has many features of a compiler.&lt;p&gt;For instance there is the kind of simple interpreter that I know how to write off the top of my head which evaluates the nodes of an expression tree which is horribly inefficient.&lt;p&gt;Then there is something like Python which &amp;quot;compiles&amp;quot; code to bytecode which is then interpreted by a &amp;quot;virtual machine&amp;quot;.  That kind of system admits very complex optimizations about as far you as can imagine,  including compiling some of the bytecode all the way to machine code the way PyPy or the JVM does it.&lt;p&gt;Note most interpretations of the Intel architectures break complex instructions up into RISC-like &amp;quot;micro-ops&amp;quot;,  which is a bit like bytecode interpretation.&lt;p&gt;One of the biggest concerns in a modern CPU is that memory accesses are very slow relative to a CPU cycle so you want to be executing a large number of instructions at a time to hide the latency of memory access.  Intel&amp;#x27;s failed Itanium had the compiler try to explicitly schedule this but it didn&amp;#x27;t work because the compiler can&amp;#x27;t know ahead of time (for general purpose code) what is in what level of the cache and what isn&amp;#x27;t -- and in a worse case scenario this can hang up not only one instruction but many other instructions that depend on the result of that instruction,  ether because they really depend on the result or because the CPU gets hung up.  The CPU, on the other hand, does know,  and can be opportunistic about taking advantage of available parallelism.</text></item></parent_chain><comment><author>czx4f4bd</author><text>Just a tiny nitpick for clarity, I think you mean PyPy rather than &amp;quot;PyPi&amp;quot;. :)&lt;p&gt;PyPI is the Python Package Index. &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;en.wikipedia.org&amp;#x2F;wiki&amp;#x2F;Python_Package_Index&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;en.wikipedia.org&amp;#x2F;wiki&amp;#x2F;Python_Package_Index&lt;/a&gt;&lt;p&gt;PyPy is the Python implementation with JIT. &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;en.wikipedia.org&amp;#x2F;wiki&amp;#x2F;PyPy&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;en.wikipedia.org&amp;#x2F;wiki&amp;#x2F;PyPy&lt;/a&gt;&lt;p&gt;(Yes, it is extremely confusing that there are two Python projects with homophonous, nearly-identical names.)</text></comment>