suppose that xmm0 has two doubles, how do you swap the values so that I can move it to a scalar variable, I hope that it makes sense
ok, I think SHUFPD is the instruction to use, it's just a bit confusing http://qcd.phys.cmu.edu/QCDcluster/intel/vtune/reference/vc292.htm
the following seems to work but I don't understand why
pshufd xmm0, xmm0, 1110b
you can get some really messed-up numbers if the select operand is wrong
It's tricky indeed :cool:
Each 2-bit field in the order operand selects the contents of one doubleword location in the destination operand. For example, bits 0 and 1 of the order operand selects the contents of doubleword 0 of the destination operand. The encoding of bits 0 and 1 of the order operand determines which doubleword from the source operand will be copied to doubleword 0 of the destination operand.
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
MyOword OWORD 0DDDDDDDDCCCCCCCCBBBBBBBBAAAAAAAAh
Init
Cls
PrintLine "AAAAAAAAh is the least significant DWORD"
movups xmm0, MyOword
deb 4, "the original", x:xmm0
PrintLine "x_x_x_x_b values indicate which source DWORD should be moved"
PrintLine "3_2_1_0_b are the destination positions"
pshufd xmm1, xmm0, 0b
deb 4, "00000000b", x:xmm1
pshufd xmm1, xmm0, 00000001b
deb 4, "00000001b", x:xmm1
pshufd xmm1, xmm0, 01000001b
deb 4, "01000001b", x:xmm1
pshufd xmm1, xmm0, 01010101b
deb 4, "01010101b", x:xmm1
pshufd xmm1, xmm0, 10101010b
deb 4, "10101010b", x:xmm1
pshufd xmm1, xmm0, 00011011b
deb 4, "00011011b", x:xmm1
PrintLine "The last one moves element 3 (11b) to position 0, element 2 (10b) to position 1, etc"
Inkey
EndOfCode
AAAAAAAAh is the least significant DWORD
the original x:xmm0 DDDDDDDD CCCCCCCC BBBBBBBB AAAAAAAA
x_x_x_x_b values indicate which source DWORD should be moved
3_2_1_0_b are the destination positions
00000000b x:xmm1 AAAAAAAA AAAAAAAA AAAAAAAA AAAAAAAA
00000001b x:xmm1 AAAAAAAA AAAAAAAA AAAAAAAA BBBBBBBB
01000001b x:xmm1 BBBBBBBB AAAAAAAA AAAAAAAA BBBBBBBB
01010101b x:xmm1 BBBBBBBB BBBBBBBB BBBBBBBB BBBBBBBB
10101010b x:xmm1 CCCCCCCC CCCCCCCC CCCCCCCC CCCCCCCC
00011011b x:xmm1 AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
The last one moves element 3 (11b) to position 0, element 2 (10b) to position 1, etc
Attached an interactive version for playing around with the immediate values.
thank you for the example jj :)
My pleasure. With the new attachment above, you can play with the immediate argument (the string is editable with cursor left/right, delete and backspace; hex and decimal values are also accepted)
deleted
To swap two doubles, use 01001110b in the interactive program above. As Nidud writes, SHUFPD is the dedicated instruction, but PSHUFD works, too.
thank you all
I like the simplicity of shufpd xmm0,xmm0,1 so will use that instead