예제 #1
0
template<class _mm> void TimgFilterNoiseMplayer::Tprocess::lineNoise_simd(uint8_t *dst,const uint8_t *src, int8_t *noise, int len, int shift)
{
    if (_mm::align && (intptr_t(src)&15 || intptr_t(dst)&15)) {
        lineNoise_simd<typename _mm::T64>(dst,src,noise,len,shift);
        return;
    }
    int mmx_len=len&(~(_mm::size-1));
    noise+=shift;

    typename _mm::__m mm7;
    pcmpeqb(mm7,mm7);
    psllw(mm7,15);
    packsswb(mm7,mm7);
    for (int x=-mmx_len; x<0; x+=_mm::size) {
        //".balign 16            \n\t"
        typename _mm::__m mm0,mm1;
        movq   (mm0,src+mmx_len+x);
        movdqu (mm1,noise+mmx_len+x); //SSE3
        pxor   (mm0,mm7);
        paddsb (mm0,mm1);
        pxor   (mm0,mm7);
        _mm::movntq(dst+mmx_len+x,mm0);
    }

    if (mmx_len!=len) {
        lineNoise_C(dst+mmx_len,src+mmx_len,noise+mmx_len,len-mmx_len,0);
    }
}
예제 #2
0
파일: AO.C 프로젝트: AoJ/SecondReality
int	xorrec(int x1,int y1,int x2,int y2)
{
	int	x,y;
	for(y=y1+1;y<y2;y++)
	{
		pxor(x1,y);
		pxor(x2,y);
	}
 	for(x=x1;x<=x2;x++)
	{
		pxor(x,y1);
		pxor(x,y2);
	}
}
void GSDrawScanlineCodeGenerator::TestDestAlpha()
{
    if(!m_sel.date || m_sel.fpsm != 0 && m_sel.fpsm != 2)
    {
        return;
    }

    // test |= ((fd [<< 16]) ^ m_env.datm).sra32(31);

    movdqa(xmm1, xmm2);

    if(m_sel.datm)
    {
        if(m_sel.fpsm == 2)
        {
            pxor(xmm0, xmm0);
            psrld(xmm1, 15);
            pcmpeqd(xmm1, xmm0);
        }
        else
        {
            pcmpeqd(xmm0, xmm0);
            pxor(xmm1, xmm0);
            psrad(xmm1, 31);
        }
    }
    else
    {
        if(m_sel.fpsm == 2)
        {
            pslld(xmm1, 16);
        }

        psrad(xmm1, 31);
    }

    por(xmm7, xmm1);

    alltrue();
}
void GSDrawScanlineCodeGenerator::clamp16(const Xmm& a, const Xmm& temp)
{
    packuswb(a, a);

    if(m_cpu.has(util::Cpu::tSSE41))
    {
        pmovzxbw(a, a);
    }
    else
    {
        pxor(temp, temp);
        punpcklbw(a, temp);
    }
}
예제 #5
0
파일: AO.C 프로젝트: AoJ/SecondReality
int	area(int x1,int y1,int x2,int y2,int c)
{
	int	x,y;
	if(c==-1)
	{
		for(y=y1;y<=y2;y++) for(x=x1;x<=x2;x++)
		{
			pxor(x,y);
		}
	}
	else
	{
		for(y=y1;y<=y2;y++) for(x=x1;x<=x2;x++)
		{
			pset(x,y,c);
		}
	}
}
예제 #6
0
void GSDrawScanlineCodeGenerator::clamp16(const Xmm& a, const Xmm& temp)
{
#if _M_SSE >= 0x500

    vpackuswb(a, a);
    vpmovzxbw(a, a);

#elif _M_SSE >= 0x401

    packuswb(a, a);
    pmovzxbw(a, a);

#else

    packuswb(a, a);
    pxor(temp, temp);
    punpcklbw(a, temp);

#endif
}
template <class _mm, int src_aligned, int dst_aligned> void TffdshowConverters2::convert_simd_Y416(
    const uint8_t* srcY,
    const uint8_t* srcCb,
    const uint8_t* srcCr,
    uint8_t* dst,
    int dx,
    int dy,
    stride_t stride_src,
    stride_t stride_dst)
{
    int xCount = dx * 2 / _mm::size;
    if (xCount <= 0)
        return;

    _mm::__m _mm0,_mm1,_mm2,_mm3,_mm4,_mm5;
    _mm::__m ffff;
    pxor(ffff,ffff);
    pcmpeqb(ffff,ffff);
    for (int y = 0 ; y < dy ; y++) {
        const uint8_t *Y = srcY + y * stride_src;
        uint8_t *dst1 = dst + y * stride_dst;
        const uint8_t *Cb = srcCb + y * stride_src;
        const uint8_t *Cr = srcCr + y * stride_src;
        int x = xCount;
        do {
            if (src_aligned) {
                movVqa(_mm1, Y);
                movVqa(_mm2, Cb);
                movVqa(_mm4, Cr);
            } else {
                movVqu(_mm1, Y);
                movVqu(_mm2, Cb);
                movVqu(_mm4, Cr);
            }
            Y  += _mm::size;
            Cb += _mm::size;
            Cr += _mm::size;
            _mm5 = _mm1;
            punpcklwd(_mm1, _mm2);
            punpckhwd(_mm5, _mm2);
            _mm2 = ffff;
            _mm3 = ffff;
            punpcklwd(_mm2, _mm4);
            punpckhwd(_mm3, _mm4);
            _mm4 = _mm2;
            punpckldq(_mm2, _mm1);
            punpckhdq(_mm4, _mm1);
            _mm0 = _mm3;
            punpckldq(_mm0, _mm5);
            punpckhdq(_mm3, _mm5);
            psllw(_mm2, 6);
            psllw(_mm4, 6);
            psllw(_mm0, 6);
            psllw(_mm3, 6);
            if (dst_aligned) {
                _mm::movntVq(dst1,                 _mm2);
                _mm::movntVq(dst1 + _mm::size,     _mm4);
                _mm::movntVq(dst1 + _mm::size * 2, _mm0);
                _mm::movntVq(dst1 + _mm::size * 3, _mm3);
            } else {
                movVqu(dst1,                 _mm2);
                movVqu(dst1 + _mm::size,     _mm4);
                movVqu(dst1 + _mm::size * 2, _mm0);
                movVqu(dst1 + _mm::size * 3, _mm3);
            }
            dst1 += _mm::size * 4;
        } while(--x);
    }

    if (xCount * (int)_mm::size < dx * 2 && dx * 2 > _mm::size) {
        // handle non-mod 8 resolution.
        int dxDone = dx * 2 - _mm::size;
        srcY  += dxDone;
        srcCb += dxDone;
        srcCr += dxDone;
        dst   += dxDone * 4;
        convert_simd_Y416<_mm, 0, 0>(srcY, srcCb, srcCr, dst, _mm::size/2, dy, stride_src, stride_dst);
    }

    _mm::empty();
}
template <class _mm, int src_aligned, int dst_aligned> void TffdshowConverters2::convert_NV12toYV12(
    const uint8_t* srcY,
    const uint8_t* srcCbCr,
    uint8_t* dstY,
    uint8_t* dstCb,
    uint8_t* dstCr,
    int dx,
    int dy,
    stride_t stride_Y,
    stride_t stride_CbCr,
    stride_t stride_dstY,
    stride_t stride_dstCbCr)
{
    int xCount = dx / (_mm::size*2);
    if (xCount <= 0)
        return;

    _mm::__m _mm0,_mm1,_mm2,_mm3,_mm_00ff;

    // fill with 0xff
    pxor(_mm_00ff,_mm_00ff);
    pcmpeqb(_mm_00ff,_mm_00ff);
    psllw(_mm_00ff, 8);
    psrlw(_mm_00ff, 8);

    for (int y = 0 ; y < dy ; y++) {
        const uint8_t *src = srcY + y * stride_Y;
        uint8_t *dst = dstY + y * stride_dstY;
        int x = xCount;
        do {
            if (src_aligned) {
                movVqa(_mm0, src);
                movVqa(_mm1, src + _mm::size);
            } else {
                movVqu(_mm0, src);
                movVqu(_mm1, src + _mm::size);
            }
            src += _mm::size * 2;
            if (dst_aligned) {
                _mm::movntVq(dst, _mm0);
                _mm::movntVq(dst + _mm::size, _mm1);
            } else {
                movVqu(dst, _mm0);
                movVqu(dst + _mm::size, _mm1);
            }
            dst += _mm::size * 2;
        } while(--x);
    }
    int dyCbCr = dy/2;
    for (int y = 0 ; y < dyCbCr ; y++) {
        const uint8_t *srcCbCrLn = srcCbCr + y * stride_CbCr;
        uint8_t *dstCbLn = dstCb + y * stride_dstCbCr;
        uint8_t *dstCrLn = dstCr + y * stride_dstCbCr;
        int x = xCount;
        do {
            if (src_aligned) {
                movVqa(_mm0, srcCbCrLn);
                movVqa(_mm1, srcCbCrLn + _mm::size);
            } else {
                movVqu(_mm0, srcCbCrLn);
                movVqu(_mm1, srcCbCrLn + _mm::size);
            }
            _mm2 = _mm0;
            _mm3 = _mm1;
            srcCbCrLn += _mm::size * 2;
            pand(_mm0, _mm_00ff);
            pand(_mm1, _mm_00ff);
            psrlw(_mm2,8);
            psrlw(_mm3,8);
            packuswb(_mm0, _mm1);
            packuswb(_mm2, _mm3);

            if (dst_aligned) {
                _mm::movntVq(dstCbLn, _mm0);
                _mm::movntVq(dstCrLn, _mm2);
            } else {
                movVqu(dstCbLn, _mm0);
                movVqu(dstCrLn, _mm2);
            }
            dstCbLn += _mm::size;
            dstCrLn += _mm::size;
        } while(--x);
    }

    if (xCount * (int)_mm::size * 2 < dx && dx > _mm::size * 2) {
        int dxDone = dx - _mm::size * 2;
        srcY  += dxDone;
        srcCbCr += dxDone;
        dstY    += dxDone;
        dstCb   += dxDone/2;
        dstCr   += dxDone/2;
        convert_NV12toYV12<_mm, 0, 0>(srcY, srcCbCr, dstY, dstCb, dstCr, _mm::size * 2, dy, stride_Y, stride_CbCr, stride_dstY, stride_dstCbCr);
    }

    _mm::empty();
}
template <class _mm, int src_aligned, int dst_aligned> void TffdshowConverters2::convert_YV12toNV12(
    const uint8_t* srcY,
    const uint8_t* srcCb,
    const uint8_t* srcCr,
    uint8_t* dstY,
    uint8_t* dstCbCr,
    int dx,
    int dy,
    stride_t stride_Y,
    stride_t stride_CbCr,
    stride_t stride_dstY,
    stride_t stride_dstCbCr)
{
    int xCount = dx / (_mm::size*2);
    if (xCount <= 0)
        return;

    _mm::__m _mm0,_mm1,_mm2,_mm3;
    _mm::__m zero;
    pxor(zero,zero);
    for (int y = 0 ; y < dy ; y++) {
        const uint8_t *src = srcY + y * stride_Y;
        uint8_t *dst = dstY + y * stride_dstY;
        int x = xCount;
        do {
            if (src_aligned) {
                movVqa(_mm0, src);
                movVqa(_mm1, src + _mm::size);
            } else {
                movVqu(_mm0, src);
                movVqu(_mm1, src + _mm::size);
            }
            src += _mm::size * 2;
            if (dst_aligned) {
                _mm::movntVq(dst, _mm0);
                _mm::movntVq(dst + _mm::size, _mm1);
            } else {
                movVqu(dst, _mm0);
                movVqu(dst + _mm::size, _mm1);
            }
            dst += _mm::size * 2;
        } while(--x);
    }
    int dyCbCr = dy/2;
    for (int y = 0 ; y < dyCbCr ; y++) {
        const uint8_t *Cb = srcCb + y * stride_CbCr;
        const uint8_t *Cr = srcCr + y * stride_CbCr;
        uint8_t *dst = dstCbCr + y * stride_dstCbCr;
        int x = xCount;
        do {
            if (src_aligned) {
                movVqa(_mm0, Cb);
                movVqa(_mm1, Cr);
            } else {
                movVqu(_mm0, Cb);
                movVqu(_mm1, Cr);
            }
            _mm2 = _mm0;
            _mm3 = _mm1;
            Cb += _mm::size;
            Cr += _mm::size;
            punpcklbw(_mm0, _mm1);
            punpckhbw(_mm2, _mm3);

            if (dst_aligned) {
                _mm::movntVq(dst, _mm0);
                _mm::movntVq(dst + _mm::size, _mm2);
            } else {
                movVqu(dst, _mm0);
                movVqu(dst + _mm::size, _mm2);
            }
            dst += _mm::size * 2;
        } while(--x);
    }

    if (xCount * (int)_mm::size * 2 < dx && dx > _mm::size * 2) {
        int dxDone = dx - _mm::size * 2;
        srcY  += dxDone;
        srcCb += dxDone/2;
        srcCr += dxDone/2;
        dstY    += dxDone;
        dstCbCr += dxDone;
        convert_YV12toNV12<_mm, 0, 0>(srcY, srcCb, srcCr, dstY, dstCbCr, _mm::size * 2, dy, stride_Y, stride_CbCr, stride_dstY, stride_dstCbCr);
    }

    _mm::empty();
}
template <class _mm, int src_aligned, int dst_aligned, uint64_t incsp> void TffdshowConverters2::convert_simd(
    const uint8_t* srcY,
    const uint8_t* srcCb,
    const uint8_t* srcCr,
    uint8_t* dstY,
    uint8_t* dstCbCr,
    int dx,
    int dy,
    stride_t stride_Y,
    stride_t stride_CbCr,
    stride_t stride_dstY,
    stride_t stride_dstCbCr)
{
    int xCount = dx * 2 / _mm::size;
    if (xCount <= 0)
        return;

    _mm::__m _mm0,_mm1,_mm2,_mm3;
    _mm::__m zero;
    pxor(zero,zero);
    for (int y = 0 ; y < dy ; y++) {
        const uint8_t *src = srcY + y * stride_Y;
        uint8_t *dst = dstY + y * stride_dstY;
        int x = xCount;
        do {
            if (incsp == FF_CSP_420P10 || incsp == FF_CSP_422P10) {
                if (src_aligned)
                    movVqa(_mm0, src);
                else
                    movVqu(_mm0, src);
                psllw(_mm0, 6);
                src += _mm::size;
            } else if (incsp == FF_CSP_420P || incsp == FF_CSP_NV12) {
                movHalf(_mm1, src);
                _mm0 = zero;
                punpcklbw(_mm0, _mm1);
                src += _mm::size/2;
            }
            if (dst_aligned)
                _mm::movntVq(dst, _mm0);
            else
                movVqu(dst, _mm0);
            dst += _mm::size;
        } while(--x);
    }
    int dyCbCr = (incsp == FF_CSP_422P10) ? dy : dy/2;
    for (int y = 0 ; y < dyCbCr ; y++) {
        const uint8_t *Cb = srcCb + y * stride_CbCr;
        const uint8_t *Cr = srcCr + y * stride_CbCr;
        uint8_t *dst = dstCbCr + y * stride_dstCbCr;
        int x = xCount;
        do {
            if (incsp == FF_CSP_420P10 || incsp == FF_CSP_422P10) {
                movHalf(_mm0, Cb);
                movHalf(_mm1, Cr);
                Cb += _mm::size/2;
                Cr += _mm::size/2;
                punpcklwd(_mm0, _mm1);
                psllw(_mm0, 6);
            } else if (incsp == FF_CSP_420P) {
                movQuarter(_mm2, Cb);
                movQuarter(_mm3, Cr);
                _mm0 = zero;
                _mm1 = zero;
                Cb += _mm::size/4;
                Cr += _mm::size/4;
                punpcklbw(_mm0, _mm2);
                punpcklbw(_mm1, _mm3);
                punpcklwd(_mm0, _mm1);
            } else if (incsp == FF_CSP_NV12) {
                movHalf(_mm1, Cb);
                Cb += _mm::size/2;
                _mm0 = zero;
                punpcklbw(_mm0, _mm1);
            }

            if (dst_aligned)
                _mm::movntVq(dst, _mm0);
            else
                movVqu(dst, _mm0);
            dst += _mm::size;
        } while(--x);
    }

    if (xCount * (int)_mm::size < dx * 2 && dx > _mm::size/2) {
        int dxDone = dx - _mm::size / 2;
        switch (incsp) {
        case FF_CSP_420P:
            srcY  += dxDone;
            srcCb += dxDone/2;
            srcCr += dxDone/2;
            break;
        case FF_CSP_NV12:
            srcY  += dxDone;
            srcCb += dxDone;
            break;
        case FF_CSP_420P10:
        case FF_CSP_422P10:
            srcY  += dxDone * 2;
            srcCb += dxDone;
            srcCr += dxDone;
            break;
        }
        dstY    += dxDone * 2;
        dstCbCr += dxDone * 2;
        convert_simd<_mm, 0, 0, incsp>(srcY, srcCb, srcCr, dstY, dstCbCr, _mm::size/2, dy, stride_Y, stride_CbCr, stride_dstY, stride_dstCbCr);
    }

    _mm::empty();
}
예제 #11
0
void GPUDrawScanlineCodeGenerator::SampleTexture()
{
	if(!m_sel.tme)
	{
		return;
	}

	if(m_sel.tlu)
	{
		mov(edx, ptr[&m_local.gd->clut]);
	}

	// xmm2 = s
	// xmm3 = t
	// xmm7 = test
	// xmm0, xmm4, xmm5, xmm6 = free
	// xmm1 = used

	if(m_sel.ltf)
	{
		// GSVector4i u = s.sub16(GSVector4i(0x00200020)); // - 0.125f
		// GSVector4i v = t.sub16(GSVector4i(0x00200020)); // - 0.125f

		mov(eax, 0x00200020);
		movd(xmm0, eax);
		pshufd(xmm0, xmm0, _MM_SHUFFLE(0, 0, 0, 0));

		psubw(xmm2, xmm0);
		psubw(xmm3, xmm0);

		// GSVector4i uf = (u & GSVector4i::x00ff()) << 7;
		// GSVector4i vf = (v & GSVector4i::x00ff()) << 7;

		movdqa(xmm0, xmm2);
		psllw(xmm0, 8);
		psrlw(xmm0, 1);
		movdqa(ptr[&m_local.temp.uf], xmm0);

		if(!m_sel.sprite)
		{
			movdqa(xmm0, xmm3);
			psllw(xmm0, 8);
			psrlw(xmm0, 1);
			movdqa(ptr[&m_local.temp.vf], xmm0);
		}
	}

	// GSVector4i u0 = s.srl16(8);
	// GSVector4i v0 = t.srl16(8);

	psrlw(xmm2, 8);
	psrlw(xmm3, 8);

	// xmm2 = u
	// xmm3 = v
	// xmm7 = test
	// xmm0, xmm4, xmm5, xmm6 = free
	// xmm1 = used

	if(m_sel.ltf)
	{
		// GSVector4i u1 = u0.add16(GSVector4i::x0001());
		// GSVector4i v1 = v0.add16(GSVector4i::x0001());

		movdqa(xmm4, xmm2);
		movdqa(xmm5, xmm3);

		pcmpeqd(xmm0, xmm0);
		psrlw(xmm0, 15);
		paddw(xmm4, xmm0);
		paddw(xmm5, xmm0);

		if(m_sel.twin)
		{
			// u0 = (u0 & m_local.twin[0].u).add16(m_local.twin[1].u);
			// v0 = (v0 & m_local.twin[0].v).add16(m_local.twin[1].v);
			// u1 = (u1 & m_local.twin[0].u).add16(m_local.twin[1].u);
			// v1 = (v1 & m_local.twin[0].v).add16(m_local.twin[1].v);

			movdqa(xmm0, ptr[&m_local.twin[0].u]);
			movdqa(xmm6, ptr[&m_local.twin[1].u]);

			pand(xmm2, xmm0);
			paddw(xmm2, xmm6);
			pand(xmm4, xmm0);
			paddw(xmm4, xmm6);

			movdqa(xmm0, ptr[&m_local.twin[0].v]);
			movdqa(xmm6, ptr[&m_local.twin[1].v]);

			pand(xmm3, xmm0);
			paddw(xmm3, xmm6);
			pand(xmm5, xmm0);
			paddw(xmm5, xmm6);
		}
		else
		{
			// u0 = u0.min_i16(m_local.twin[2].u);
			// v0 = v0.min_i16(m_local.twin[2].v);
			// u1 = u1.min_i16(m_local.twin[2].u);
			// v1 = v1.min_i16(m_local.twin[2].v);

			// TODO: if(!sprite) clamp16 else:

			movdqa(xmm0, ptr[&m_local.twin[2].u]);
			movdqa(xmm6, ptr[&m_local.twin[2].v]);

			pminsw(xmm2, xmm0);
			pminsw(xmm3, xmm6);
			pminsw(xmm4, xmm0);
			pminsw(xmm5, xmm6);
		}

		// xmm2 = u0
		// xmm3 = v0
		// xmm4 = u1
		// xmm5 = v1
		// xmm7 = test
		// xmm0, xmm6 = free
		// xmm1 = used

		// GSVector4i addr00 = v0.sll16(8) | u0;
		// GSVector4i addr01 = v0.sll16(8) | u1;
		// GSVector4i addr10 = v1.sll16(8) | u0;
		// GSVector4i addr11 = v1.sll16(8) | u1;

		psllw(xmm3, 8);
		movdqa(xmm0, xmm3);
		por(xmm3, xmm2);
		por(xmm0, xmm4);

		psllw(xmm5, 8);
		movdqa(xmm6, xmm5);
		por(xmm5, xmm2);
		por(xmm6, xmm4);

		// xmm3 = addr00
		// xmm0 = addr01
		// xmm5 = addr10
		// xmm6 = addr11
		// xmm7 = test
		// xmm2, xmm4 = free
		// xmm1 = used

		ReadTexel(xmm2, xmm3);
		ReadTexel(xmm4, xmm0);
		ReadTexel(xmm3, xmm5);
		ReadTexel(xmm5, xmm6);

		// xmm2 = c00
		// xmm4 = c01
		// xmm3 = c10
		// xmm5 = c11
		// xmm7 = test
		// xmm0, xmm6 = free
		// xmm1 = used

		// spill (TODO)

		movdqa(ptr[&m_local.temp.fd], xmm1);
		movdqa(ptr[&m_local.temp.test], xmm7);

		// xmm2 = c00
		// xmm4 = c01
		// xmm3 = c10
		// xmm5 = c11
		// xmm0, xmm1, xmm6, xmm7 = free

		movdqa(xmm1, xmm2);
		psllw(xmm1, 11);
		psrlw(xmm1, 8);

		movdqa(xmm0, xmm4);
		psllw(xmm0, 11);
		psrlw(xmm0, 8);

		lerp16<0>(xmm0, xmm1, ptr[&m_local.temp.uf]);

		movdqa(xmm6, xmm2);
		psllw(xmm6, 6);
		psrlw(xmm6, 11);
		psllw(xmm6, 3);

		movdqa(xmm1, xmm4);
		psllw(xmm1, 6);
		psrlw(xmm1, 11);
		psllw(xmm1, 3);

		lerp16<0>(xmm1, xmm6, ptr[&m_local.temp.uf]);

		movdqa(xmm7, xmm2);
		psllw(xmm7, 1);
		psrlw(xmm7, 11);
		psllw(xmm7, 3);

		movdqa(xmm6, xmm4);
		psllw(xmm6, 1);
		psrlw(xmm6, 11);
		psllw(xmm6, 3);

		lerp16<0>(xmm6, xmm7, ptr[&m_local.temp.uf]);

		psraw(xmm2, 15);
		psrlw(xmm2, 8);
		psraw(xmm4, 15);
		psrlw(xmm4, 8);

		lerp16<0>(xmm4, xmm2, ptr[&m_local.temp.uf]);

		// xmm0 = r00
		// xmm1 = g00
		// xmm6 = b00
		// xmm4 = a00
		// xmm3 = c10
		// xmm5 = c11
		// xmm2, xmm7 = free

		movdqa(xmm7, xmm3);
		psllw(xmm7, 11);
		psrlw(xmm7, 8);

		movdqa(xmm2, xmm5);
		psllw(xmm2, 11);
		psrlw(xmm2, 8);

		lerp16<0>(xmm2, xmm7, ptr[&m_local.temp.uf]);
		lerp16<0>(xmm2, xmm0, ptr[&m_local.temp.vf]);

		// xmm2 = r
		// xmm1 = g00
		// xmm6 = b00
		// xmm4 = a00
		// xmm3 = c10
		// xmm5 = c11
		// xmm0, xmm7 = free

		movdqa(xmm7, xmm3);
		psllw(xmm7, 6);
		psrlw(xmm7, 11);
		psllw(xmm7, 3);

		movdqa(xmm0, xmm5);
		psllw(xmm0, 6);
		psrlw(xmm0, 11);
		psllw(xmm0, 3);

		lerp16<0>(xmm0, xmm7, ptr[&m_local.temp.uf]);
		lerp16<0>(xmm0, xmm1, ptr[&m_local.temp.vf]);

		// xmm2 = r
		// xmm0 = g
		// xmm6 = b00
		// xmm4 = a00
		// xmm3 = c10
		// xmm5 = c11
		// xmm1, xmm7 = free

		movdqa(xmm7, xmm3);
		psllw(xmm7, 1);
		psrlw(xmm7, 11);
		psllw(xmm7, 3);

		movdqa(xmm1, xmm5);
		psllw(xmm1, 1);
		psrlw(xmm1, 11);
		psllw(xmm1, 3);

		lerp16<0>(xmm1, xmm7, ptr[&m_local.temp.uf]);
		lerp16<0>(xmm1, xmm6, ptr[&m_local.temp.vf]);

		// xmm2 = r
		// xmm0 = g
		// xmm1 = b
		// xmm4 = a00
		// xmm3 = c10
		// xmm5 = c11
		// xmm6, xmm7 = free

		psraw(xmm3, 15);
		psrlw(xmm3, 8);
		psraw(xmm5, 15);
		psrlw(xmm5, 8);

		lerp16<0>(xmm5, xmm3, ptr[&m_local.temp.uf]);
		lerp16<0>(xmm5, xmm4, ptr[&m_local.temp.vf]);

		// xmm2 = r
		// xmm0 = g
		// xmm1 = b
		// xmm5 = a
		// xmm3, xmm4, xmm6, xmm7 = free

		// TODO
		movdqa(xmm3, xmm5); // a
		movdqa(xmm4, xmm2); // r
		movdqa(xmm6, xmm1); // b
		movdqa(xmm5, xmm0); // g

		// reload test

		movdqa(xmm7, ptr[&m_local.temp.test]);

		// xmm4 = r
		// xmm5 = g
		// xmm6 = b
		// xmm3 = a
		// xmm7 = test
		// xmm0, xmm1, xmm2 = free

		// test |= (c[0] | c[1] | c[2] | c[3]).eq16(GSVector4i::zero()); // mask out blank pixels (not perfect)

		movdqa(xmm1, xmm3);
		por(xmm1, xmm4);
		movdqa(xmm2, xmm5);
		por(xmm2, xmm6);
		por(xmm1, xmm2);

		pxor(xmm0, xmm0);
		pcmpeqw(xmm1, xmm0);
		por(xmm7, xmm1);

		// a = a.gt16(GSVector4i::zero());

		pcmpgtw(xmm3, xmm0);

		// reload fd

		movdqa(xmm1, ptr[&m_local.temp.fd]);
	}
	else
	{
		if(m_sel.twin)
		{
			// u = (u & m_local.twin[0].u).add16(m_local.twin[1].u);
			// v = (v & m_local.twin[0].v).add16(m_local.twin[1].v);

			pand(xmm2, ptr[&m_local.twin[0].u]);
			paddw(xmm2, ptr[&m_local.twin[1].u]);
			pand(xmm3, ptr[&m_local.twin[0].v]);
			paddw(xmm3, ptr[&m_local.twin[1].v]);
		}
		else
		{
			// u = u.min_i16(m_local.twin[2].u);
			// v = v.min_i16(m_local.twin[2].v);

			// TODO: if(!sprite) clamp16 else:

			pminsw(xmm2, ptr[&m_local.twin[2].u]);
			pminsw(xmm3, ptr[&m_local.twin[2].v]);
		}

		// xmm2 = u
		// xmm3 = v
		// xmm7 = test
		// xmm0, xmm4, xmm5, xmm6 = free
		// xmm1 = used

		// GSVector4i addr = v.sll16(8) | u;

		psllw(xmm3, 8);
		por(xmm3, xmm2);

		// xmm3 = addr
		// xmm7 = test
		// xmm0, xmm2, xmm4, xmm5, xmm6 = free
		// xmm1 = used

		ReadTexel(xmm6, xmm3);

		// xmm3 = c00
		// xmm7 = test
		// xmm0, xmm2, xmm4, xmm5, xmm6 = free
		// xmm1 = used

		// test |= c00.eq16(GSVector4i::zero()); // mask out blank pixels

		pxor(xmm0, xmm0);
		pcmpeqw(xmm0, xmm6);
		por(xmm7, xmm0);

		// c[0] = (c00 << 3) & 0x00f800f8;
		// c[1] = (c00 >> 2) & 0x00f800f8;
		// c[2] = (c00 >> 7) & 0x00f800f8;
		// c[3] = c00.sra16(15);

		movdqa(xmm3, xmm6);
		psraw(xmm3, 15); // a

		pcmpeqd(xmm0, xmm0);
		psrlw(xmm0, 11);
		psllw(xmm0, 3); // 0x00f8

		movdqa(xmm4, xmm6);
		psllw(xmm4, 3);
		pand(xmm4, xmm0); // r

		movdqa(xmm5, xmm6);
		psrlw(xmm5, 2);
		pand(xmm5, xmm0); // g

		psrlw(xmm6, 7);
		pand(xmm6, xmm0); // b
	}
}
예제 #12
0
void MacroAssembler::fast_exp(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xmm2, XMMRegister xmm3, XMMRegister xmm4, XMMRegister xmm5, XMMRegister xmm6, XMMRegister xmm7, Register eax, Register ecx, Register edx, Register tmp) {
  Label L_2TAG_PACKET_0_0_2, L_2TAG_PACKET_1_0_2, L_2TAG_PACKET_2_0_2, L_2TAG_PACKET_3_0_2;
  Label L_2TAG_PACKET_4_0_2, L_2TAG_PACKET_5_0_2, L_2TAG_PACKET_6_0_2, L_2TAG_PACKET_7_0_2;
  Label L_2TAG_PACKET_8_0_2, L_2TAG_PACKET_9_0_2, L_2TAG_PACKET_10_0_2, L_2TAG_PACKET_11_0_2;
  Label L_2TAG_PACKET_12_0_2, B1_3, B1_5, start;

  assert_different_registers(tmp, eax, ecx, edx);
  jmp(start);
  address cv = (address)_cv;
  address Shifter = (address)_shifter;
  address mmask = (address)_mmask;
  address bias = (address)_bias;
  address Tbl_addr = (address)_Tbl_addr;
  address ALLONES = (address)_ALLONES;
  address ebias = (address)_ebias;
  address XMAX = (address)_XMAX;
  address XMIN = (address)_XMIN;
  address INF = (address)_INF;
  address ZERO = (address)_ZERO;
  address ONE_val = (address)_ONE_val;

  bind(start);
  subq(rsp, 24);
  movsd(Address(rsp, 8), xmm0);
  unpcklpd(xmm0, xmm0);
  movdqu(xmm1, ExternalAddress(cv));       // 0x652b82feUL, 0x40571547UL, 0x652b82feUL, 0x40571547UL
  movdqu(xmm6, ExternalAddress(Shifter));  // 0x00000000UL, 0x43380000UL, 0x00000000UL, 0x43380000UL
  movdqu(xmm2, ExternalAddress(16+cv));    // 0xfefa0000UL, 0x3f862e42UL, 0xfefa0000UL, 0x3f862e42UL
  movdqu(xmm3, ExternalAddress(32+cv));    // 0xbc9e3b3aUL, 0x3d1cf79aUL, 0xbc9e3b3aUL, 0x3d1cf79aUL
  pextrw(eax, xmm0, 3);
  andl(eax, 32767);
  movl(edx, 16527);
  subl(edx, eax);
  subl(eax, 15504);
  orl(edx, eax);
  cmpl(edx, INT_MIN);
  jcc(Assembler::aboveEqual, L_2TAG_PACKET_0_0_2);
  mulpd(xmm1, xmm0);
  addpd(xmm1, xmm6);
  movapd(xmm7, xmm1);
  subpd(xmm1, xmm6);
  mulpd(xmm2, xmm1);
  movdqu(xmm4, ExternalAddress(64+cv));    // 0xe3289860UL, 0x3f56c15cUL, 0x555b9e25UL, 0x3fa55555UL
  mulpd(xmm3, xmm1);
  movdqu(xmm5, ExternalAddress(80+cv));    // 0xc090cf0fUL, 0x3f811115UL, 0x55548ba1UL, 0x3fc55555UL
  subpd(xmm0, xmm2);
  movdl(eax, xmm7);
  movl(ecx, eax);
  andl(ecx, 63);
  shll(ecx, 4);
  sarl(eax, 6);
  movl(edx, eax);
  movdqu(xmm6, ExternalAddress(mmask));    // 0xffffffc0UL, 0x00000000UL, 0xffffffc0UL, 0x00000000UL
  pand(xmm7, xmm6);
  movdqu(xmm6, ExternalAddress(bias));     // 0x0000ffc0UL, 0x00000000UL, 0x0000ffc0UL, 0x00000000UL
  paddq(xmm7, xmm6);
  psllq(xmm7, 46);
  subpd(xmm0, xmm3);
  lea(tmp, ExternalAddress(Tbl_addr));
  movdqu(xmm2, Address(ecx,tmp));
  mulpd(xmm4, xmm0);
  movapd(xmm6, xmm0);
  movapd(xmm1, xmm0);
  mulpd(xmm6, xmm6);
  mulpd(xmm0, xmm6);
  addpd(xmm5, xmm4);
  mulsd(xmm0, xmm6);
  mulpd(xmm6, ExternalAddress(48+cv));     // 0xfffffffeUL, 0x3fdfffffUL, 0xfffffffeUL, 0x3fdfffffUL
  addsd(xmm1, xmm2);
  unpckhpd(xmm2, xmm2);
  mulpd(xmm0, xmm5);
  addsd(xmm1, xmm0);
  por(xmm2, xmm7);
  unpckhpd(xmm0, xmm0);
  addsd(xmm0, xmm1);
  addsd(xmm0, xmm6);
  addl(edx, 894);
  cmpl(edx, 1916);
  jcc (Assembler::above, L_2TAG_PACKET_1_0_2);
  mulsd(xmm0, xmm2);
  addsd(xmm0, xmm2);
  jmp (B1_5);

  bind(L_2TAG_PACKET_1_0_2);
  xorpd(xmm3, xmm3);
  movdqu(xmm4, ExternalAddress(ALLONES));  // 0xffffffffUL, 0xffffffffUL, 0xffffffffUL, 0xffffffffUL
  movl(edx, -1022);
  subl(edx, eax);
  movdl(xmm5, edx);
  psllq(xmm4, xmm5);
  movl(ecx, eax);
  sarl(eax, 1);
  pinsrw(xmm3, eax, 3);
  movdqu(xmm6, ExternalAddress(ebias));    // 0x00000000UL, 0x3ff00000UL, 0x00000000UL, 0x3ff00000UL
  psllq(xmm3, 4);
  psubd(xmm2, xmm3);
  mulsd(xmm0, xmm2);
  cmpl(edx, 52);
  jcc(Assembler::greater, L_2TAG_PACKET_2_0_2);
  pand(xmm4, xmm2);
  paddd(xmm3, xmm6);
  subsd(xmm2, xmm4);
  addsd(xmm0, xmm2);
  cmpl(ecx, 1023);
  jcc(Assembler::greaterEqual, L_2TAG_PACKET_3_0_2);
  pextrw(ecx, xmm0, 3);
  andl(ecx, 32768);
  orl(edx, ecx);
  cmpl(edx, 0);
  jcc(Assembler::equal, L_2TAG_PACKET_4_0_2);
  movapd(xmm6, xmm0);
  addsd(xmm0, xmm4);
  mulsd(xmm0, xmm3);
  pextrw(ecx, xmm0, 3);
  andl(ecx, 32752);
  cmpl(ecx, 0);
  jcc(Assembler::equal, L_2TAG_PACKET_5_0_2);
  jmp(B1_5);

  bind(L_2TAG_PACKET_5_0_2);
  mulsd(xmm6, xmm3);
  mulsd(xmm4, xmm3);
  movdqu(xmm0, xmm6);
  pxor(xmm6, xmm4);
  psrad(xmm6, 31);
  pshufd(xmm6, xmm6, 85);
  psllq(xmm0, 1);
  psrlq(xmm0, 1);
  pxor(xmm0, xmm6);
  psrlq(xmm6, 63);
  paddq(xmm0, xmm6);
  paddq(xmm0, xmm4);
  movl(Address(rsp,0), 15);
  jmp(L_2TAG_PACKET_6_0_2);

  bind(L_2TAG_PACKET_4_0_2);
  addsd(xmm0, xmm4);
  mulsd(xmm0, xmm3);
  jmp(B1_5);

  bind(L_2TAG_PACKET_3_0_2);
  addsd(xmm0, xmm4);
  mulsd(xmm0, xmm3);
  pextrw(ecx, xmm0, 3);
  andl(ecx, 32752);
  cmpl(ecx, 32752);
  jcc(Assembler::aboveEqual, L_2TAG_PACKET_7_0_2);
  jmp(B1_5);

  bind(L_2TAG_PACKET_2_0_2);
  paddd(xmm3, xmm6);
  addpd(xmm0, xmm2);
  mulsd(xmm0, xmm3);
  movl(Address(rsp,0), 15);
  jmp(L_2TAG_PACKET_6_0_2);

  bind(L_2TAG_PACKET_8_0_2);
  cmpl(eax, 2146435072);
  jcc(Assembler::aboveEqual, L_2TAG_PACKET_9_0_2);
  movl(eax, Address(rsp,12));
  cmpl(eax, INT_MIN);
  jcc(Assembler::aboveEqual, L_2TAG_PACKET_10_0_2);
  movsd(xmm0, ExternalAddress(XMAX));      // 0xffffffffUL, 0x7fefffffUL
  mulsd(xmm0, xmm0);

  bind(L_2TAG_PACKET_7_0_2);
  movl(Address(rsp,0), 14);
  jmp(L_2TAG_PACKET_6_0_2);

  bind(L_2TAG_PACKET_10_0_2);
  movsd(xmm0, ExternalAddress(XMIN));      // 0x00000000UL, 0x00100000UL
  mulsd(xmm0, xmm0);
  movl(Address(rsp,0), 15);
  jmp(L_2TAG_PACKET_6_0_2);

  bind(L_2TAG_PACKET_9_0_2);
  movl(edx, Address(rsp,8));
  cmpl(eax, 2146435072);
  jcc(Assembler::above, L_2TAG_PACKET_11_0_2);
  cmpl(edx, 0);
  jcc(Assembler::notEqual, L_2TAG_PACKET_11_0_2);
  movl(eax, Address(rsp,12));
  cmpl(eax, 2146435072);
  jcc(Assembler::notEqual, L_2TAG_PACKET_12_0_2);
  movsd(xmm0, ExternalAddress(INF));       // 0x00000000UL, 0x7ff00000UL
  jmp(B1_5);

  bind(L_2TAG_PACKET_12_0_2);
  movsd(xmm0, ExternalAddress(ZERO));      // 0x00000000UL, 0x00000000UL
  jmp(B1_5);

  bind(L_2TAG_PACKET_11_0_2);
  movsd(xmm0, Address(rsp, 8));
  addsd(xmm0, xmm0);
  jmp(B1_5);

  bind(L_2TAG_PACKET_0_0_2);
  movl(eax, Address(rsp, 12));
  andl(eax, 2147483647);
  cmpl(eax, 1083179008);
  jcc(Assembler::aboveEqual, L_2TAG_PACKET_8_0_2);
  movsd(Address(rsp, 8), xmm0);
  addsd(xmm0, ExternalAddress(ONE_val));   // 0x00000000UL, 0x3ff00000UL
  jmp(B1_5);

  bind(L_2TAG_PACKET_6_0_2);
  movq(Address(rsp, 16), xmm0);

  bind(B1_3);
  movq(xmm0, Address(rsp, 16));

  bind(B1_5);
  addq(rsp, 24);
}
void GSDrawScanlineCodeGenerator::SampleTexture()
{
    if(!m_sel.fb || m_sel.tfx == TFX_NONE)
    {
        return;
    }

    mov(ebx, dword[&m_env.tex]);

    // ebx = tex

    if(!m_sel.fst)
    {
        // TODO: move these into Init/Step too?

        cvttps2dq(xmm2, xmm2);
        cvttps2dq(xmm3, xmm3);

        if(m_sel.ltf)
        {
            // u -= 0x8000;
            // v -= 0x8000;

            mov(eax, 0x8000);
            movd(xmm4, eax);
            pshufd(xmm4, xmm4, _MM_SHUFFLE(0, 0, 0, 0));
            psubd(xmm2, xmm4);
            psubd(xmm3, xmm4);
        }
    }

    // xmm2 = u
    // xmm3 = v

    if(m_sel.ltf)
    {
        // GSVector4i uf = u.xxzzlh().srl16(1);

        movdqa(xmm0, xmm2);
        pshuflw(xmm0, xmm0, _MM_SHUFFLE(2, 2, 0, 0));
        pshufhw(xmm0, xmm0, _MM_SHUFFLE(2, 2, 0, 0));
        psrlw(xmm0, 1);
        movdqa(xmmword[&m_env.temp.uf], xmm0);

        if(!m_sel.sprite)
        {
            // GSVector4i vf = v.xxzzlh().srl16(1);

            movdqa(xmm1, xmm3);
            pshuflw(xmm1, xmm1, _MM_SHUFFLE(2, 2, 0, 0));
            pshufhw(xmm1, xmm1, _MM_SHUFFLE(2, 2, 0, 0));
            psrlw(xmm1, 1);
            movdqa(xmmword[&m_env.temp.vf], xmm1);
        }
    }

    // GSVector4i uv0 = u.sra32(16).ps32(v.sra32(16));

    psrad(xmm2, 16);
    psrad(xmm3, 16);
    packssdw(xmm2, xmm3);

    if(m_sel.ltf)
    {
        // GSVector4i uv1 = uv0.add16(GSVector4i::x0001());

        movdqa(xmm3, xmm2);
        pcmpeqd(xmm1, xmm1);
        psrlw(xmm1, 15);
        paddw(xmm3, xmm1);

        // uv0 = Wrap(uv0);
        // uv1 = Wrap(uv1);

        Wrap(xmm2, xmm3);
    }
    else
    {
        // uv0 = Wrap(uv0);

        Wrap(xmm2);
    }

    // xmm2 = uv0
    // xmm3 = uv1 (ltf)
    // xmm0, xmm1, xmm4, xmm5, xmm6 = free
    // xmm7 = used

    // GSVector4i y0 = uv0.uph16() << tw;
    // GSVector4i x0 = uv0.upl16();

    pxor(xmm0, xmm0);
    movd(xmm1, ptr[&m_env.tw]);

    movdqa(xmm4, xmm2);
    punpckhwd(xmm2, xmm0);
    punpcklwd(xmm4, xmm0);
    pslld(xmm2, xmm1);

    // xmm0 = 0
    // xmm1 = tw
    // xmm2 = y0
    // xmm3 = uv1 (ltf)
    // xmm4 = x0
    // xmm5, xmm6 = free
    // xmm7 = used

    if(m_sel.ltf)
    {
        // GSVector4i y1 = uv1.uph16() << tw;
        // GSVector4i x1 = uv1.upl16();

        movdqa(xmm6, xmm3);
        punpckhwd(xmm3, xmm0);
        punpcklwd(xmm6, xmm0);
        pslld(xmm3, xmm1);

        // xmm2 = y0
        // xmm3 = y1
        // xmm4 = x0
        // xmm6 = x1
        // xmm0, xmm5, xmm6 = free
        // xmm7 = used

        // GSVector4i addr00 = y0 + x0;
        // GSVector4i addr01 = y0 + x1;
        // GSVector4i addr10 = y1 + x0;
        // GSVector4i addr11 = y1 + x1;

        movdqa(xmm5, xmm2);
        paddd(xmm5, xmm4);
        paddd(xmm2, xmm6);

        movdqa(xmm0, xmm3);
        paddd(xmm0, xmm4);
        paddd(xmm3, xmm6);

        // xmm5 = addr00
        // xmm2 = addr01
        // xmm0 = addr10
        // xmm3 = addr11
        // xmm1, xmm4, xmm6 = free
        // xmm7 = used

        // c00 = addr00.gather32_32((const uint32/uint8*)tex[, clut]);
        // c01 = addr01.gather32_32((const uint32/uint8*)tex[, clut]);
        // c10 = addr10.gather32_32((const uint32/uint8*)tex[, clut]);
        // c11 = addr11.gather32_32((const uint32/uint8*)tex[, clut]);

        ReadTexel(xmm6, xmm5, xmm1, xmm4);

        // xmm2, xmm5, xmm1 = free

        ReadTexel(xmm4, xmm2, xmm5, xmm1);

        // xmm0, xmm2, xmm5 = free

        ReadTexel(xmm1, xmm0, xmm2, xmm5);

        // xmm3, xmm0, xmm2 = free

        ReadTexel(xmm5, xmm3, xmm0, xmm2);

        // xmm6 = c00
        // xmm4 = c01
        // xmm1 = c10
        // xmm5 = c11
        // xmm0, xmm2, xmm3 = free
        // xmm7 = used

        movdqa(xmm0, xmmword[&m_env.temp.uf]);

        // GSVector4i rb00 = c00 & mask;
        // GSVector4i ga00 = (c00 >> 8) & mask;

        movdqa(xmm2, xmm6);
        psllw(xmm2, 8);
        psrlw(xmm2, 8);
        psrlw(xmm6, 8);

        // GSVector4i rb01 = c01 & mask;
        // GSVector4i ga01 = (c01 >> 8) & mask;

        movdqa(xmm3, xmm4);
        psllw(xmm3, 8);
        psrlw(xmm3, 8);
        psrlw(xmm4, 8);

        // xmm0 = uf
        // xmm2 = rb00
        // xmm3 = rb01
        // xmm6 = ga00
        // xmm4 = ga01
        // xmm1 = c10
        // xmm5 = c11
        // xmm7 = used

        // rb00 = rb00.lerp16<0>(rb01, uf);
        // ga00 = ga00.lerp16<0>(ga01, uf);

        lerp16<0>(xmm3, xmm2, xmm0);
        lerp16<0>(xmm4, xmm6, xmm0);

        // xmm0 = uf
        // xmm3 = rb00
        // xmm4 = ga00
        // xmm1 = c10
        // xmm5 = c11
        // xmm2, xmm6 = free
        // xmm7 = used

        // GSVector4i rb10 = c10 & mask;
        // GSVector4i ga10 = (c10 >> 8) & mask;

        movdqa(xmm2, xmm1);
        psllw(xmm1, 8);
        psrlw(xmm1, 8);
        psrlw(xmm2, 8);

        // GSVector4i rb11 = c11 & mask;
        // GSVector4i ga11 = (c11 >> 8) & mask;

        movdqa(xmm6, xmm5);
        psllw(xmm5, 8);
        psrlw(xmm5, 8);
        psrlw(xmm6, 8);

        // xmm0 = uf
        // xmm3 = rb00
        // xmm4 = ga00
        // xmm1 = rb10
        // xmm5 = rb11
        // xmm2 = ga10
        // xmm6 = ga11
        // xmm7 = used

        // rb10 = rb10.lerp16<0>(rb11, uf);
        // ga10 = ga10.lerp16<0>(ga11, uf);

        lerp16<0>(xmm5, xmm1, xmm0);
        lerp16<0>(xmm6, xmm2, xmm0);

        // xmm3 = rb00
        // xmm4 = ga00
        // xmm5 = rb10
        // xmm6 = ga10
        // xmm0, xmm1, xmm2 = free
        // xmm7 = used

        // rb00 = rb00.lerp16<0>(rb10, vf);
        // ga00 = ga00.lerp16<0>(ga10, vf);

        movdqa(xmm0, xmmword[&m_env.temp.vf]);

        lerp16<0>(xmm5, xmm3, xmm0);
        lerp16<0>(xmm6, xmm4, xmm0);
    }
    else
    {
        // GSVector4i addr00 = y0 + x0;

        paddd(xmm2, xmm4);

        // c00 = addr00.gather32_32((const uint32/uint8*)tex[, clut]);

        ReadTexel(xmm5, xmm2, xmm0, xmm1);

        // GSVector4i mask = GSVector4i::x00ff();

        // c[0] = c00 & mask;
        // c[1] = (c00 >> 8) & mask;

        movdqa(xmm6, xmm5);

        psllw(xmm5, 8);
        psrlw(xmm5, 8);
        psrlw(xmm6, 8);
    }
}
 template <class _mm, int src_aligned, int dst_aligned> void TffdshowConverters2::convert_simd_GBRPtoRGB(
    const uint8_t* srcG,
    const uint8_t* srcB,
    const uint8_t* srcR,
    uint8_t* dst,
    int dx,
    int dy,
    stride_t stride_src,
    stride_t stride_dst)
 {
    int xCount = dx / _mm::size;
    if (xCount <= 0)
        return;

    _mm::__m _mm0,_mm1,_mm2,_mm3,_mm4,_mm5,_mm6;
    _mm::__m ffff;
    pxor(ffff,ffff);
    pcmpeqb(ffff,ffff);
    for (int y = 0 ; y < dy ; y++) {
        const uint8_t *g = srcG + y * stride_src;
        const uint8_t *b = srcB + y * stride_src;
        const uint8_t *r = srcR + y * stride_src;
        uint8_t *dst1 = dst + y * stride_dst;
        int x = xCount;
        do {
            if (src_aligned) {
                movVqa(_mm0, r);
                movVqa(_mm1, g);
                movVqa(_mm2, b);
            } else {
                movVqu(_mm0, r);
                movVqu(_mm1, g);
                movVqu(_mm2, b);
            }
            _mm4 = _mm0;
            _mm5 = _mm2;
            punpcklbw(_mm0,ffff);    // 0xff,R
            punpcklbw(_mm2,_mm1);    // G,B
            punpckhbw(_mm4,ffff);    // 0xff,R
            punpckhbw(_mm5,_mm1);    // G,B
            _mm3 = _mm2;
            _mm6 = _mm5;
            punpckhwd(_mm2,_mm0);    // 0xff,RGB * 4 (dst+_mm::size)
            punpcklwd(_mm3,_mm0);    // 0xff,RGB * 4 (dst)
            punpckhwd(_mm5,_mm4);    // 0xff,RGB * 4 (dst+_mm::size)
            punpcklwd(_mm6,_mm4);    // 0xff,RGB * 4 (dst)
            if (dst_aligned) {
                _mm::movntVq(dst1              , _mm3);
                _mm::movntVq(dst1 + _mm::size  , _mm2);
                _mm::movntVq(dst1 + _mm::size*2, _mm6);
                _mm::movntVq(dst1 + _mm::size*3, _mm5);
            } else {
                movVqu(dst1              , _mm3);
                movVqu(dst1 + _mm::size  , _mm2);
                movVqu(dst1 + _mm::size*2, _mm6);
                movVqu(dst1 + _mm::size*3, _mm5);
            }
            r += _mm::size;
            g += _mm::size;
            b += _mm::size;
            dst1 += _mm::size * 4;
        } while(--x);
    }

    if (xCount * (int)_mm::size < dx && dx > _mm::size) {
        // handle non-mod 8 resolution.
        int dxDone = dx - _mm::size;
        srcG += dxDone;
        srcB += dxDone;
        srcR += dxDone;
        dst  += dxDone * 4;
        convert_simd_GBRPtoRGB<_mm, 0, 0>(srcG, srcB, srcR, dst, _mm::size, dy, stride_src, stride_dst);
    }

    _mm::empty();
 }
void GSDrawScanlineCodeGenerator::AlphaBlend()
{
    if(!m_sel.fwrite)
    {
        return;
    }

    if(m_sel.abe == 0 && m_sel.aa1 == 0)
    {
        return;
    }

    if((m_sel.aba != m_sel.abb) && (m_sel.aba == 1 || m_sel.abb == 1 || m_sel.abc == 1) || m_sel.abd == 1)
    {
        switch(m_sel.fpsm)
        {
        case 0:
        case 1:

            // c[2] = fd & mask;
            // c[3] = (fd >> 8) & mask;

            movdqa(xmm0, xmm2);
            movdqa(xmm1, xmm2);

            psllw(xmm0, 8);
            psrlw(xmm0, 8);
            psrlw(xmm1, 8);

            break;

        case 2:

            // c[2] = ((fd & 0x7c00) << 9) | ((fd & 0x001f) << 3);
            // c[3] = ((fd & 0x8000) << 8) | ((fd & 0x03e0) >> 2);

            movdqa(xmm0, xmm2);
            movdqa(xmm1, xmm2);
            movdqa(xmm4, xmm2);

            pcmpeqd(xmm7, xmm7);
            psrld(xmm7, 27); // 0x0000001f
            pand(xmm0, xmm7);
            pslld(xmm0, 3);

            pslld(xmm7, 10); // 0x00007c00
            pand(xmm4, xmm7);
            pslld(xmm4, 9);

            por(xmm0, xmm4);

            movdqa(xmm4, xmm1);

            psrld(xmm7, 5); // 0x000003e0
            pand(xmm1, xmm7);
            psrld(xmm1, 2);

            psllw(xmm7, 10); // 0x00008000
            pand(xmm4, xmm7);
            pslld(xmm4, 8);

            por(xmm1, xmm4);

            break;
        }
    }

    // xmm5, xmm6 = src rb, ga
    // xmm0, xmm1 = dst rb, ga
    // xmm2, xmm3 = used
    // xmm4, xmm7 = free

    if(m_sel.pabe || (m_sel.aba != m_sel.abb) && (m_sel.abb == 0 || m_sel.abd == 0))
    {
        movdqa(xmm4, xmm5);
    }

    if(m_sel.aba != m_sel.abb)
    {
        // rb = c[aba * 2 + 0];

        switch(m_sel.aba)
        {
        case 0:
            break;
        case 1:
            movdqa(xmm5, xmm0);
            break;
        case 2:
            pxor(xmm5, xmm5);
            break;
        }

        // rb = rb.sub16(c[abb * 2 + 0]);

        switch(m_sel.abb)
        {
        case 0:
            psubw(xmm5, xmm4);
            break;
        case 1:
            psubw(xmm5, xmm0);
            break;
        case 2:
            break;
        }

        if(!(m_sel.fpsm == 1 && m_sel.abc == 1))
        {
            // GSVector4i a = abc < 2 ? c[abc * 2 + 1].yywwlh().sll16(7) : m_env.afix;

            switch(m_sel.abc)
            {
            case 0:
            case 1:
                movdqa(xmm7, m_sel.abc ? xmm1 : xmm6);
                pshuflw(xmm7, xmm7, _MM_SHUFFLE(3, 3, 1, 1));
                pshufhw(xmm7, xmm7, _MM_SHUFFLE(3, 3, 1, 1));
                psllw(xmm7, 7);
                break;
            case 2:
                movdqa(xmm7, xmmword[&m_env.afix]);
                break;
            }

            // rb = rb.modulate16<1>(a);

            modulate16<1>(xmm5, xmm7);
        }

        // rb = rb.add16(c[abd * 2 + 0]);

        switch(m_sel.abd)
        {
        case 0:
            paddw(xmm5, xmm4);
            break;
        case 1:
            paddw(xmm5, xmm0);
            break;
        case 2:
            break;
        }
    }
    else
    {
        // rb = c[abd * 2 + 0];

        switch(m_sel.abd)
        {
        case 0:
            break;
        case 1:
            movdqa(xmm5, xmm0);
            break;
        case 2:
            pxor(xmm5, xmm5);
            break;
        }
    }

    if(m_sel.pabe)
    {
        // mask = (c[1] << 8).sra32(31);

        movdqa(xmm0, xmm6);
        pslld(xmm0, 8);
        psrad(xmm0, 31);

        // rb = c[0].blend8(rb, mask);

        blend8r(xmm5, xmm4);
    }

    // xmm6 = src ga
    // xmm1 = dst ga
    // xmm5 = rb
    // xmm7 = a
    // xmm2, xmm3 = used
    // xmm0, xmm4 = free

    movdqa(xmm4, xmm6);

    if(m_sel.aba != m_sel.abb)
    {
        // ga = c[aba * 2 + 1];

        switch(m_sel.aba)
        {
        case 0:
            break;
        case 1:
            movdqa(xmm6, xmm1);
            break;
        case 2:
            pxor(xmm6, xmm6);
            break;
        }

        // ga = ga.sub16(c[abeb * 2 + 1]);

        switch(m_sel.abb)
        {
        case 0:
            psubw(xmm6, xmm4);
            break;
        case 1:
            psubw(xmm6, xmm1);
            break;
        case 2:
            break;
        }

        if(!(m_sel.fpsm == 1 && m_sel.abc == 1))
        {
            // ga = ga.modulate16<1>(a);

            modulate16<1>(xmm6, xmm7);
        }

        // ga = ga.add16(c[abd * 2 + 1]);

        switch(m_sel.abd)
        {
        case 0:
            paddw(xmm6, xmm4);
            break;
        case 1:
            paddw(xmm6, xmm1);
            break;
        case 2:
            break;
        }
    }
    else
    {
        // ga = c[abd * 2 + 1];

        switch(m_sel.abd)
        {
        case 0:
            break;
        case 1:
            movdqa(xmm6, xmm1);
            break;
        case 2:
            pxor(xmm6, xmm6);
            break;
        }
    }

    // xmm4 = src ga
    // xmm5 = rb
    // xmm6 = ga
    // xmm2, xmm3 = used
    // xmm0, xmm1, xmm7 = free

    if(m_sel.pabe)
    {
        if(!m_cpu.has(util::Cpu::tSSE41))
        {
            // doh, previous blend8r overwrote xmm0 (sse41 uses pblendvb)

            movdqa(xmm0, xmm4);
            pslld(xmm0, 8);
            psrad(xmm0, 31);
        }

        psrld(xmm0, 16); // zero out high words to select the source alpha in blend (so it also does mix16)

        // ga = c[1].blend8(ga, mask).mix16(c[1]);

        blend8r(xmm6, xmm4);
    }
    else
    {
        if(m_sel.fpsm != 1) // TODO: fm == 0xffxxxxxx
        {
            mix16(xmm6, xmm4, xmm7);
        }
    }
}
void GSDrawScanlineCodeGenerator::Wrap(const Xmm& uv)
{
    // xmm0, xmm1, xmm4, xmm5, xmm6 = free

    int wms_clamp = ((m_sel.wms + 1) >> 1) & 1;
    int wmt_clamp = ((m_sel.wmt + 1) >> 1) & 1;

    int region = ((m_sel.wms | m_sel.wmt) >> 1) & 1;

    if(wms_clamp == wmt_clamp)
    {
        if(wms_clamp)
        {
            if(region)
            {
                pmaxsw(uv, xmmword[&m_env.t.min]);
            }
            else
            {
                pxor(xmm0, xmm0);
                pmaxsw(uv, xmm0);
            }

            pminsw(uv, xmmword[&m_env.t.max]);
        }
        else
        {
            pand(uv, xmmword[&m_env.t.min]);

            if(region)
            {
                por(uv, xmmword[&m_env.t.max]);
            }
        }
    }
    else
    {
        movdqa(xmm1, uv);

        movdqa(xmm4, xmmword[&m_env.t.min]);
        movdqa(xmm5, xmmword[&m_env.t.max]);

        // GSVector4i clamp = t.sat_i16(m_env.t.min, m_env.t.max);

        pmaxsw(uv, xmm4);
        pminsw(uv, xmm5);

        // GSVector4i repeat = (t & m_env.t.min) | m_env.t.max;

        pand(xmm1, xmm4);

        if(region)
        {
            por(xmm1, xmm5);
        }

        // clamp.blend8(repeat, m_env.t.mask);

        movdqa(xmm0, xmmword[&m_env.t.mask]);
        blend8(uv, xmm1);
    }
}
void GSDrawScanlineCodeGenerator::TestAlpha()
{
    switch(m_sel.afail)
    {
    case AFAIL_FB_ONLY:
        if(!m_sel.zwrite) return;
        break;

    case AFAIL_ZB_ONLY:
        if(!m_sel.fwrite) return;
        break;

    case AFAIL_RGB_ONLY:
        if(!m_sel.zwrite && m_sel.fpsm == 1) return;
        break;
    }

    switch(m_sel.atst)
    {
    case ATST_NEVER:
        // t = GSVector4i::xffffffff();
        pcmpeqd(xmm1, xmm1);
        break;

    case ATST_ALWAYS:
        return;

    case ATST_LESS:
    case ATST_LEQUAL:
        // t = (ga >> 16) > m_env.aref;
        movdqa(xmm1, xmm6);
        psrld(xmm1, 16);
        pcmpgtd(xmm1, xmmword[&m_env.aref]);
        break;

    case ATST_EQUAL:
        // t = (ga >> 16) != m_env.aref;
        movdqa(xmm1, xmm6);
        psrld(xmm1, 16);
        pcmpeqd(xmm1, xmmword[&m_env.aref]);
        pcmpeqd(xmm0, xmm0);
        pxor(xmm1, xmm0);
        break;

    case ATST_GEQUAL:
    case ATST_GREATER:
        // t = (ga >> 16) < m_env.aref;
        movdqa(xmm0, xmm6);
        psrld(xmm0, 16);
        movdqa(xmm1, xmmword[&m_env.aref]);
        pcmpgtd(xmm1, xmm0);
        break;

    case ATST_NOTEQUAL:
        // t = (ga >> 16) == m_env.aref;
        movdqa(xmm1, xmm6);
        psrld(xmm1, 16);
        pcmpeqd(xmm1, xmmword[&m_env.aref]);
        break;
    }

    switch(m_sel.afail)
    {
    case AFAIL_KEEP:
        // test |= t;
        por(xmm7, xmm1);
        alltrue();
        break;

    case AFAIL_FB_ONLY:
        // zm |= t;
        por(xmm4, xmm1);
        break;

    case AFAIL_ZB_ONLY:
        // fm |= t;
        por(xmm3, xmm1);
        break;

    case AFAIL_RGB_ONLY:
        // zm |= t;
        por(xmm4, xmm1);
        // fm |= t & GSVector4i::xff000000();
        psrld(xmm1, 24);
        pslld(xmm1, 24);
        por(xmm3, xmm1);
        break;
    }
}
void GSDrawScanlineCodeGenerator::Wrap(const Xmm& uv0, const Xmm& uv1)
{
    // xmm0, xmm1, xmm4, xmm5, xmm6 = free

    int wms_clamp = ((m_sel.wms + 1) >> 1) & 1;
    int wmt_clamp = ((m_sel.wmt + 1) >> 1) & 1;

    int region = ((m_sel.wms | m_sel.wmt) >> 1) & 1;

    if(wms_clamp == wmt_clamp)
    {
        if(wms_clamp)
        {
            if(region)
            {
                movdqa(xmm4, xmmword[&m_env.t.min]);

                pmaxsw(uv0, xmm4);
                pmaxsw(uv1, xmm4);
            }
            else
            {
                pxor(xmm0, xmm0);
                pmaxsw(uv0, xmm0);
                pmaxsw(uv1, xmm0);
            }

            movdqa(xmm5, xmmword[&m_env.t.max]);

            pminsw(uv0, xmm5);
            pminsw(uv1, xmm5);
        }
        else
        {
            movdqa(xmm4, xmmword[&m_env.t.min]);

            pand(uv0, xmm4);
            pand(uv1, xmm4);

            if(region)
            {
                movdqa(xmm5, xmmword[&m_env.t.max]);

                por(uv0, xmm5);
                por(uv1, xmm5);
            }
        }
    }
    else
    {
        movdqa(xmm1, uv0);
        movdqa(xmm6, uv1);

        movdqa(xmm4, xmmword[&m_env.t.min]);
        movdqa(xmm5, xmmword[&m_env.t.max]);

        // GSVector4i clamp = t.sat_i16(m_env.t.min, m_env.t.max);

        pmaxsw(uv0, xmm4);
        pmaxsw(uv1, xmm4);
        pminsw(uv0, xmm5);
        pminsw(uv1, xmm5);

        // GSVector4i repeat = (t & m_env.t.min) | m_env.t.max;

        pand(xmm1, xmm4);
        pand(xmm6, xmm4);

        if(region)
        {
            por(xmm1, xmm5);
            por(xmm6, xmm5);
        }

        // clamp.blend8(repeat, m_env.t.mask);

        if(m_cpu.has(util::Cpu::tSSE41))
        {
            movdqa(xmm0, xmmword[&m_env.t.mask]);

            pblendvb(uv0, xmm1);
            pblendvb(uv1, xmm6);
        }
        else
        {
            movdqa(xmm0, xmmword[&m_env.t.invmask]);
            movdqa(xmm4, xmm0);

            pand(uv0, xmm0);
            pandn(xmm0, xmm1);
            por(uv0, xmm0);

            pand(uv1, xmm4);
            pandn(xmm4, xmm6);
            por(uv1, xmm4);
        }
    }
}
예제 #19
0
int main()
{
	int rval;
	mmx_t ma;
	mmx_t mb;

	movq_r2r(mm0, mm1);

	rval = mmx_ok();

	/* Announce return value of mmx_ok() */
//	printf("Value returned from init was %x.", rval);
//	printf(" (Indicates MMX %s available)\n\n",(rval)? "is" : "not");
//	fflush(stdout); fflush(stderr);

//	if(rval)
	{
		/* PADD *****************************************************/
		ma.q = 0x1111111180000000LL;
		mb.q = 0x7fffffff00000001LL;
		paddd(ma, mb);
		fprintf(stdout, "paddd: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddd: mb.q is 9111111080000001\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x0001000100010001LL;
		mb.q = 0x80007fffffff0001LL;
		paddw(ma, mb);
		fprintf(stdout, "paddw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddw: mb.q is 8001800000000002\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x80007fffffff0001LL;
		mb.q = 0x0001000100010000LL;
		paddw(ma, mb);
		fprintf(stdout, "paddw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddw: mb.q is 8001800000000001\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x01010101807fff01LL;
		mb.q = 0x807fff0101010101LL;
		paddb(ma, mb);
		fprintf(stdout, "paddb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddb: mb.q is 8180000281800002\n");
		fflush(stdout); fflush(stderr);


		/* PADDS ****************************************************/
		ma.q = 0x0001000100010001LL;
		mb.q = 0x80007fffffff0001LL;
		paddsw(ma, mb);
		fprintf(stdout, "paddsw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddsw: mb.q is 80017fff00000002\n");

		ma.q = 0x80007fffffff0001LL;
		mb.q = 0x0001000100010000LL;
		paddsw(ma, mb);
		fprintf(stdout, "paddsw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddsw: mb.q is 80017fff00000001\n");

		ma.q = 0x01010101807fff01LL;
		mb.q = 0x807fff0101010101LL;
		paddsb(ma, mb);
		fprintf(stdout, "paddsb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddsb: mb.q is 817f0002817f0002\n");
		fflush(stdout); fflush(stderr);


		/* PADDUS ***************************************************/
		ma.q = 0x0001000100010001LL;
		mb.q = 0x80007fffffff0001LL;
		paddusw(ma, mb);
		fprintf(stdout, "paddusw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddusw: mb.q is 80018000ffff0002\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x80007fffffff0001LL;
		mb.q = 0x0001000100010000LL;
		paddusw(ma, mb);
		fprintf(stdout, "paddusw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddusw: mb.q is 80018000ffff0001\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x01010101807fff01LL;
		mb.q = 0x807fff0101010101LL;
		paddusb(ma, mb);
		fprintf(stdout, "paddusb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "paddusb: mb.q is 8180ff028180ff02\n");
		fflush(stdout); fflush(stderr);


		/* PSUB *****************************************************/
		ma.q = 0x7fffffff00000001LL;
		mb.q = 0x1111111180000000LL;
		psubd(ma, mb);
		fprintf(stdout, "psubd: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubd: mb.q is 911111127fffffff\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x80007fffffff0001LL;
		mb.q = 0x0001000100010001LL;
		psubw(ma, mb);
		fprintf(stdout, "psubw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubw: mb.q is 8001800200020000\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x0001000100010000LL;
		mb.q = 0x80007fffffff0001LL;
		psubw(ma, mb);
		fprintf(stdout, "psubw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubw: mb.q is 7fff7ffefffe0001\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x807fff0101010101LL;
		mb.q = 0x01010101807fff01LL;
		psubb(ma, mb);
		fprintf(stdout, "psubb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubb: mb.q is 818202007f7efe00\n");
		fflush(stdout); fflush(stderr);


		/* PSUBS ****************************************************/
		ma.q = 0x80007fffffff0001LL;
		mb.q = 0x0001000100010001LL;
		psubsw(ma, mb);
		fprintf(stdout, "psubsw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubsw: mb.q is 7fff800200020000\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x0001000100010000LL;
		mb.q = 0x80007fffffff0001LL;
		psubsw(ma, mb);
		fprintf(stdout, "psubsw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubsw: mb.q is 80007ffefffe0001\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x807fff0101010101LL;
		mb.q = 0x01010101807fff01LL;
		psubsb(ma, mb);
		fprintf(stdout, "psubsb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubsb: mb.q is 7f820200807efe00\n");
		fflush(stdout); fflush(stderr);
 

		/* PSUBUS ***************************************************/
		ma.q = 0x80007fffffff0001LL;
		mb.q = 0x0001000100010001LL;
		psubusw(ma, mb);
		fprintf(stdout, "psubusw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubusw: mb.q is 0000000000000000\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x0001000100010000LL;
		mb.q = 0x80007fffffff0001LL;
		psubusw(ma, mb);
		fprintf(stdout, "psubusw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubusw: mb.q is 7fff7ffefffe0001\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x807fff0101010101LL;
		mb.q = 0x01010101807fff01LL;
		psubusb(ma, mb);
		fprintf(stdout, "psubusb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psubusb: mb.q is 000000007f7efe00\n");
		fflush(stdout); fflush(stderr);


		/* PMUL *****************************************************/
		ma.q = 0x8000ffff00ff0000LL;
		mb.q = 0x0200ffff00ffffffLL;
		pmulhw(ma, mb);
		fprintf(stdout, "pmulhw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pmulhw: mb.q is ff00000000000000\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0200ffff00ffffffLL;
		pmullw(ma, mb);
		fprintf(stdout, "pmullw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pmullw: mb.q is 00000001fe010000\n");
		fflush(stdout); fflush(stderr);


		/* PMADD ****************************************************/
		ma.q = 0x8000345680007f34LL;
		mb.q = 0x93234a27ffff1707LL;

		pmaddwd(ma, mb);
		fprintf(stdout, "pmaddwd: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pmaddwd: mb.q is 4597551a0b71a66c\n");
		fflush(stdout); fflush(stderr);


		/* PCMPEQ ***************************************************/
		ma.q = 0x800034568f237f34LL;
		mb.q = 0x93009a568f237f34LL;

		pcmpeqd(ma, mb);
		fprintf(stdout, "pcmpeqd: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pcmpeqd: mb.q is 00000000ffffffff\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x93009a568f237f34LL;
		pcmpeqw(ma, mb);
		fprintf(stdout, "pcmpeqw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pcmpeqw: mb.q is 00000000ffffffff\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x93009a568f237f34LL;
		pcmpeqb(ma, mb);
		fprintf(stdout, "pcmpeqb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pcmpeqb: mb.q is 00ff00ffffffffff\n");
		fflush(stdout); fflush(stderr);



		/* PCMPGT ***************************************************/
		ma.q = 0x666688884477aaffLL;
		mb.q = 0x1234567890abcdefLL;

		pcmpgtd(ma, mb);
		fprintf(stdout, "pcmpgtd: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pcmpgtd: mb.q is 0000000000000000\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x1234567890abcdefLL;
		pcmpgtw(ma, mb);
		fprintf(stdout, "pcmpgtw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pcmpgtw: mb.q is 0000ffff0000ffff\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x1234567890abcdefLL;
		pcmpgtb(ma, mb);
		fprintf(stdout, "pcmpgtb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pcmpgtb: mb.q is 0000ffff0000ff00\n");
		fflush(stdout); fflush(stderr);


		/* PACKSS ***************************************************/
		ma.q = 0x00012222000abbbbLL;
		mb.q = 0x0000888800003333LL;

		packssdw(ma, mb);
		fprintf(stdout, "packssdw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "packssdw: mb.q is 7fff7fff7fff3333\n");
		fflush(stdout); fflush(stderr);

		ma.q = 0x00aa00dd01009999LL;
		mb.q = 0x0011002200330044LL;

		packsswb(ma, mb);
		fprintf(stdout, "packsswb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "packsswb: mb.q is 7f7f7f8011223344\n");
		fflush(stdout); fflush(stderr);


		/* PACKUS ***************************************************/
		ma.q = 0x00aa00dd01009999LL;
		mb.q = 0x0011002200330044LL;

		packuswb(ma, mb);
		fprintf(stdout, "packuswb: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "packuswb: mb.q is aaddff0011223344\n");
		fflush(stdout); fflush(stderr);


		/* PUNPCKH **************************************************/
		ma.q = 0x090a0b0c0d0e0f00LL;
		mb.q = 0x0102030405060708LL;

		punpckhdq(ma, mb);
		fprintf(stdout, "punpckhdq: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "punpckhdq: mb.q is 090a0b0c01020304\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0102030405060708LL;
		punpckhwd(ma, mb);
		fprintf(stdout, "punpckhwd: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "punpckhwd: mb.q is 090a01020b0c0304\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0102030405060708LL;
		punpckhbw(ma, mb);
		fprintf(stdout, "punpckhbw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "punpckhbw: mb.q is 09010a020b030c04\n");
		fflush(stdout); fflush(stderr);


		/* PUNPCKL **************************************************/
		ma.q = 0x090a0b0c0d0e0f00LL;
		mb.q = 0x0102030405060708LL;

		punpckldq(ma, mb);
		fprintf(stdout, "punpckldq: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "punpckldq: mb.q is 0d0e0f0005060708\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0102030405060708LL;
		punpcklwd(ma, mb);
		fprintf(stdout, "punpcklwd: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "punpcklwd: mb.q is 0d0e05060f000708\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0102030405060708LL;
		punpcklbw(ma, mb);
		fprintf(stdout, "punpcklbw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "punpcklbw: mb.q is 0d050e060f070008\n");
		fflush(stdout); fflush(stderr);



		/* PAND, PANDN, POR, PXOR ***********************************/
		ma.q = 0x5555555555555555LL;
		mb.q = 0x3333333333333333LL;

		pand(ma, mb);
		fprintf(stdout, "pand: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pand: mb.q is 1111111111111111\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x3333333333333333LL;
		pandn(ma, mb);
		fprintf(stdout, "pandn: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pandn: mb.q is 4444444444444444\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x3333333333333333LL;
		por(ma, mb);
		fprintf(stdout, "por: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "por: mb.q is 7777777777777777\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x3333333333333333LL;
		pxor(ma, mb);
		fprintf(stdout, "pxor: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pxor: mb.q is 6666666666666666\n");
		fflush(stdout); fflush(stderr);



		/* PSLL *****************************************************/
		ma.q = 0x0000000000000018LL;
		mb.q = 0x0123456789abcdefLL;

		psllq(ma, mb);
		fprintf(stdout, "psllq: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psllq: mb.q is 6789abcdef000000\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0123456789abcdefLL;
		pslld(ma, mb);
		fprintf(stdout, "pslld: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "pslld: mb.q is 67000000ef000000\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0123456789abcdefLL;
		psllw(ma, mb);
		fprintf(stdout, "psllw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psllw: mb.q is 0000000000000000\n");
		fflush(stdout); fflush(stderr);



		/* PSRL *****************************************************/
		ma.q = 0x0000000000000018LL;
		mb.q = 0x0123456789abcdefLL;

		psrlq(ma, mb);
		fprintf(stdout, "psrlq: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psrlq: mb.q is 0000000123456789\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0123456789abcdefLL;
		psrld(ma, mb);
		fprintf(stdout, "psrld: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psrld: mb.q is 0000000100000089\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0123456789abcdefLL;
		psrlw(ma, mb);
		fprintf(stdout, "psrlw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psrlw: mb.q is 0000000000000000\n");
		fflush(stdout); fflush(stderr);



		/* PSRA *****************************************************/
		ma.q = 0x0000000000000018LL;
		mb.q = 0x0123456789abcdefLL;

		psrad(ma, mb);
		fprintf(stdout, "psrad: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psrad: mb.q is 00000001ffffff89\n");
		fflush(stdout); fflush(stderr);

		mb.q = 0x0123456789abcdefLL;
		psraw(ma, mb);
		fprintf(stdout, "psraw: mb.q is %016llx\n", mb.q);
		fprintf(stderr, "psraw: mb.q is 00000000ffffffff\n");
		fflush(stdout); fflush(stderr);

		/* Exit MXX *************************************************/
		emms();
	}

	/* Clean-up and exit nicely */
	exit(0);
}
void GSDrawScanlineCodeGenerator::TestZ(const Xmm& temp1, const Xmm& temp2)
{
    if(!m_sel.zb)
    {
        return;
    }

    // int za = fza_base.y + fza_offset->y;

    mov(ebp, dword[esi + 4]);
    add(ebp, dword[edi + 4]);

    // GSVector4i zs = zi;

    if(!m_sel.sprite)
    {
        if(m_sel.zoverflow)
        {
            // zs = (GSVector4i(z * 0.5f) << 1) | (GSVector4i(z) & GSVector4i::x00000001());

            static float half = 0.5f;

            movss(temp1, dword[&half]);
            shufps(temp1, temp1, _MM_SHUFFLE(0, 0, 0, 0));
            mulps(temp1, xmm0);
            cvttps2dq(temp1, temp1);
            pslld(temp1, 1);

            cvttps2dq(xmm0, xmm0);
            pcmpeqd(temp2, temp2);
            psrld(temp2, 31);
            pand(xmm0, temp2);

            por(xmm0, temp1);
        }
        else
        {
            // zs = GSVector4i(z);

            cvttps2dq(xmm0, xmm0);
        }

        if(m_sel.zwrite)
        {
            movdqa(xmmword[&m_env.temp.zs], xmm0);
        }
    }

    if(m_sel.ztest)
    {
        ReadPixel(xmm1, ebp);

        if(m_sel.zwrite && m_sel.zpsm < 2)
        {
            movdqa(xmmword[&m_env.temp.zd], xmm1);
        }

        // zd &= 0xffffffff >> m_sel.zpsm * 8;

        if(m_sel.zpsm)
        {
            pslld(xmm1, m_sel.zpsm * 8);
            psrld(xmm1, m_sel.zpsm * 8);
        }

        if(m_sel.zoverflow || m_sel.zpsm == 0)
        {
            // GSVector4i o = GSVector4i::x80000000();

            pcmpeqd(xmm4, xmm4);
            pslld(xmm4, 31);

            // GSVector4i zso = zs - o;

            psubd(xmm0, xmm4);

            // GSVector4i zdo = zd - o;

            psubd(xmm1, xmm4);
        }

        switch(m_sel.ztst)
        {
        case ZTST_GEQUAL:
            // test |= zso < zdo; // ~(zso >= zdo)
            pcmpgtd(xmm1, xmm0);
            por(xmm7, xmm1);
            break;

        case ZTST_GREATER: // TODO: tidus hair and chocobo wings only appear fully when this is tested as ZTST_GEQUAL
            // test |= zso <= zdo; // ~(zso > zdo)
            pcmpgtd(xmm0, xmm1);
            pcmpeqd(xmm4, xmm4);
            pxor(xmm0, xmm4);
            por(xmm7, xmm0);
            break;
        }

        alltrue();
    }
}