Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

c++ - Looking for sse 128 bit shift operation for non-immediate shift value

The intrinsic _mm_slli_si128 will do a logical shift left of a 128 bit register, but is restricted to immediate shift values, and shifts by bytes not bits.

I can use an intrinsic like _mm_sll_epi64 or _mm_sll_epi32 to shift left a set of values within the __m128i register, but these don't carry the "overflow" bits.

For a shift by N bits imagine that I could do a something like:

  • _mm_sll_epi64
  • _mm_srr_epi64 (for the bits I want to carry: move them into the low order )
  • shuffle the srr result
  • or these together.

(but probably also have to include checks of N relative to 64).

Is there a better way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not your ideal solution, but if you want to rotate or shift an SSE register by a number of bits that is a multiple of 8, then the PSHUFB instruction (and the _mm_shuffle_epi8() intrinsic) can help. It takes a second SSE register as an input; each byte in the register holds a value that is used to index the bytes in the first input register.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...