0

I'm trying to convert an inherited 32-bit Windows app to 64-bit. I'm hung up on this bit which was embedded in the 32-bit C file:

__asm {
     pxor mm0,mm0
     punpcklbw mm0, dword ptr[x]
     ...   }

'x' is a structure in C.

As required by MASM 64-bit, I refactored the ASM into an external file like this:

mmx_speedup_asm PROC x:PTR DWORD
         pxor mm0,mm0
         punpcklbw mm0, x
         ...
mmx_spedup_asm ENDP

On compile, I get this error:

invalid instruction operands

on the 'punpcklbw' line

This seems like it might be a mismatch between 64-bit/32-bit but I can't tell exactly why or how to fix it.

  • 2
    Is it worth preserving as assembly or is there a C equivalent that works just as well? – tadman Jan 04 '21 at 20:46
  • There is a C equivalent that I'm trying now. Documentation indicates that the ASM version gave a 10-15% speed increase but this code is 15+ years old so things may have changed. – Randy Jay Yarger Jan 04 '21 at 20:49
  • 1
    That's what I'm thinking. They keep adding macros and such to cover use cases like this, and in many cases you can just write C code that emits exactly the same instructions if you read the documentation closely enough. The other good news is that in 15 years computers have gotten a lot faster so maybe this isn't as big a deal. – tadman Jan 04 '21 at 20:51
  • Try by changing the `mm0` register to `xmm0` – Kamil.S Jan 04 '21 at 21:08
  • If your hardware supports it, processing 256 at a time might be an even bigger win. Have you checked out the [intrinsics](https://learn.microsoft.com/en-us/cpp/intrinsics/x64-amd64-intrinsics-list?view=msvc-160)? Almost certainly a better deal than inline asm. – David Wohlferd Jan 05 '21 at 04:37

0 Answers0