<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;action=history&amp;feed=atom</id>
		<title>Consider the Hardware - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;action=history&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;action=history"/>
		<updated>2013-06-20T00:49:40Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.11.0</generator>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=25661&amp;oldid=prev</id>
		<title>Jasonpsage at 04:51, 6 October 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=25661&amp;oldid=prev"/>
				<updated>2009-10-06T04:51:04Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 04:51, 6 October 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the ''goto'' command is the fastest method to get around in a code block, followed closely by jump tables. Functions are great for us developers; from the CPU's point of view, however, they are penny smart and dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the ''goto'' command is the fastest method to get around in a code block, followed closely by jump tables. Functions are great for us developers; from the CPU's point of view, however, they are penny smart and dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Class inheritance and virtual &lt;/del&gt;functions&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, whether direct or via interfaces, have convenience that comes at &lt;/del&gt;a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;price&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;You can eliminate much of their overhead by keeping inheritance levels to &lt;/del&gt;a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;minimum and avoiding using interfaces just &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;extend inheritance levels. Sometimes &lt;/del&gt;it's &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;better to have a larger faster executable than a smaller one that runs slower&lt;/del&gt;; &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for example try using include files to reuse code across various classes rather than using inheritance&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Inline &lt;/ins&gt;functions &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/ins&gt;a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;different animal that trades requiring start up and completion tasks for overall program size&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;The word inline is accurate because everywhere in your source code where you have &lt;/ins&gt;a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;call &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;an inline function, the code for that function is copied into your code verbatim and then &lt;/ins&gt;it &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is compiled. Having too many inline functions, especially large ones, can significantly increase your compiled application&lt;/ins&gt;'s &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;filesize&lt;/ins&gt;; &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;this might be a worthwhile trade&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Speed or Filesize? Make your choice!&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video game and embedded system developers know the hardware ramifications of their code. Do you?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Depending on your compiler, there can be implications on program execution speed using classes. Many developers seem to think having class libraries that contain many generations of inheritance is wonderful when it comes at a price. Normal inheritance levels incur some overhead if you get into the nuts and bolts of them but the real problem when it comes to efficiency is those nasty virtual functions. Virtual functions require a virtual base class lookup table for each level of virtual inheritance and matters can get exponentially worse when there are multiple levels of inheritance. There are better things your processor could be doing than traversing memory linked list tables to hunt for code to run. &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;What hardware are you developing for? What does your compiler do to your code as it turns it to assembly language? Are you using a virtual machine? You'll rarely find a single programming methodology that will work perfectly on all hardware platforms, real or virtual. &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video game and embedded system developers know the hardware ramifications of their &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;compiled &lt;/ins&gt;code. Do you?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Jason P Sage]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[Jason P Sage]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:24955:newid:25661 --&gt;
&lt;/table&gt;</summary>
		<author><name>Jasonpsage</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=24955&amp;oldid=prev</id>
		<title>Kevlin at 10:16, 19 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=24955&amp;oldid=prev"/>
				<updated>2009-07-19T10:16:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 10:16, 19 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's a common opinion that slow software just needs faster hardware. This line of thinking is not necessarily wrong, but like misusing antibiotics, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;over time &lt;/del&gt;it can become a big problem. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt; &lt;/del&gt;Software architecture has abstracted the underlying hardware so much that many developers don't have any idea how it really works. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's a common opinion that slow software just needs faster hardware. This line of thinking is not necessarily wrong, but like misusing antibiotics, it can become a big problem &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;over time&lt;/ins&gt;. Software architecture has abstracted the underlying hardware so much that many developers don't have any idea how it really works. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First let's look at how you can start to make the most of your CPUs' prefetch cache. Code branches such as &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;IF&lt;/del&gt;-&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;THEN &lt;/del&gt;constructs can only go two ways (jump tables aside): condition met and condition not met. Most prefetch caches look ahead by &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;“guessing” &lt;/del&gt;where your code will branch to. When the cache &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;“guesses” &lt;/del&gt;correctly, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;its &lt;/del&gt;amazingly fast&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, however if &lt;/del&gt;it &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;“guesses” &lt;/del&gt;wrong, all the preprocessing on this &amp;quot;wrong branch&amp;quot; is useless and a time consuming cache invalidation occurs. Fortunately, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;its &lt;/del&gt;easy to start making the prefetch cache work harder for you. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;let's look at how you can start to make the most of your CPUs' prefetch cache. Code branches such as &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''if&lt;/ins&gt;-&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;then'' &lt;/ins&gt;constructs can only go &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;one of &lt;/ins&gt;two ways (jump tables aside): condition met and condition not met. Most prefetch caches look ahead by &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;quot;guessing&amp;quot; &lt;/ins&gt;where your code will branch to. When the cache &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;quot;guesses&amp;quot; &lt;/ins&gt;correctly, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;it's &lt;/ins&gt;amazingly fast&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. If &lt;/ins&gt;it &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;quot;guesses&amp;quot; &lt;/ins&gt;wrong&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, on the other hand&lt;/ins&gt;, all the preprocessing on this &amp;quot;wrong branch&amp;quot; is useless and a time&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/ins&gt;consuming cache invalidation occurs. Fortunately, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;it's &lt;/ins&gt;easy to start making the prefetch cache work harder for you.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you code your branch logic so that the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;MOST FREQUENT RESULT &lt;/del&gt;is the condition that is tested for, you will help your CPU's prefetch cache be &amp;quot;correct&amp;quot; more often &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;resulting is less &amp;quot;&lt;/del&gt;CPU &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Expensive&amp;quot; &lt;/del&gt;cache invalidations. This sometimes may read a little awkwardly, but &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;systemically &lt;/del&gt;applying this technique over time will decrease your code's execution time.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you code your branch logic so that the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''most frequent result'' &lt;/ins&gt;is the condition that is tested for, you will help your CPU's prefetch cache be &amp;quot;correct&amp;quot; more often&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, leading to fewer &lt;/ins&gt;CPU&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-expensive &lt;/ins&gt;cache invalidations. This sometimes may read a little awkwardly, but &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;systematically &lt;/ins&gt;applying this technique over time will decrease your code's execution time.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for &lt;/del&gt;mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;against &lt;/ins&gt;mainstream best practices.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;/or &lt;/del&gt;from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;GOTO &lt;/del&gt;command is the fastest method to get around in a code block&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;; following &lt;/del&gt;closely &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;behind are &lt;/del&gt;jump tables. Functions are great for us developers&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;: &lt;/del&gt;from the CPU's point of view however, they are penny smart and dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''goto'' &lt;/ins&gt;command is the fastest method to get around in a code block&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, followed &lt;/ins&gt;closely &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;by &lt;/ins&gt;jump tables. Functions are great for us developers&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;; &lt;/ins&gt;from the CPU's point of view&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;however, they are penny smart and dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces, have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces, have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Game &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Embedded System &lt;/del&gt;developers know the hardware ramifications of their code&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;;  do &lt;/del&gt;you?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;game &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;embedded system &lt;/ins&gt;developers know the hardware ramifications of their code&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. Do &lt;/ins&gt;you?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;By [[Jason P Sage]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This work is licensed under a [http://creativecommons.org/licenses/by/3.0/us/ Creative Commons Attribution 3] &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Back to [[97 Things Every Programmer Should Know]] home page&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23611&amp;oldid=prev</id>
		<title>Rstafford at 05:52, 6 March 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23611&amp;oldid=prev"/>
				<updated>2009-03-06T05:52:36Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 05:52, 6 March 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's a common opinion that slow software just needs faster hardware. This line of thinking is not necessarily wrong, but like misusing antibiotics, over time it can become a big problem.  Software architecture has abstracted the underlying hardware so much that many developers don't have any idea how it really works. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's a common opinion that slow software just needs faster hardware. This line of thinking is not necessarily wrong, but like misusing antibiotics, over time it can become a big problem.  Software architecture has abstracted the underlying hardware so much that many developers don't have any idea how it really works. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First let's look at how you can start to make the most of your CPUs' prefetch cache. Code branches such as IF-THEN constructs can only go two ways (jump tables aside): condition met and condition not met. Most prefetch &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;cache &lt;/del&gt;look ahead by “guessing” where your code will branch to. When the cache “guesses” correctly, its amazingly fast, however if it “guesses” wrong, all the preprocessing on this &amp;quot;wrong branch&amp;quot; is useless and a time consuming cache invalidation occurs. Fortunately, its easy to start making the prefetch cache work harder for you. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First let's look at how you can start to make the most of your CPUs' prefetch cache. Code branches such as IF-THEN constructs can only go two ways (jump tables aside): condition met and condition not met. Most prefetch &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;caches &lt;/ins&gt;look ahead by “guessing” where your code will branch to. When the cache “guesses” correctly, its amazingly fast, however if it “guesses” wrong, all the preprocessing on this &amp;quot;wrong branch&amp;quot; is useless and a time consuming cache invalidation occurs. Fortunately, its easy to start making the prefetch cache work harder for you. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you code your branch logic so that the MOST FREQUENT RESULT is the condition that is tested for, you will help your CPU's prefetch cache be &amp;quot;correct&amp;quot; more often resulting is less &amp;quot;CPU Expensive&amp;quot; cache invalidations. This sometimes may read a little &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;awkward &lt;/del&gt;but systemically applying this technique over time will &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;increase &lt;/del&gt;your code's execution time.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you code your branch logic so that the MOST FREQUENT RESULT is the condition that is tested for, you will help your CPU's prefetch cache be &amp;quot;correct&amp;quot; more often resulting is less &amp;quot;CPU Expensive&amp;quot; cache invalidations. This sometimes may read a little &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;awkwardly, &lt;/ins&gt;but systemically applying this technique over time will &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;decrease &lt;/ins&gt;your code's execution time.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and/or from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the GOTO command is the fastest method to get around in a code block; following closely behind are jump tables. Functions are great for us developers: from the CPU's point of view however, they are penny smart and dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and/or from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the GOTO command is the fastest method to get around in a code block; following closely behind are jump tables. Functions are great for us developers: from the CPU's point of view however, they are penny smart and dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video Game and Embedded System developers know the hardware ramifications of their code;  do you?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video Game and Embedded System developers know the hardware ramifications of their code;  do you?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:23585:newid:23611 --&gt;
&lt;/table&gt;</summary>
		<author><name>Rstafford</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23585&amp;oldid=prev</id>
		<title>Jasonpsage at 02:13, 4 March 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23585&amp;oldid=prev"/>
				<updated>2009-03-04T02:13:51Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 02:13, 4 March 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and/or from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the GOTO command is the fastest method to get around in a code block; following closely behind are jump tables. Functions are great&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, but &lt;/del&gt;the CPU &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;might think &lt;/del&gt;they are penny smart&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls require moving data to and/or from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the GOTO command is the fastest method to get around in a code block; following closely behind are jump tables. Functions are great &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for us developers: from &lt;/ins&gt;the CPU&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'s point of view however, &lt;/ins&gt;they are penny smart &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and &lt;/ins&gt;dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video Game and Embedded System developers know the hardware ramifications of their code;  do you?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video Game and Embedded System developers know the hardware ramifications of their code;  do you?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:23584:newid:23585 --&gt;
&lt;/table&gt;</summary>
		<author><name>Jasonpsage</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23584&amp;oldid=prev</id>
		<title>Jasonpsage at 02:11, 4 March 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23584&amp;oldid=prev"/>
				<updated>2009-03-04T02:11:57Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 02:11, 4 March 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;requires &lt;/del&gt;moving data to and/or from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the GOTO command is the fastest method to get around in a code block; following closely behind are jump tables. Functions are great, but the CPU might think they are penny smart, dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of large ones to ease maintainability, but the fact is that function calls &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;require &lt;/ins&gt;moving data to and/or from the stack to prepare for the function call and to return properly from it. Many applications using this paradigm spend more time preparing and recovering from work than actually doing it! Truth is, the GOTO command is the fastest method to get around in a code block; following closely behind are jump tables. Functions are great, but the CPU might think they are penny smart, dollar dumb.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Class inheritance and virtual functions, whether direct or via interfaces have convenience that comes at a price. You can eliminate much of their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels. Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video Game and Embedded System developers know the hardware ramifications of their code;  do you?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Video Game and Embedded System developers know the hardware ramifications of their code;  do you?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:23583:newid:23584 --&gt;
&lt;/table&gt;</summary>
		<author><name>Jasonpsage</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23583&amp;oldid=prev</id>
		<title>Jasonpsage at 02:10, 4 March 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23583&amp;oldid=prev"/>
				<updated>2009-03-04T02:10:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 02:10, 4 March 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's a common opinion that slow software just needs faster hardware. This line of thinking is not necessarily wrong, but like &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;overusing &lt;/del&gt;antibiotics, over time it can become a big problem.  Software architecture has abstracted the underlying hardware so much that many developers don't have any idea how it really works. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's a common opinion that slow software just needs faster hardware. This line of thinking is not necessarily wrong, but like &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;misusing &lt;/ins&gt;antibiotics, over time it can become a big problem.  Software architecture has abstracted the underlying hardware so much that many developers don't have any idea how it really works. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First let's look at how you can start to make the most of your CPUs' prefetch cache. Code branches such as IF-THEN constructs can only go two ways (jump tables aside): condition met and condition not met. Most prefetch cache look ahead by “guessing” where your code will branch to. When the cache “guesses” correctly, its amazingly fast, however if it “guesses” wrong, all the preprocessing on this &amp;quot;wrong branch&amp;quot; is useless and a time consuming cache invalidation occurs. Fortunately, its easy to start making the prefetch cache work harder for you. &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First let's look at how you can start to make the most of your CPUs' prefetch cache. Code branches such as IF-THEN constructs can only go two ways (jump tables aside): condition met and condition not met. Most prefetch cache look ahead by “guessing” where your code will branch to. When the cache “guesses” correctly, its amazingly fast, however if it “guesses” wrong, all the preprocessing on this &amp;quot;wrong branch&amp;quot; is useless and a time consuming cache invalidation occurs. Fortunately, its easy to start making the prefetch cache work harder for you. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Jasonpsage</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23562&amp;oldid=prev</id>
		<title>Jasonpsage at 02:35, 3 March 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23562&amp;oldid=prev"/>
				<updated>2009-03-03T02:35:34Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 02:35, 3 March 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for developers, managers, and users alike to have the &lt;/del&gt;opinion that software &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that doesn't run fast enough &lt;/del&gt;just needs faster hardware. This line of thinking is not necessarily wrong, but like &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;incorrect use of &lt;/del&gt;antibiotics, over time can become a big problem &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that is hard to solve&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Unfortunately, software development seems to have been &lt;/del&gt;abstracted so much that many developers &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;do not even consider the hardware at all&lt;/del&gt;. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/ins&gt;common opinion that &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;slow &lt;/ins&gt;software just needs faster hardware. This line of thinking is not necessarily wrong, but like &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;overusing &lt;/ins&gt;antibiotics, over time &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;it &lt;/ins&gt;can become a big problem. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt; Software architecture has &lt;/ins&gt;abstracted &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the underlying hardware &lt;/ins&gt;so much that many developers &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;don't have any idea how it really works&lt;/ins&gt;. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First let's look at &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;something that doesn't cause any conflicts in most developer shops' accepted best practices: Making &lt;/del&gt;the most of your CPUs' prefetch cache. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;CPU prefetch caching logic and heuristics are not trivial but there is something trivial you can do in all your branching logic to make it work for you. All branching in your code &lt;/del&gt;can only go two ways (jump tables aside): &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;One way if a &lt;/del&gt;condition &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/del&gt;met&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, another if that &lt;/del&gt;condition &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/del&gt;not met. Most &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;CPU Prefetch &lt;/del&gt;cache &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;load and pre-process code that hasn't even been encountered yet &lt;/del&gt;by &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;quot;guessing&amp;quot; the path &lt;/del&gt;your &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;program &lt;/del&gt;will &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;follow before it gets there&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;CPU discovers that the &amp;quot;guesses&amp;quot; &lt;/del&gt;it &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;made were incorrect&lt;/del&gt;, all the preprocessing on this &amp;quot;wrong branch&amp;quot; &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/del&gt;useless and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;invalidate the cache: this is &lt;/del&gt;a time consuming &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;consequence in CPU cycles&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;So &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;befriend &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;CPU &lt;/del&gt;cache &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;you need to know how to make it &lt;/del&gt;work for you&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, fortunately, its quite simple. If you code all your branch logic so that the MOST FREQUENT RESULT is the condition that is tested for, you will help your CPU's prefetch cache be &amp;quot;correct&amp;quot; more often resulting is less &amp;quot;CPU Expensive&amp;quot; cache invalidations. This sometimes may read a little awkward but systemically applying this technique over time will increase your code's execution time&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;First let's look at &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;how you can start to make &lt;/ins&gt;the most of your CPUs' prefetch cache. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Code branches such as IF-THEN constructs &lt;/ins&gt;can only go two ways (jump tables aside): condition met &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and &lt;/ins&gt;condition not met. Most &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;prefetch &lt;/ins&gt;cache &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;look ahead &lt;/ins&gt;by &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;“guessing” where &lt;/ins&gt;your &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;code &lt;/ins&gt;will &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;branch to&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;When &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;cache “guesses” correctly, its amazingly fast, however if &lt;/ins&gt;it &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;“guesses” wrong&lt;/ins&gt;, all the preprocessing on this &amp;quot;wrong branch&amp;quot; &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/ins&gt;useless and a time consuming &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;cache invalidation occurs&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Fortunately, its easy &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;start making &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;prefetch &lt;/ins&gt;cache work &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;harder &lt;/ins&gt;for you. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. It's common practice to write many small functions in favor of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;larger &lt;/del&gt;ones &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that are harder &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;maintain. Now this is perfectly sound from an abstract point of view &lt;/del&gt;but the fact is that &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;every &lt;/del&gt;function &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;call &lt;/del&gt;requires moving data to and from the stack &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;both &lt;/del&gt;to prepare for the function call and to return properly from it. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Most &lt;/del&gt;applications &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that are written &lt;/del&gt;using this &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;design &lt;/del&gt;paradigm &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;actually &lt;/del&gt;spend more time &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;getting ready &lt;/del&gt;and recovering from &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;doing &lt;/del&gt;work than &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;they do actual work. Some developers might cringe at &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;mention of the fact that the often ridiculed &lt;/del&gt;GOTO command is the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;most efficient &lt;/del&gt;method to get around a code block; &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;rivaled only by the lightning fast &lt;/del&gt;jump &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;table - another hardware savvy technique &lt;/del&gt;that &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;many developers aren't even aware &lt;/del&gt;of.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If you code your branch logic so that the MOST FREQUENT RESULT is the condition that is tested for, you will help your CPU's prefetch cache be &amp;quot;correct&amp;quot; more often resulting is less &amp;quot;CPU Expensive&amp;quot; cache invalidations. This sometimes may read a little awkward but systemically applying this technique over time will increase your code's execution time.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common practice to write many small functions in favor of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;large &lt;/ins&gt;ones to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;ease maintainability, &lt;/ins&gt;but the fact is that function &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;calls &lt;/ins&gt;requires moving data to and&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;/or &lt;/ins&gt;from the stack to prepare for the function call and to return properly from it. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Many &lt;/ins&gt;applications using this paradigm spend more time &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;preparing &lt;/ins&gt;and recovering from work than &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;actually doing it! Truth is, &lt;/ins&gt;the GOTO command is the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;fastest &lt;/ins&gt;method to get around &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;in &lt;/ins&gt;a code block; &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;following closely behind are &lt;/ins&gt;jump &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;tables. Functions are great, but the CPU might think they are penny smart, dollar dumb.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Class inheritance and virtual functions, whether direct or via interfaces have convenience &lt;/ins&gt;that &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;comes at a price. You can eliminate much &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;their overhead by keeping inheritance levels to a minimum and avoiding using interfaces just to extend inheritance levels&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Sometimes it's better to have a larger faster executable than a smaller one that runs slower; for example try using include files to reuse code across various classes rather than using inheritance.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Video Game and Embedded System developers know the hardware ramifications of their code;  do you?&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Jasonpsage</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23558&amp;oldid=prev</id>
		<title>Jasonpsage at 01:32, 3 March 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23558&amp;oldid=prev"/>
				<updated>2009-03-03T01:32:16Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 01:32, 3 March 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common for developers, managers, and users alike to have the opinion that software that doesn't run fast enough just needs faster hardware. This line of thinking is not necessarily wrong, but like incorrect use of antibiotics, over time can become a big problem that is hard to solve.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It's common for developers, managers, and users alike to have the opinion that software that doesn't run fast enough just needs faster hardware. This line of thinking is not necessarily wrong, but like incorrect use of antibiotics, over time can become a big problem that is hard to solve&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. Unfortunately, software development seems to have been abstracted so much that many developers do not even consider the hardware at all. Furthermore, there is often a direct conflict of interest between best programming practices and writing code that screams on the given hardware&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;There are three important facts &lt;/del&gt;that are &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;important &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;consider&lt;/del&gt;:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;First let's look at something &lt;/ins&gt;that &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;doesn't cause any conflicts in most developer shops' accepted best practices: Making the most of your CPUs' prefetch cache. CPU prefetch caching logic and heuristics &lt;/ins&gt;are &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;not trivial but there is something trivial you can do in all your branching logic &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;make it work for you. All branching in your code can only go two ways (jump tables aside)&lt;/ins&gt;: &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;One way if a condition is met, another if that condition is not met. Most CPU Prefetch cache load and pre-process code that hasn't even been encountered yet by &amp;quot;guessing&amp;quot; the path your program will follow before it gets there. If the CPU discovers that the &amp;quot;guesses&amp;quot; it made were incorrect, all the preprocessing on this &amp;quot;wrong branch&amp;quot; are useless and invalidate the cache: this is a time consuming consequence in CPU cycles. So to befriend the CPU cache you need to know how to make it work for you, fortunately, its quite simple. If you code all your branch logic so that the MOST FREQUENT RESULT is the condition that is tested for, you will help your CPU's prefetch cache be &amp;quot;correct&amp;quot; more often resulting is less &amp;quot;CPU Expensive&amp;quot; cache invalidations. This sometimes may read a little awkward but systemically applying this technique over time will increase your code's execution time.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt; * test&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Now, let's look at some of the conflicts between writing code for hardware and writing for mainstream best practices. It's common practice to write many small functions in favor of larger ones that are harder to maintain. Now this is perfectly sound from an abstract point of view but the fact is that every function call requires moving data to and from the stack both to prepare for the function call and to return properly from it. Most applications that are written using this design paradigm actually spend more time getting ready and recovering from doing work than they do actual work. Some developers might cringe at the mention of the fact that the often ridiculed GOTO command is the most efficient method to get around a code block; rivaled only by the lightning fast jump table - another hardware savvy technique that many developers aren't even aware of.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:23557:newid:23558 --&gt;
&lt;/table&gt;</summary>
		<author><name>Jasonpsage</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23557&amp;oldid=prev</id>
		<title>Jasonpsage: New page: It's common for developers, managers, and users alike to have the opinion that software that doesn't run fast enough just needs faster hardware. This line of thinking is not necessarily wr...</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Consider_the_Hardware&amp;diff=23557&amp;oldid=prev"/>
				<updated>2009-03-03T00:47:43Z</updated>
		
		<summary type="html">&lt;p&gt;New page: It's common for developers, managers, and users alike to have the opinion that software that doesn't run fast enough just needs faster hardware. This line of thinking is not necessarily wr...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;It's common for developers, managers, and users alike to have the opinion that software that doesn't run fast enough just needs faster hardware. This line of thinking is not necessarily wrong, but like incorrect use of antibiotics, over time can become a big problem that is hard to solve.&lt;br /&gt;
&lt;br /&gt;
There are three important facts that are important to consider:&lt;br /&gt;
 * test&lt;/div&gt;</summary>
		<author><name>Jasonpsage</name></author>	</entry>

	</feed>