Optimizing for SIMD Integer Applications 4
4-7
Signed Unpack
Signed numbers should be sign-extended when unpacking the values.
This is similar to the zero-extend shown above except that the
psrad
instruction (packed shift right arithmetic) is used to effectively sign
extend the values. Example 4-3 assumes the source is a packed-word
(16-bit) data type.
Example 4-2 Unsigned Unpack Instructions
; Input:
; MM0 source value
; MM7 0 a local variable can be used
; instead of the register MM7 if
; desired.
; Output:
; MM0 two zero-extended 32-bit
; doublewords from two low-end
; words
; MM1 two zero-extended 32-bit
; doublewords from two high-end
; words
movq MM1, MM0 ; copy source
punpcklwd MM0, MM7 ; unpack the 2 low-end words
; into two 32-bit doubleword
punpckhwd MM1, MM7 ; unpack the 2 high-end words
; into two 32-bit doublewords