2

In an existing Visual Studio 2015 C++ 32-bit Windows project I have a function for converting a video frame from NV12 to YUY2, which is basically just shuffling bytes around. Here it is:

void ConvertNV12toYUY2(int nInputHeight,
                       LPBITMAPINFOHEADER lpbiOutput,
                       void * _src, void * _dst,
                       bool bInterlaced)
{
    const unsigned char* py8 = (const unsigned char*)_src;
    unsigned char* pyuy2_8 = (unsigned char*)_dst;
    int pitch = lpbiOutput->biWidth;
    int width = pitch;
    int nOutputHeight = abs((int)lpbiOutput->biHeight);
    const unsigned char *puv8 = py8 + (nInputHeight * pitch);

    int w = (width+7) >> 3;
    const __m64 *py = (const __m64 *)py8;
    __m64 *pyuy2 = (__m64 *)pyuy2_8;

    for (int y = 0; y < nOutputHeight; y++)
    {
        const __m64 *puv;

        if (bInterlaced)
            puv = (const __m64 *)(puv8+(((y/2)&~1)+(y&1))*pitch);
        else
            puv = (const __m64 *)(puv8+(y/2)*pitch);
        for (int x = 0; x < w; x++)
        {
            __m64 r0 = py[x];       // yyyy
            __m64 r1 = puv[x];      // uvuv
            __m64 r2 = r0;          // yyyy
            r0 = _m_punpcklbw(r0, r1);  // yuyv
            r2 = _m_punpckhbw(r2, r1);  // yuyv
            pyuy2[x*2] = r0;
            pyuy2[x*2+1] = r2;
        }
        py += pitch/sizeof(__m64);
        pyuy2 += (width*2)/sizeof(__m64);
    }
    _m_empty();
}

If has always worked OK in the 32 bit project, but now I'm porting it to 64 bit, and it fails to compile due to these identifiers not found:

_m_punpcklbw
_m_punpckhbw
_m_empty

I think this is something to do with mmx intrinsics not being supported by the Microsoft 64 bit compiler, but to be honest I know very little about mmx.

Are there equivalent replacement functions that would do the same in 64 bit ?

appleton
  • 168
  • 1
  • 11
  • why do you use MMX in this era? x86_64 already implies SSE2 – phuclv Jun 27 '17 at 13:51
  • 1
    MMX isn't supported on x86-64; it is not a limitation of Microsoft's compiler. Fortunately, SSE2 is essentially a drop-in replacement for MMX, *plus* you get to perform operations that are twice as wide (for twice as much bandwidth). See the bottom of [this answer](https://stackoverflow.com/questions/43568840/warning-c4799-function-has-no-emms-instruction/43571015#43571015) for an example of how to convert between the two. If you have any *specific* problems finding an SSE2 replacement, ask a new question about it. – Cody Gray - on strike Jun 27 '17 at 14:04

0 Answers0