<div dir="ltr">Correction: The test I'm running is actually using V4<V4<Float>>.<div>Manually unrolling the loop makes adding V4<V4<Float>> as fast as adding SIMD float4x4.</div><div>Using the (un-unrolled) for loop will be about 4 times slower.</div><div>My question is still: Shouldn't the optimizer be able to handle that for loop / make my manual unrolling unnecessary?</div><div>/Jens</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 11, 2015 at 8:28 AM, Jens Persson <span dir="ltr"><<a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>I've been doing a lot of performance testing related to generic value types and SIMD lately, and I've built Swift from sources in order to get an idea of what's coming up optimizerwise. Things have improved and the optimizer is impressive overall. But I still see no improvement in the case exemplified below.</div><div><br></div><div>Manually unrolling the simple for loop will make it ~ 4 times faster (and exactly the same as when SIMD float4):<br></div><div><br></div><div>struct V4<T> {</div><div> var elements: (T, T, T, T)</div><div> /.../</div><div> subscript(index: Int) -> T { /.../ }</div><div> /.../</div><div> func addedTo(other: V4) -> V4 {</div><div> var r = V4()</div><div> // Manually unrolling makes code ~ 4 times faster:</div><div> // for i in 0 ..< 4 { r[i] = self[i] + other[i] }</div><div> r[0] = self[0] + other[0]</div><div> r[1] = self[1] + other[1]</div><div> r[2] = self[2] + other[2]</div><div> r[3] = self[3] + other[3]</div><div> return r</div><div> }</div><div> /.../</div><div>}</div><div><br></div><div>Shouldn't the optimizer be able to handle that for loop and make the manual unrolling unnecessary?</div><div><br></div><div>(compiled the test with -O -whole-module-optimizations, also tried -Ounchecked but with same results.)</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>/Jens</div><div><br></div></font></span></div>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">bitCycle AB | Smedjegatan 12 | 742 32 Östhammar | Sweden<br><a href="http://www.bitcycle.com/" target="_blank">http://www.bitcycle.com/</a><br>Phone: +46-73-753 24 62<br>E-mail: <a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.com</a><br><br></div>
</div>