<div dir="ltr">On 25 August 2013 01:01, Ilya Yaroshenko <span dir="ltr"><<a href="mailto:ilyayaroshenko@gmail.com" target="_blank">ilyayaroshenko@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sunday, 18 August 2013 at 05:26:00 UTC, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
movups is not good. It'll be a lot faster (and portable) if you use movaps.<br>
<br>
Process looks something like:<br>
  * do the first few from a[0] until a's alignment interval as scalar<br>
  * load the left of b's aligned pair<br>
  * loop for each aligned vector in a<br>
    - load a[n..n+4] aligned<br>
    - load the right of b's pair<br>
    - combine left~right and shift left to match elements against a<br>
    - left = right<br>
  * perform stragglers as scalar<br>
<br>
Your benchmark is probably misleading too, because I suspect you are<br>
passing directly alloc-ed arrays into the function (which are 16 byte<br>
aligned).<br>
movups will be significantly slower if the pointers supplied are not 16<br>
byte aligned.<br>
Also, results vary significantly between chip manufacturers and revisions.<br>
</blockquote>
<br>
<br></div></div>
I have tried to write fast implementation with aligned loads:<br>
1. I have now idea how to shift (rotate) 32-bytes avx vector without XOP instruction set (XOP available only for AMD).<br>
2. I have tried to use one vmovaps and [one vmovups]/[two vinsertf128] with 16-bytes aligned arrays (previously iterates with a). It works slower then two vmovups (because loop tricks). Now I have 300 lines of slow dotProduct code =)<br>
</blockquote><div><br></div><div>This if course depends largely on your processor too. What processor/revision?</div><div>There is a massive difference between vendors and revisions.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

4. Condition for small arrays works good.<br></blockquote><div><br></div><div>Did you try putting this path selection logic in an outer function that the compiler can inline?</div><div><br></div><div>Where's your new code with the movaps solution?</div>
</div></div></div>