<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>Mike Acton</title>
      <link>http://www.cellperformance.com/mike_acton/</link>
      <description>Thoughts on performance, the video game industry, and development.</description>
      <language>en</language>
      <copyright>Copyright 2008</copyright>
      <lastBuildDate>Sat, 07 Apr 2007 06:13:23 +0000</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/?v=3.2</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

            <item>
         <title>Utility: match</title>
         <description><![CDATA[<div class="sticky-note">
<b>Update!</b> If fixed up all the greater-than and less-than symbols in this entry. I didn't make much sense before. I always forget to change those up in the HTML.
</div>

I'm just sharing a little utility I use all the time called <b>match</b>. <br />
<br />

<pre class="code">
Usage: ./match [-h] &lt;source_file&gt; &lt;uniq_file&gt;

For each line in &lt;source_file&gt; print the index to the 
first matching line in &lt;uniq_file&gt;.

[-h] Print results in 32 bit hexidecimal (default is decimal)

Note: The max line width supported is 4095 characters.
Note: Maximum number of lines supported is (2^32)
</pre>

If I have a source file of data represented as text (as I often do because it's often easier for me to read binary dumps in a text editor than a special "hex editor"), I use match to create a table of indices to unique lines (often these correspond to 128 bits since that's the size of an SPU register).<br >
<br />
I commonly use it like so (given I have a file called "source_file")
<pre class="code">
sort source_file | uniq &gt; uniq_file
match source_file uniq_file
</pre>

Now I have a handy table of indices! <br />
<br />
Download: <a href="http://www.cellperformance.com/public/attachments/match.c">match.c</a><br />
]]></description>
         <link>http://www.cellperformance.com/mike_acton/2007/04/utility_match.html</link>
         <guid>http://www.cellperformance.com/mike_acton/2007/04/utility_match.html</guid>
         <category>Public</category>
         <pubDate>Sat, 07 Apr 2007 06:13:23 +0000</pubDate>
      </item>
            <item>
         <title>Open Source and Console Games</title>
         <description><![CDATA[<div class="sticky-note">
	On August 16, 2006 I participated in a <a href="http://www.digitalhollywood.com/%231BBlkSessions/BBWedFourWork.html">
	panel discussion on Open Source and media</a> as part of Digital Hollywood's <a href="http://www.digitalhollywood.com/BuildingBlocks.html">Building Blocks 2006</a>
	conference.<br />
	<br />
	Here is the description of the panel [from digitalhollywood.com]
	<div class="quote">
		The Open Source movement began during the dot.com rise with young companies
		developing great tools to deliver applications and services across
		multiple platforms. The consumer’s appetite for new content driven
		experiences has expanded to include ways to view, manage, and share
		content across devices. With the changing landscape around the home,
		Open Source promises to power a new generation of applications running
		over today’s high-speed networks and the systems used to create,
		manage, and distribute that content.<br /> 
		<br /> 
		Come join key leaders in the global electronics, online, and media 
		communities to discuss Open Source's definition, and learn how companies
		will create systems, infrastructure, and applications for the next 
		generation of the Consumer Entertainment Experience.
	</div><br />
	<br />
	For those of you who did not attend, I would like to take an
	opportunity to discuss here my personal opinions on these issues.
</div>]]></description>
         <link>http://www.cellperformance.com/mike_acton/2006/08/open_source_and_console_games.html</link>
         <guid>http://www.cellperformance.com/mike_acton/2006/08/open_source_and_console_games.html</guid>
         <category>Public</category>
         <pubDate>Wed, 09 Aug 2006 08:45:28 +0000</pubDate>
      </item>
            <item>
         <title>Understanding Strict Aliasing</title>
         <description><![CDATA[<div class="sticky-note"><strong>UPDATED! (25 Feb 08) Added note on bitfields. Corrected a typo (Thanks <span class="monospace-strong">Turly O'Connor</span>!)</strong></div>
<div class="sticky-note"><strong>UPDATED! (08 Aug 06) More Clarifications! 
Special thanks to <span class="monospace-strong">Nicolas Riesch</span>, <span class="monospace-strong">André de Leiradella</span> and <span class="monospace-strong">pinskia</span> for their comments and suggestions.
</strong></div>
<div class="sticky-note"><strong>UPDATED! (28 Dec 06) Minor fixes. 
Special thanks to <span class="monospace-strong">Kobi Cohen-Arazi</span> and <span class="monospace-strong">Chris Pickett</span>.
</strong></div>


<div class="subtitle">Aliasing</div>

One pointer is said to <i>alias</i> another pointer when both refer to the same location or object. In this example,
<pre class="code">
<span class="line-number">  0</span>uint32_t 
<span class="line-number">  1</span>swap_words( uint32_t arg )
<span class="line-number">  2</span>{
<span class="line-number">  3</span>  uint16_t* const sp = (uint16_t*)&amp;arg;
<span class="line-number">  4</span>  uint16_t        hi = sp[0];
<span class="line-number">  5</span>  uint16_t        lo = sp[1];
<span class="line-number">  6</span>  
<span class="line-number">  7</span>  sp[1] = hi;
<span class="line-number">  8</span>  sp[0] = lo;
<span class="line-number">  9</span>
<span class="line-number"> 10</span>  return (arg);
<span class="line-number"> 11</span>} 
</pre>
<div class="rule-of-thumb">
Using GCC 3.4.1 and above, the above code will generate <b>warning: dereferencing type-punned pointer will break strict-aliasing rules</b> on line 3.
</div>
The memory referred to by <b>sp</b> is an alias of <b>arg</b> because they refer to the same address in memory. In C99, it is <i>illegal</i> to create an alias of a different type than the original. This is often refered to as the <b>strict aliasing</b> rule. The rule is enabled by default in GCC at optimization levels at or above O2. Although the above example would compile, the results are undefined. 
More than likely, <strong>arg</strong> would be returned unchanged because a pointer to uint16_t cannot be an alias
to a pointer to uint32_t when applying the strict aliasing rule.<br />
<br />

<div class="rule-of-thumb">
Dereferencing a cast of a variable from one type of pointer to a different type is <em>usually</em> in violation of the strict aliasing rule.
</div>

However, having multiple representations of the same location in memory is often beneficial. Properly balancing the compiler's memory optimizations and the programmer's optimizations based on real-world context and data is a bit of a black art. It requires an understanding of the tradeoffs among what's permitted by the standard, what's the reality of compilers and the value of a particular transformation based on the architecture and the data. It's worth it in the end though when the results speak for themselves.<br />

<div class="sticky-note"> All of the examples in this article have been tested with various versions of GCC. Although you can expect most of the examples to generate similar results across the major compilers, programmers' expectations should always be validated for the compilers and compiler revisions required. </div>
<br /> 

Read on for details on the strict aliasing rule and some common pitfalls.<br />
]]></description>
         <link>http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html</link>
         <guid>http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html</guid>
         <category>Public</category>
         <pubDate>Thu, 01 Jun 2006 09:35:19 +0000</pubDate>
      </item>
            <item>
         <title>Demystifying The Restrict Keyword</title>
         <description><![CDATA[<div class="sticky-note"><strong>
UPDATED! More examples! More detailed explainations! </strong></div>
<div class="subtitle">Contract</div>

The restrict keyword can be considered an extension to the strict aliasing rule. It allows the programmer to declare that pointers which share the same type (or were otherwise validly created) <b>do not</b> alias eachother. By using restrict the programmer can declare that any loads and stores through the qualified pointer (or through another pointer copied either directly or indirectly from the restricted pointer) are the <b>only</b> loads and stores to the same address during the lifetime of the pointer. In other words, the pointer is not aliased by any pointers other than its own copies.<br />
<br />
<div class="rule-of-thumb">
Restrict is a “no data hazards will be generated” contract between the programmer and the compiler. The compiler relies on this information to make optimizations. If the data is, in fact, aliased, the results are undefined and a programmer should not expect the compiler to output a warning. The compiler assumes the programmer is not <i>lying</i>.</div>
<br />
<br />
<div class="contract-header">THE RESTRICT CONTRACT</div>
<div class="contract">
I, [insert your name], a PROFESSIONAL or AMATEUR [circle one] programmer recognize that there are
limits to what a compiler can do. I certify that, to the best of my knowledge, there are no magic
elves or monkeys in the compiler which through the forces of fairy dust can always make code faster.
I understand that there are some problems for which there is not enough information to solve. I 
hereby declare that given the opportunity to provide the compiler with sufficient information,
perhaps through some key word, I will gladly use said keyword and not bitch and moan about how 
"the compiler should be doing this for me."<br />
<br />
In this case, I promise that the pointer declared along with the restrict qualifier is not aliased.
I certify that writes through this pointer will not effect the values read through any other pointer
available in the same context which is also declared as restricted.<br />
<br />
* Your agreement to this contract is implied by use of the restrict keyword ;)
</div>
<br />
<br />
Read on for more information on the practical use and benefits to using the restrict keyword...]]></description>
         <link>http://www.cellperformance.com/mike_acton/2006/05/demystifying_the_restrict_keyw.html</link>
         <guid>http://www.cellperformance.com/mike_acton/2006/05/demystifying_the_restrict_keyw.html</guid>
         <category>Public</category>
         <pubDate>Mon, 29 May 2006 08:13:54 +0000</pubDate>
      </item>
            <item>
         <title>A Practical GCC Trick To Use During Optimization</title>
         <description><![CDATA[<div class="subtitle">Splitting a basic block (by force)</div>
<br />
<div class="quote"><b>Warning:</b> This is a trick to use during optimization. It is not documented nor gauranteed to work across multiple platforms or different revisions of the compiler. Many programmers will say that this non-portable code should not be used in production, but there is such a huge practical benefit to using it has to be mentioned.</div>
<br/>

One of the first things that the compiler's scheduler does is organize the code into blocks of code without branches, out-of-line function calls or other optimization barriers. These basic blocks will then be scheduled among eachother based on their dependencies. Toward the end of scheduling individual instructions will be scheduled within basic blocks. Finally, instructions may be moved across block boundaries.<br/>
<br/>
Inline assembly is most definately an optimization barrier and every block of inline assembly is treated as an independent basic block. This is why assembly should be inlined one instruction at a time - to give the compiler the maximum number of options for scheduling.<br/>
<br/>
<br/>
<b>Why do I mention this?</b> <br/>
<br/>
Well, it turns out that if you have an empty inline assembly statement you can rely on the side-effect of splitting the basic block witout actually adding any instructions.
<div class="code">
#define GCC_SPLIT_BLOCK __asm__ ("");
</div>

]]></description>
         <link>http://www.cellperformance.com/mike_acton/2006/04/a_practical_gcc_trick_to_use_d.html</link>
         <guid>http://www.cellperformance.com/mike_acton/2006/04/a_practical_gcc_trick_to_use_d.html</guid>
         <category>Public</category>
         <pubDate>Sat, 15 Apr 2006 09:10:13 +0000</pubDate>
      </item>
            <item>
         <title>Performance and Good Data Design</title>
         <description><![CDATA[<div class="subtitle">Why Is Data Design Important For Games?</div>
All game technology is simply a function to manipulate data. A game can be thought of as a very complicated DSP with controllers, source art and time as inputs and an audio-visual display as output. This is not a radical or revolutionary concept. It is however, widely forgotten or ignored in console game development. Development has changed dramatically over the years and the idea behind this article is to remind game programmers that the only thing we do now of any consequence is transform data. The only thing that really makes games unique is the types and amounts of data programmers must transform in a short, fixed period of time.<br />
<br />
Data access is the biggest problem in attaining maximum performance from a game console. This is necessarily true. Modern consoles are made up of deeply pipelined systems – The CPUs and coprocessors are designed for minimum cycle throughput, caches are designed for maximum throughput on sequential access, DSPs and GPUs are designed to maximize performance at the cost of instruction and data space – Any significant change in data access patterns will stall any or all of these pipelines. Of course there are required stalls in any pipelined system, however game systems themselves provide a pipeline from the content creators to the hardware and the best of those maximize the width and speed of those pipelines by minimizing non-required stalls along the way.<br />
<br />
<div class="subtitle">Good code follows good data, not the other way around.</div>
Fundamentally game systems can not be built for performance independent of the data. Good code follows good data, not the other way around. It is a common misperception that the products of programmers are programs – code. The truth is that the only people who care about code are programmers and we do not ultimately serve ourselves – The product of programmers is a service – console game programmers provide a mechanism for the content creators to put the content on a particular piece of hardware. Both the content creators and the game players want more and more and if we do not do everything we can within the limits of time and budget simply because the code doesn’t meet our expectations of how code should be designed or because a particular piece of hardware is more difficult to work with than we had hoped, then we are doing a disservice to our ultimate customers.<br />
<br />
<div class="rule-of-thumb">
In order to effectively design and optimize a system for a console game, both the data and how it is used must be known.  This is the most obvious, most crucial and most neglected principle in software architecture.
</div>
<br />
It used to be that programmer's did everything - the design, the art, the testing, not to mention writing the code. Things have changed.  There are professional designers, level builders, graphic artists, technical artists, art directors, creative directors, and a QA staff large enough to require their own building.<br />
<br />
In today's console game development world, programmers are responsible for only one thing: the data traffic through the console. detailed knowledge of what that content actually is, when it is transferred and how it is constructed it is very difficult to shape that data for best-fit performance. <br />
<br />
What follows are some simple rules of thumb that programmers can follow to create a solid pipeline from the content creators to the screen and speakers.<br />
<br />]]></description>
         <link>http://www.cellperformance.com/mike_acton/2006/04/basic_principles_of_good_data.html</link>
         <guid>http://www.cellperformance.com/mike_acton/2006/04/basic_principles_of_good_data.html</guid>
         <category>Public</category>
         <pubDate>Mon, 03 Apr 2006 08:47:20 +0000</pubDate>
      </item>
      
   </channel>
</rss>
