Dan M.
Dan M.

Reputation: 4052

How to use AVX2 in MASM/VS15?

problem: I write something like this (inside proc):

.CODE
myProc PROC
    vpmovsxbd ymm0, qword ptr [rdx] ; rdx is ptr to array of 8 bytes
    vcvtdqps ymm0, ymm0
    ret
myProc ENDP

and masm complains with invalid instruction operands for first and syntax error : ymm0 for second. I'm compiling for x64 using VS15 community edition.

Upvotes: 3

Views: 772

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490178

The first error looks like a problem in MASM--it simply refuses to accept that form of that instruction (even though the Intel docs say it exists).

The closest workaround I've been able to find is something like:

vmovdqu xmm0, xmmword ptr[rdx]
vpmovsxbd ymm0, xmm0

...but this is obviously kind of clumsy by comparison (since it destroys some xmm register, and obviously requires decoding an instruction instruction, etc.) On the other hand, it probably won't make much difference in speed as a rule (since the speed will usually be dominated by the memory read time in any case).

As a side note, the MS compiler seems to have roughly the same problem. A quick check using the _mm256_cvtepi8_epi32 intrinsic, which Intel says should generate a vpmovsxbd, shows that the Microsoft compiler generates it like the sequence above--a vmovdqu followed by a vpmovsxbd.

For the second one, you apparently wanted vcvtdq2ps, but left out the 2. Since the assembler didn't recognize that as an instruction, it got confused about what that line was supposed to be at all.

In case you actually care, it probably tried to parse it as a declaration like:

my_var dd ?

So, the first part (the vcvtdqps) seemed legitimate, but as a symbol, not an instruction. Then it found ymm0 instead of something like db, dw, dq (etc.) and realized there was an error, because a register name wasn't a legitimate thing to have there.

Upvotes: 5

Related Questions