<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Suggestion for Speed Improvement to Blender Functions</title>
		<link>http://www.allegro.cc/forums/view/588187</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 23 Oct 2006 22:41:40 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was browsing the Allegro 4.2.0 source to see how complex the blender functions are so I could determine how to effectively integrate them into the game engine I&#39;m working on, and I noticed that there are numerous divisions by constant powers of 2 on unsigned long integers littered throughout &quot;colblend.c&quot;. For example:</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/* _blender_dodge24:</span>
<span class="c"> *  24 bit dodge blender function.</span>
<span class="c"> */</span>
<span class="k1">unsigned</span> <span class="k1">long</span> _blender_dodge24<span class="k2">(</span><span class="k1">unsigned</span> <span class="k1">long</span> x, <span class="k1">unsigned</span> <span class="k1">long</span> y, <span class="k1">unsigned</span> <span class="k1">long</span> n<span class="k2">)</span>
<span class="k2">{</span>
   <span class="k1">return</span> BLEND<span class="k2">(</span><span class="n">24</span>, <a href="http://www.allegro.cc/manual/getr24" target="_blank"><span class="a">getr24</span></a><span class="k2">(</span>x<span class="k2">)</span> <span class="k3">+</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/getr24" target="_blank"><span class="a">getr24</span></a><span class="k2">(</span>y<span class="k2">)</span> <span class="k3">*</span> n <span class="k3">/</span> <span class="n">256</span><span class="k2">)</span>,
        <a href="http://www.allegro.cc/manual/getg24" target="_blank"><span class="a">getg24</span></a><span class="k2">(</span>x<span class="k2">)</span> <span class="k3">+</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/getg24" target="_blank"><span class="a">getg24</span></a><span class="k2">(</span>y<span class="k2">)</span> <span class="k3">*</span> n <span class="k3">/</span> <span class="n">256</span><span class="k2">)</span>,
        <a href="http://www.allegro.cc/manual/getb24" target="_blank"><span class="a">getb24</span></a><span class="k2">(</span>x<span class="k2">)</span> <span class="k3">+</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/getb24" target="_blank"><span class="a">getb24</span></a><span class="k2">(</span>y<span class="k2">)</span> <span class="k3">*</span> n <span class="k3">/</span> <span class="n">256</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Wouldn&#39;t it be faster and more efficient, especially considering the nature of these procedures, to change all the divisions by 8, 32, and 256 to right bit-shifts of 3, 5 and 8? I&#39;d do the change myself if I understood how changes to the Allegro source were actually proposed and made.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Mon, 23 Oct 2006 19:21:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;d do the change myself if I understood how changes to the Allegro source were actually proposed and made.
</p></div></div><p>I imagine this hasn&#39;t been done because it&#39;s trivial for the compiler to optimize constant, power-of-2 division itself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 23 Oct 2006 19:32:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Profile it and see what happens.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Mon, 23 Oct 2006 19:34:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I decided to perform a test on my system. I compiled Allegro 4.2.0 the way it always was, made the change from division to bit-shifting, then compiled another copy of the DLL. I quickly wrote up a pixel plotting program and tested it with both DLLs...</p><p>...There was no discernable difference in speed.</p><p>Then again, when <b>I</b> compile Allegro, the ALLEG42.DLL file ends up almost twice as big as the one that comes with the pre-compiled binaries, so I have to wonder if something&#39;s going on with that which would be affecting my tests. <b>shrugs</b></p><p>In either case, I guess it isn&#39;t the biggest of deals considering my results.</p><p>...though my pixel plotter managed to hit 4,000,000 additive-blended pixels a second, with 5 modulo, 5 rand(), one addition and one IF operation additionally being performed for each of those 4,000,000 pixels... that&#39;s a lot of processing going on... <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>When I took the blender functionality out, it only got up to 6,500,000 pixels a second. I guess the blender functions must work faster than I thought...</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Mon, 23 Oct 2006 21:56:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Wouldn&#39;t it be faster and more efficient, especially considering the nature of these procedures, to change all the divisions by 8, 32, and 256 to right bit-shifts of 3, 5 and 8?
</p></div></div><p>
Not really; it&#39;s one of those trivial optimizations that the compiler can do automatically.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 23 Oct 2006 22:38:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I was browsing the Allegro 4.2.0 source to see how complex the blender functions are so I could determine how to effectively integrate them into the game engine I&#39;m working on
</p></div></div><p>
If you didn&#39;t want to use AllegroGL / OpenLayer, I&#39;d look at the source for FBlend and that use parts of that (without the functions calls if possible).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Mon, 23 Oct 2006 22:41:40 +0000</pubDate>
	</item>
</rss>
