Re: [PATCH] x86: clean up unnecessarily wide TEST insns

From: Linus Torvalds
Date: Fri Mar 06 2015 - 17:55:01 EST


On Fri, Mar 6, 2015 at 2:24 PM, Andi Kleen <andi@xxxxxxxxxxxxxx> wrote:
>
> It also results in expensive LCP stalls.

BS, Andi.

That's only true for prefixed operations - ie 16-bit data or address overrides.

There are no stalls from using 8-bit instruction forms.

Now, changing from 64-bit or 32-bit 'test' instructions to 8-bit ones
*could* cause problems if it ends up having forwarding issues, so that
instead of just forwarding the result, you end up having to wait for
it to be stable in the L1 cache (or possibly the register file). The
forwarding from the store buffer is simplest and most reliable if the
read is done at the exact same address and the exact same size as the
write that gets forwarded.

But that's true only if

(a) the write was very recent and is still in the write queue. I'm
not sure that's the case here anyway.

(b) on at least most intel microarchitectures, you have to test a
different byte than the lowest one (so forwarding a 64-bit write to a
8-bit read ends up working fine, as long as the 8-bit read is of the
low 8 bits of the written data).

a very similar issue *might* show up for registers too, not just
memory writes, if you use 'testb' with a high-byte register (where
instead of forwarding the value from the original producer it needs to
go through the register file and then shifted). But it's mainly a
problem for store buffers.

But afaik, the way Denys changed the test instructions, neither of the
above issues should be true.

The real problem for store buffer forwarding tends to be "write 8
bits, read 32 bits". That can be really surprisingly expensive,
because the read ends up having to wait until the write has hit the
cacheline, and we might talk tens of cycles of latency here. But
"write 32 bits, read the low 8 bits" *should* be fast on pretty much
all x86 chips, afaik.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/