Anycorn
Anycorn

Reputation: 51505

SSE, interleave low and high words

Is there a single SSE instruction to interleave high and low words of two registers into another register? Eg:

r[63-0]   = a[64-127]
r[64-127] = b[63-0]

Upvotes: 1

Views: 753

Answers (1)

Stephen Canon
Stephen Canon

Reputation: 106247

No, because there are no SSE shuffles that have two sources and a distinct destination. However, you can do it if r is the same as a, with shufpd. If you need to preserve the value of a:

movapd r, a
shufpd r, b, 1

On recent µarches, the movapd is free and handled in rename[*], so this effectively is a “single instruction", from the point of view of the execution core.

If AVX is available, you can use vshufpd.

[*] It’s possible to saturate this capability of rename, in which case the extra reg-reg moves will behave like normal port 0|1|5 operations—fortunately, real world code almost always has some bubbles on one of those ports, so the move tends to still be “free”.

Upvotes: 7

Related Questions