Skip to content

Specialise constant-mask swizzle for lsx and lasx - #1422

Merged
serge-sans-paille merged 1 commit into
xtensor-stack:masterfrom
domibel:lsx-swizzle-const-mask
Oct 2, 2026
Merged

serge-sans-paille merged 1 commit into
xtensor-stack:masterfrom
domibel:lsx-swizzle-const-mask

Conversation

@domibel

@domibel domibel commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

On lsx the only new case is the identity mask, which returns the batch unchanged. Every other mask takes the runtime path as before.

On lasx there are four. An identity mask again returns the batch unchanged. The other three exist because xvshuf.b only shuffles within each 128 bit half of the register, so permuting bytes across the whole register is the expensive case and worth avoiding. When no element reads from the other half, a single xvshuf.b does the whole job, with each index taken modulo the half width so that it addresses its own half. When every element reads from the low half, that half is first broadcast to both halves with xvpermi.q 0x00, after which the same single xvshuf.b applies; a mask reading only the high half is the same with 0x11. Any other mask takes the runtime path as before.

Those three cases apply only where the element type is one byte. Wider element types get the identity check and nothing else.

Comment thread include/xsimd/arch/xsimd_lasx.hpp
On lsx the only new case is the identity mask, which returns the batch
unchanged. Every other mask takes the runtime path as before.

On lasx there are four cases. An identity mask again returns the batch
unchanged. The other three exist because xvshuf.b only shuffles within
each 128 bit lane, so permuting bytes across the whole register is the
expensive case and worth avoiding.

When no element crosses a lane, a single xvshuf.b does the whole job,
once each index is reduced to an offset within its own lane.

When every element reads from a single lane, that lane is first broadcast
to both lanes with xvpermi.q, after which the same single xvshuf.b applies.

Any other mask takes the runtime path as before.

Those three cases apply only where the element type is one byte. Wider
element types get the identity check and nothing else.
@domibel
domibel force-pushed the lsx-swizzle-const-mask branch from c68530d to 440d2f5 Compare October 2, 2026 18:22
@serge-sans-paille
serge-sans-paille merged commit 67ade81 into xtensor-stack:master Oct 2, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants