<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3445357166715628606</id><updated>2011-09-09T04:49:40.494-07:00</updated><category term='iPhone'/><category term='vfp'/><title type='text'>Sketchbook</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aleiby.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://aleiby.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Aaron Leiby</name><uri>http://www.blogger.com/profile/15283392831954712873</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3445357166715628606.post-7787324783787345782</id><published>2008-12-05T20:07:00.000-08:00</published><updated>2008-12-06T16:22:08.193-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='iPhone'/><category scheme='http://www.blogger.com/atom/ns#' term='vfp'/><title type='text'>iPhone VFP for n00bs</title><content type='html'>&lt;blockquote&gt;&lt;/blockquote&gt;I thought I'd jot down a couple notes outlining my experience so far with writing vector assembly for the iPhone.&lt;br /&gt;&lt;br /&gt;First of all, a couple of useful links...&lt;br /&gt;&lt;br /&gt;About the only examples on the web to date are in the vfpmathlibrary: &lt;a href="http://code.google.com/p/vfpmathlibrary"&gt;http://code.google.com/p/vfpmathlibrary&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The website is currently down, but the ARM GCC Inline Assembly Cookbook has lots of great info: &lt;a href="http://www.ethernut.de/en/documents/arm-inline-asm.html"&gt;http://www.ethernut.de/en/documents/arm-inline-asm.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You'll also likely want the quick reference card for the ARM/VFP instruction set: &lt;a href="http://www.voti.nl/hvu/arm/ARMquickref.pdf"&gt;http://www.voti.nl/hvu/arm/ARMquickref.pdf&lt;/a&gt;&lt;div&gt;(I unfortunately couldn't find a link on arm's site)&lt;br /&gt;&lt;br /&gt;If your app is floating point heavy (which is probably why you want to use the vfp in the first place), then you'll likely already have disabled compiling for thumb.  If not, you might want to open up your project settings and uncheck that box.  Otherwise, you'll have to follow the vfpmathlibrary and wrap your assembly in their macros switch to arm mode and back.&lt;br /&gt;&lt;br /&gt;Now, go read the inline assembly cookbook linked above if you're not already familiar with how inline assembly works in gcc.  The basic format is:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;void test(float * src, float * dst)&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;asm volatile (&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;        "fldmias %0!, {s8-s11} \n\t" // operations&lt;br /&gt;"fstmias %1!, {s8-s11} \n\t"&lt;br /&gt;: "=r" (src), "=r" (dst)       // output operands&lt;br /&gt;: "0" (src), "1" (dst)         // input operands&lt;br /&gt;: "memory"                     // clobbers&lt;br /&gt;);&lt;/span&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;A couple of notes here:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;If you're compiling your code as C instead of C++, then you'll need to use __asm__.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;'volatile' tells the compiler not to optimize your code.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The load and store commands don't obey the vector width (more on that below), so you have to specify the range explicitly.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The first 8 fp registers (or rather the first two banks - s0-s7 and d0-d3) are treated as scalars, so they also ignore the width.  This is useful for loading a single value into and using to multiply an entire vector by.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;VFP has support for both single and double precision.  This is what the last letter of each instruction specifies (e.g. fmuls vs fmuld), and the first letter for registers (s0-s31 vs d0-d15).&lt;br /&gt;&lt;/li&gt;&lt;li&gt;fldmias = floating [point], load multiple, increment after, single [precision].  In the example above, it loads the values at src[0], src[1], src[2] &amp;amp; src[3] into registers s8, s9, s10 &amp;amp; s11 respectively.  Alternatively, you can use decrement before (fldmdbs).  Some good details on increment ascending vs decrement before, etc. can be found &lt;a href="http://www.sesp.cse.clrc.ac.uk/html/SoftwareTools/vtune/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/xscinstruct_hh/Address_Load_and_Store_Multiple_Overview.htm"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The exclamation mark (!) is required to actually increment or decrement the pointer.  If you want to leave it alone, leave the exclamation point off.  Technically speaking, it's used to set the 'w' bit.  When you modify it this way, you need to make sure it's both an input and output operand.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Output operands are write-only.  Input operands are read-only.  Normally, you'd specify it using just "r", but when you want it to be both read and write, you use the output operand index instead.  Refer back to the inline assembler cookbook for more details.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Instructions should be separated by new lines and tabs as illustrated above so when it's linked into the rest it'll read nicely for debugging.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;The vfp can support widths up to 4 floats.  This is how many floats are processed per vfp operation.  To set this use the following code:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;"fmrx    r0, fpscr           \n\t"&lt;br /&gt;"bic     r0, r0, #0x00370000 \n\t"&lt;br /&gt;"orr     r0, r0, #0x00030000 \n\t"  // the 3 in here is the width&lt;br /&gt;"fmxr    fpscr, r0           \n\t"&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;(or just use common_macros.h from vfpmathlibrary)&lt;br /&gt;&lt;br /&gt;The value is always width-1, so for width 4 you use the value 3, and width 1 you use 0.&lt;br /&gt;&lt;br /&gt;If you change the width, you should set it back to one when you're done.  Changing the width is expensive since it needs to wait for existing operations to finish.  This means vfp is mostly useful for doing large batches of work instead of wrapping up all your vector operations individually.  My guess is this is why Apple hasn't released a nice math library already.&lt;br /&gt;&lt;br /&gt;For inline assembly, you can only use local labels (0-9).  When you branch, you use f or b to jump to the next (forward) or previous (back) specified label.  Here's a simple example.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;void loop()&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;const int count = 10;&lt;br /&gt;&lt;br /&gt;asm volatile (&lt;br /&gt;&lt;br /&gt;// Setup loop using count.&lt;br /&gt;"mov r0, %0       \n\t"&lt;br /&gt;"1:               \n\t"&lt;br /&gt;&lt;br /&gt;// Stuff we want to do count times.&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;// Decrement count and loop till zero.&lt;br /&gt;"subs r0, r0, #1  \n\t"&lt;br /&gt;"bne 1b           \n\t"&lt;br /&gt;&lt;br /&gt;: // no output in this example&lt;br /&gt;: "r" (count)&lt;br /&gt;: "r0", "cc"&lt;br /&gt;);&lt;/span&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;                          &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the clobbers, we need to specify that we changed "r0" (which we're using to count down), and "cc" because we set the condition flag in the "subs" instruction - the last 's' does that.  Refer back to the quick reference card for all the neat things you can do if you're not familiar with arm assembly.  Here, we're subtracting 1 (use the '#' prefix for constants) from r0 and storing it back in r0, but also setting the condition, so we can use it for branching in the next instruction.&lt;br /&gt;&lt;br /&gt;One thing that's easy to forget early on is that modifying registers (i.e your output operands) modifies the variables.  It sounds stupid when put like that, but when you're doing your fldmias %0! to load in a bunch of data, it's updating your 'src' pointer along the way, so when you're done, 'src' will point off the end of your array.&lt;br /&gt;&lt;br /&gt;Finally, you'll likely want to wrap your assembly in #if !TARGET_IPHONE_SIMULATOR / #endif.  Or rather, you'll want something like:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;#if TARGET_IPHONE_SIMULATOR&lt;/span&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;C/C++ only versions here&lt;/span&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;#else&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;inline asm version here&lt;/span&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;#endif&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Otherwise, you won't be able to compile for the simulator (which uses your Intel Mac's x86 processor, not ARM asm).&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3445357166715628606-7787324783787345782?l=aleiby.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aleiby.blogspot.com/feeds/7787324783787345782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3445357166715628606&amp;postID=7787324783787345782' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/7787324783787345782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/7787324783787345782'/><link rel='alternate' type='text/html' href='http://aleiby.blogspot.com/2008/12/iphone-vfp-for-n00bs.html' title='iPhone VFP for n00bs'/><author><name>Aaron Leiby</name><uri>http://www.blogger.com/profile/15283392831954712873</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3445357166715628606.post-3999883124425731254</id><published>2007-05-12T18:05:00.000-07:00</published><updated>2007-05-12T18:52:37.499-07:00</updated><title type='text'>Silverlight ftw...</title><content type='html'>&lt;iframe marginwidth="0" src="http://seattle.servegame.org/BouncingBall.html" frameborder="0" width="200" scrolling="no" height="200"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Source: &lt;/span&gt;&lt;a href="http://seattle.servegame.org/BouncingBall.py"&gt;&lt;span style="font-family:arial;"&gt;BouncingBall.py&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;XAML: &lt;/span&gt;&lt;a href="http://seattle.servegame.org/BouncingBall.xaml"&gt;&lt;span style="font-family:arial;"&gt;BouncingBall.xaml&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;(You can install Silverlight &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/silverlight/bb419317.aspx"&gt;&lt;span style="font-family:arial;"&gt;here&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;.)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3445357166715628606-3999883124425731254?l=aleiby.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aleiby.blogspot.com/feeds/3999883124425731254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3445357166715628606&amp;postID=3999883124425731254' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/3999883124425731254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/3999883124425731254'/><link rel='alternate' type='text/html' href='http://aleiby.blogspot.com/2007/05/silverlight.html' title='Silverlight ftw...'/><author><name>Aaron Leiby</name><uri>http://www.blogger.com/profile/15283392831954712873</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3445357166715628606.post-8735512377185359719</id><published>2007-05-11T17:25:00.000-07:00</published><updated>2007-05-11T17:26:56.069-07:00</updated><title type='text'>Update *this*...</title><content type='html'>&lt;span style="font-family:arial;"&gt;&lt;applet codebase="http://seattle.servegame.org/" height="200" archive="sketch_070511a.jar" width="200" code="sketch_070511a" mayscript="true"&gt;&lt;param name="_cx" value="5292"&gt;&lt;param name="_cy" value="5292"&gt;&lt;br /&gt;To view this content, you need to install Java from &lt;a href="http://java.com"&gt;java.com&lt;/a&gt;&lt;br /&gt;&lt;/applet&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3445357166715628606-8735512377185359719?l=aleiby.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aleiby.blogspot.com/feeds/8735512377185359719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3445357166715628606&amp;postID=8735512377185359719' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/8735512377185359719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/8735512377185359719'/><link rel='alternate' type='text/html' href='http://aleiby.blogspot.com/2007/05/update-this.html' title='Update *this*...'/><author><name>Aaron Leiby</name><uri>http://www.blogger.com/profile/15283392831954712873</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3445357166715628606.post-2600060647685220368</id><published>2007-05-07T21:53:00.000-07:00</published><updated>2007-05-07T21:54:28.950-07:00</updated><title type='text'>Chickens all the way down...</title><content type='html'>&lt;span style="font-family:arial;"&gt;&lt;applet codebase="http://seattle.servegame.org/" height="200" archive="sketch_070506a.jar" width="200" code="sketch_070506a" mayscript="true"&gt;&lt;param name="_cx" value="5292"&gt;&lt;param name="_cy" value="5292"&gt;&lt;br /&gt;To view this content, you need to install Java from &lt;a href="http://java.com"&gt;java.com&lt;/a&gt;&lt;br /&gt;&lt;/applet&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3445357166715628606-2600060647685220368?l=aleiby.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aleiby.blogspot.com/feeds/2600060647685220368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3445357166715628606&amp;postID=2600060647685220368' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/2600060647685220368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/2600060647685220368'/><link rel='alternate' type='text/html' href='http://aleiby.blogspot.com/2007/05/chickens-all-way-down.html' title='Chickens all the way down...'/><author><name>Aaron Leiby</name><uri>http://www.blogger.com/profile/15283392831954712873</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3445357166715628606.post-5914248835258828376</id><published>2007-04-25T23:13:00.000-07:00</published><updated>2007-04-25T23:45:59.910-07:00</updated><title type='text'>Testing...</title><content type='html'>&lt;span style="font-family:arial;"&gt;&lt;applet codebase="http://seattle.servegame.org/" height="200" archive="sketch_070424a.jar" width="200" code="sketch_070424a" mayscript="true"&gt;&lt;param name="_cx" value="5292"&gt;&lt;param name="_cy" value="5292"&gt;&lt;br /&gt;To view this content, you need to install Java from &lt;a href="http://java.com"&gt;java.com&lt;/a&gt;&lt;br /&gt;&lt;/applet&gt;&lt;br /&gt;Source code: &lt;/span&gt;&lt;a href="http://seattle.servegame.org/sketch_070424a.pde"&gt;&lt;span style="font-family:arial;"&gt;sketch_070424a&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3445357166715628606-5914248835258828376?l=aleiby.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aleiby.blogspot.com/feeds/5914248835258828376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3445357166715628606&amp;postID=5914248835258828376' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/5914248835258828376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3445357166715628606/posts/default/5914248835258828376'/><link rel='alternate' type='text/html' href='http://aleiby.blogspot.com/2007/04/testing.html' title='Testing...'/><author><name>Aaron Leiby</name><uri>http://www.blogger.com/profile/15283392831954712873</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
