LooPer
LooPer

Reputation: 1479

MMX sign extension

Does anyone know how to make sign extension from 16 bits words to 32 bits words using MMX registers? I would like to get two 32 bits sign extended words from two 16 bits words stored in a MMX register. No SSE4 instructions allowed.

Regards

Upvotes: 2

Views: 374

Answers (1)

Paul R
Paul R

Reputation: 213160

You can just do a left shift (PSLLD) followed by an arithmetic right shift (PSRAD), e.g. using intrinsics:

v = _mm_srai_pi32(_mm_slli_pi32(v, 16), 16);

(This is assuming that you already have the 16 bit values in the low halves of each 32 bit word.)

Upvotes: 5

Related Questions