<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 19 Dec 2015, at 06:19, David Turnbull &lt;<a href="mailto:dturnbull@gmail.com" class="">dturnbull@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Fri, Dec 18, 2015 at 4:34 PM, Janosch Hildebrand <span dir="ltr" class="">&lt;<a href="mailto:jnosh@jnosh.com" target="_blank" class="">jnosh@jnosh.com</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class="">If you only care about having a simple cross-platform library, doing a simple implementation by yourself is fine. Also Swift (well, LLVM) is also pretty good at auto-vectorization so you get decent results for custom vector/matrix types.<br class=""><div class=""><div class=""><br class=""></div><div class="">However OpenGL-related code is usually pretty performance sensitive and the math parts doubly so, so I'd recommend wrapping some appropriate libraries instead of writing your own...</div></div></div></blockquote><div class=""><br class=""></div><div class="">Multiplying two mat4x4 is one of the most complex and common operations. Doing 2 million of these...<br class=""></div><div class=""><br class=""></div><div class="">C++: 1.3 seconds</div><div class="">Swift: 1.9 seconds</div><div class=""><br class=""></div><div class="">The C++ code is glm using packed SIMD operations. Swift is just plain whatever LLVM gave me with -O.</div><div class=""><br class=""></div><div class="">While implementing the multiplication I darn near fell out of my chair when the compiler said, "Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions." I had to break it in half twice before the compiler stopped complaining about the math being too hard.<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>:-) It's not the math that's bothering the compiler but type inference which can get pretty nasty if you have many operations in a single statement.</div><div>The compiler emits that error to help you reduce compile times.</div><div><br class=""></div><div>Depending on the code, specifying the resulting type can also be of help (eg var foo<b class="">: T</b>&nbsp;= &lt;lots of math here&gt;) but breaking up the code into smaller pieces will always work.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">-<span style="font-size:13px" class="">david (</span><a href="https://github.com/AE9RB/SwiftGL" target="_blank" style="font-size:13px" class="">https://github.com/AE9RB/SwiftGL</a><span style="font-size:13px" class="">)</span></div></div></div></div></div></blockquote><br class=""></div><div class="">
<div class="">- Janosch</div>
</div>
<br class=""></body></html>