Test results for Broadwell and Skylake
I think I figured out what was happening the question I posted to Agner.   I submitted a reply, but it&#x27;s still in moderation.  For me, it finally explains a lot of lower than expected performance issues I&#x27;ve had with AVX&#x2F;AVX2.  In case others are interested, here it is.<p>-----<p>Agner wrote:
You are always limited by cache ways, read&#x2F;write buffers, faulty
prefetching, suboptimal reordering, etc.<p>Yes, although in my example I&#x27;m considering the much simpler case
where there are two reads but no writes, and all data is already in
L1. So although problematic in the real world, these shouldn&#x27;t be a
factor here. In fact, I see the same maximum speed if I read the same
4 vectors over and over rather than striding over all the data. I&#x27;ve
refined my example, though, and think I now understand what&#x27;s
happening. The problem isn&#x27;t a bank conflict, rather it&#x27;s a slowdown
due to unaligned access. I don&#x27;t think I&#x27;ve seen this discussed
before.<p>Contrary to my previous understanding, alignment makes a big
difference on the speed at which vectors are read from L1 to register.
If your data is 16B aligned rather than 32B aligned, a sequential read
from L1 is no faster with 256-bit YMM reads than it is with 128-bit
XMM reads. VMOVAPS and VMOVUPS have the same speed, but you cannot
achieve 2 32B loads per cycle if the underlying data is not 32B
aligned. If the data is 32B aligned, you still can&#x27;t quite sustain 64
B&#x2F;cycle of load with either, but you can get to about 54 B&#x2F;cycle with
both.<p>I put up new test code here: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;nkurz&#x2F;439ca1044e11181c1089" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;nkurz&#x2F;439ca1044e11181c1089</a><p>Results at L1 sizes are essentially the same on Haswell and Skylake.<p><pre><code>  Loading 4096 floats with 64 byte raw alignment
  Vector alignment 8:
  load_xmm : 19.79 bytes&#x2F;cycle
  load_xmm_nonsequential : 23.41 bytes&#x2F;cycle
  load_ymm : 28.64 bytes&#x2F;cycle
  load_ymm_nonsequential : 36.57 bytes&#x2F;cycle

  Vector alignment 16:
  load_xmm : 29.26 bytes&#x2F;cycle
  load_xmm_nonsequential : 29.05 bytes&#x2F;cycle
  load_ymm : 28.44 bytes&#x2F;cycle
  load_ymm_nonsequential : 36.90 bytes&#x2F;cycle

  Vector alignment 24:
  load_xmm : 19.79 bytes&#x2F;cycle
  load_xmm_nonsequential : 23.54 bytes&#x2F;cycle
  load_ymm : 28.64 bytes&#x2F;cycle
  load_ymm_nonsequential : 36.57 bytes&#x2F;cycle

  Vector alignment 32:
  load_xmm : 29.05 bytes&#x2F;cycle
  load_xmm_nonsequential : 28.85 bytes&#x2F;cycle
  load_ymm : 53.19 bytes&#x2F;cycle
  load_ymm_nonsequential : 52.51 bytes&#x2F;cycle
</code></pre>
What this says is that unless your loads are 32B aligned, regardless
of method you are limited to about 40B loaded per cycle. If you are
sequentially loading non-32B aligned data from L1, the speeds for 16B
loads and 32B loads are identical, and limited to less than 32B per
cycle. All alignments not shown were the same as 8B alignment.<p>Loading in a non-sequential order is about 20% faster for unaligned
XMM and unaligned YMM loads. It&#x27;s possible there is a faster order
than I have found so far. Aligned loads are the same speed
regardless of order. Maximum speed for aligned XMM loads is about 30
B&#x2F;cycle, and maximum speed for aligned YMM loads is about 54 B&#x2F;cycle.<p>At L2 sizes, the effect still exists, but is less extreme. XMM loads
are limited to 13-15 B&#x2F;cycle on both Haswell and Skylake. On Haswell,
YMM non-aligned loads are 18-20 B&#x2F;cycle, and YMM aligned loads are
24-26 B&#x2F;cycle. On Skylake, YMM aligned loads are slightly faster at
27 B&#x2F;cycle. Interestingly, sequential unaligned L2 loads on Skylake
are almost the same as aligned loads (26 B&#x2F;cycle), while non-sequential
loads are much slower (17 B&#x2F;cycle).<p>At L3 sizes, alignment is barely a factor. On Haswell, all loads are
limited to 11-13 B&#x2F;cycle. On Skylake, XMM loads are the same 11-13
B&#x2F;cycle, while YMM loads are slightly faster at 14-17 B&#x2F;cycle.<p>Coming from memory, XMM and YMM loads on Haswell are the same
regardless of alignment, at about 5 B&#x2F;cycle. On Skylake, XMM loads
are about 6.25 B&#x2F;cycle, and YMM loads are about 6.75 B&#x2F;cycle, with
little dependence on alignment. It&#x27;s possible that prefetch can
improve these speeds slightly.<p>Agner writes:
The write operations may sometimes use port 2 or 3 for address
calculation, where the maximum throughput requires that they use port
7.<p>I don&#x27;t recall if you mention it in your manuals, but I presume you
are aware that Port 7 on Haswell and Skylake is only capable of
&quot;simple&quot; address calculations? Thus sustaining 2 loads and a store is
only possible if the store address is [const + base] form rather than
[const + index*scale + base]. And as you point out, even if you do
this, it can still be difficult to force the processor to use only
Port 7 for the store address.