abrash-black-book/53-01.html
2013-12-30 12:21:49 +11:00

76 lines
6.1 KiB
HTML

<HTML>
<HEAD>
<META name=vsisbn content="1576101746">
<META name=vstitle content="Michael Abrash's Graphics Programming Black Book, Special Edition">
<META name=vsauthor content="Michael Abrash">
<META name=vspublisher content="The Coriolis Group">
<META name=vspubdate content="07/01/97">
<META name=vscategory content="Web and Software Development: Game Development,Web and Software Development: Graphics and Multimedia Development">
<TITLE>Michael Abrash's Graphics Programming Black Book Special Edition: Raw Speed and More</TITLE>
<!-- HEADER -->
<!-- Empty Reference Subhead -->
<!--ISBN=1576101746//-->
<!--TITLE=Michael Abrash's Graphics Programming Black Book Special Edition//-->
<!--AUTHOR=Michael Abrash//-->
<!--PUBLISHER=The Coriolis Group, Inc.//-->
<!--CHAPTER=53//-->
<!--PAGES=989-992//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//--></HEAD><BODY LINK=#0000FF ALINK=#000099 VLINK=#0000FF BGCOLOR=#FFFFFF>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="52-08.html">Previous</A></TD>
<TD><A HREF="index.html">Table of Contents</A></TD>
<TD><A HREF="53-02.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 53<BR>Raw Speed and More
</FONT></H2>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">The Naked Truth About Speed in 3-D Animation</FONT></H3>
<P>Years ago, this friend of mine&#151;let&#146;s call him Bert&#151;went to Hawaii with three other fellows to celebrate their graduation from high school. This was an unchaperoned trip, and they behaved pretty much as responsibly as you&#146;d expect four teenagers to behave, which is to say, not; there&#146;s a story about a rental car that, to this day, Bert can&#146;t bring himself to tell. They had a good time, though, save for one thing: no girls.
</P>
<P>By and by, they met a group of girls by the pool, but the boys couldn&#146;t get past the hi-howya-doin stage, so they retired to their hotel room to plot a better approach. This being the early &#146;70s, and them being slightly tipsy teenagers with raging hormones and the effective combined IQ of four eggplants, it took them no time at all to come up with a brilliant plan: streaking. The girls had mentioned their room number, so the boys piled into the elevator, pushed the button for the girls&#146; floor, shucked their clothes as fast as they could, and sprinted to the girls&#146; door. They knocked on the door and ran on down the hall. As the girls opened their door, Bert and his crew raced past, toward the elevator, laughing hysterically.</P>
<P>Bert was by far the fastest of them all. He whisked between the elevator doors just as they started to close; by the time his friends got there, it was too late, and the doors slid shut in their faces. As the elevator began to move, Bert could hear the frantic pounding of six fists thudding on the closed doors. As Bert stood among the clothes littering the elevator floor, the thought of his friends stuck in the hall, naked as jaybirds, was just too much, and he doubled over with helpless laughter, tears streaming down his face. The universe had blessed him with one of those exceedingly rare moments of perfect timing and execution.</P>
<P>The universe wasn&#146;t done with Bert quite yet, though. He was still contorted with laughter&#151;and still quite thoroughly undressed&#151;when the elevator doors opened again. On the lobby.</P>
<P>And with that, we come to this chapter&#146;s topics: raw speed and hidden surfaces.</P>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Raw Speed, Part 1: Assembly Language</FONT></H3>
<P>I would like to state, here and for the record, that I am not an assembly language fanatic. Frankly, I prefer programming in C; assembly language is hard work, and I can get a whole lot more done with fewer hassles in C. However, I <I>am</I> a performance fanatic, performance being defined as having programs be as nimble as possible in those areas where the user wants fast response. And, in the course of pursuing performance, there are times when a little assembly language goes a long way.</P>
<P>We&#146;re now four chapters into development of the X-Sharp 3-D animation package. In realtime animation, performance is <I>sine qua non</I> (Latin for &#147;Make it fast or find another line of work&#148;), so some judiciously applied assembly language is in order. In the previous chapter, we got up to a serviceable performance level by switching to fixed-point math, then implementing the fixed-point multiplication and division functions in assembly in order to take advantage of the 386&#146;s 32-bit capabilities. There&#146;s another area of the program that fairly cries out for assembly language: matrix math. The function to multiply a matrix by a vector (<B>XformVec()</B>) and the function to concatenate matrices (<B>ConcatXforms()</B>) both loop heavily around calls to <B>FixedMul();</B> a lot of calling and looping can be eliminated by converting these functions to pure assembly language.</P>
<P>Listing 53.1 is the module FIXED.ASM from this chapter&#146;s iteration of X-Sharp, with <B>XformVec()</B> and <B>ConcatXforms()</B> implemented in assembly language. The code is heavily optimized, to the extent of completely unrolling the loops via macros so that looping is eliminated altogether. FIXED.ASM is highly effective; the time taken for matrix math is now down to the point where it&#146;s a fairly minor component of execution time, representing less than ten percent of the total. It&#146;s time to turn our optimization sights elsewhere.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="52-08.html">Previous</A></TD>
<TD><A HREF="index.html">Table of Contents</A></TD>
<TD><A HREF="53-02.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<hr width="90%" size="1" noshade>
<div align="center">
<font face="Verdana,sans-serif" size="1">Graphics Programming Black Book &copy; 2001 Michael Abrash</font>
</div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- BEGIN SUB FOOTER -->
</BODY>
</HTML>
<!-- END FOOTER -->