News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

XMMWORD initializers?

Started by redskull, January 13, 2011, 07:26:51 PM

Previous topic - Next topic

redskull

Does anyone know the appropriate syntax for getting MASM to accept initializing values for an XMMWORD?  It just seems to ignore any specified values you give it, and initializes everything to zero.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Works with Masm 8, 9 and JWasm:
include \masm32\include\masm32rt.inc
.xmm
.code
MyXmm OWORD 12345678
start:
movups xmm1, MyXmm
inkey "Done"
exit
end start

redskull

It can't accept four distinct floating point values?  E.G.


foo   XMMWORD  3.14, 2.73, 6.674, 1.234
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

It's actually a lot more complicated...
Masm does not initialise the XMMWORD (but it does initialise the OWORD)
JWasm initialises both.

include \masm32\MasmBasic\MasmBasic.inc
.data
MyX XMMWORD 123456789.0123456789
MyO OWORD 1234567890123456789
foo XMMWORD 3.14, 2.73, 6.674, 1.234
fooR8 REAL8 3.14, 6.28

Init
movdqu xmm0, MyX
movups xmm1, MyO
movups xmm2, foo
movlps xmm3, fooR8
movlps xmm4, fooR8+8
Print Str$("MyX/x0\t%9f\n", xmm0)
Print Str$("Xmm1\t%9f\n", xmm1)
Print Str$("foo/x2\t%9f\n", xmm2)
Print Str$("Xmm3\t%9f\n", f:xmm3)
Inkey Str$("Xmm4\t%9f\n", f:xmm4)
Exit
end start


Output:
MyX/x0  0.0
Xmm1    1.23456789e+18
foo/x2  0.0
Xmm3    3.14000000
Xmm4    6.28000000

clive

Guess you'd need to use

foo REAL4 3.14, 2.73, 6.674, 1.234

and override it.

So JJ how do you print a packed scalar in MasmBasic?
It could be a random act of randomness. Those happen a lot as well.

jj2007

Quote from: clive on January 13, 2011, 08:08:02 PM
So JJ how to you print a packed scalar in MasmBasic?

Good question. It's not yet foreseen, but if there is an urgent need for it...

fld fooR8
fld fooR8+8
Print Str$("Packed: %9f and ", ST(0)), Str$(ST(1)), CrLf$
fstp st
fstp st


Output:
Packed: 6.28000000 and 3.140000

redskull

Quote from: clive on January 13, 2011, 08:08:02 PM
Guess you'd need to use

foo REAL4 3.14, 2.73, 6.674, 1.234

and override it.


Is an XMMWORD the same byte ordering as four consequtive REAL4s?  I'm too rusty on the format to remember big vs little endian.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

dedndave

or...
foo     LABEL   OWORD
        REAL4 3.14, 2.73, 6.674, 1.234

clive

        include \masm32\MasmBasic\MasmBasic.inc
        .data
foo     REAL4   3.14, 2.73, 6.674, 1.234
bar     REAL4   ?, ?, ?, ?
Init
        movups xmm2, foo

        movups bar, xmm2
        fld     bar[0]
        print Str$("Xmm2:0\t%9f\n", ST(0))
        fstp    st
        fld     bar[4]
        print Str$("Xmm2:1\t%9f\n", ST(0))
        fstp    st
        fld     bar[8]
        print Str$("Xmm2:2\t%9f\n", ST(0))
        fstp    st
        fld     bar[12]
        print Str$("Xmm2:3\t%9f\n", ST(0))
        fstp    st
        Inkey
Exit
        end     start


Xmm2:0  3.14000010
Xmm2:1  2.73000002
Xmm2:2  6.67399979
Xmm2:3  1.23399997
It could be a random act of randomness. Those happen a lot as well.

jj2007

Quote from: redskull on January 13, 2011, 08:29:20 PM
Is an XMMWORD the same byte ordering as four consequtive REAL4s?  I'm too rusty on the format to remember big vs little endian.

I am not sure if it's a valid question. SSE2 can handle REAL4 and REAL8 but not REAL16.
If you use...
MyO OWORD 11111111
MyQ QWORD 11111111, 22222222
...
movups xmm1, MyO
movups xmm5, oword ptr MyQ
... you get this output. Looks little Endian somehow :wink
MyO/x1  11111111.0
MyQ/x5  11111111.0

clive

Quote from: redskull on January 13, 2011, 08:29:20 PM
Is an XMMWORD the same byte ordering as four consequtive REAL4s?  I'm too rusty on the format to remember big vs little endian.

Haven't thought about it, always assumed they all fit together in the right fashion. Not like I'm jamming a MC68882 into the mix.

       include \masm32\MasmBasic\MasmBasic.inc
       .data
foo     REAL4   3.14, 2.73, 6.674, 1.234
bar     REAL4   ?, ?, ?, ?
Init
       movups  xmm2, foo
       addps   xmm2,xmm2

       movups  bar, xmm2
       fld     bar[0]
       print Str$("Xmm2:0\t%9f\n", ST(0))
       fstp    st
       fld     bar[4]
       print Str$("Xmm2:1\t%9f\n", ST(0))
       fstp    st
       fld     bar[8]
       print Str$("Xmm2:2\t%9f\n", ST(0))
       fstp    st
       fld     bar[12]
       print Str$("Xmm2:3\t%9f\n", ST(0))
       fstp    st
       Inkey
Exit
       end     start


Xmm2:0  6.28000021
Xmm2:1  5.46000004
Xmm2:2  13.3479996
Xmm2:3  2.46799994


Could try a multiply with different constants for giggles.
It could be a random act of randomness. Those happen a lot as well.

clive

        include \masm32\MasmBasic\MasmBasic.inc
        .data
foo     REAL4   3.14, 2.73, 6.674, 1.234
oof     REAL4   1.00, 2.00, 3.00,  4.00

bar     REAL4   ?, ?, ?, ?

Init
        movups  xmm2, foo
        movups  xmm5, oof
        mulps   xmm2,xmm5

        movups  bar, xmm2
        fld     bar[0]
        print Str$("Xmm2:0\t%9f\n", ST(0))
        fstp    st
        fld     bar[4]
        print Str$("Xmm2:1\t%9f\n", ST(0))
        fstp    st
        fld     bar[8]
        print Str$("Xmm2:2\t%9f\n", ST(0))
        fstp    st
        fld     bar[12]
        print Str$("Xmm2:3\t%9f\n", ST(0))
        fstp    st
        Inkey   "Press any key", 10, 13
Exit
        end     start


Xmm2:0  3.14000010
Xmm2:1  5.46000004
Xmm2:2  20.0219994
Xmm2:3  4.93599987
Press any key
It could be a random act of randomness. Those happen a lot as well.

clive

Quote from: jj2007
It's not yet foreseen, but if there is an urgent need for it...

About the second thing I thought of, most any case of vector math you'd likely want to see all the values. Not that I'm trying to make work for you.
It could be a random act of randomness. Those happen a lot as well.

jj2007

Even with the current version it is not that difficult:

.data
MyP4 dd 12, 34, 56, 78
xxl0 dd ?
xxl1 dd ?
xxl2 dd ?
xxl3 dd ?
.code
movups xmm1, MyP4
movups xxl0, xmm1
PrintLine Str$("Packed 4: %i", xxl0), ", ", Str$(xxl1), ", ", Str$(xxl2), ", ", Str$(xxl3)


Note that JWasm requires two oword ptr qualifiers:
movups xmm1, oword ptr MyP4
movups oword ptr xxl0, xmm1


Output:
Packed 4: 12, 34, 56, 78