// mmx.cpp :
// C(t) = (1-t)*C1 + t*C2
#include <conio.h>
#include <stdio.h>
typedef struct { char r,g,b,a;} color;
__fastcall void FPUBlendColor(float t,color c1,color c2,color& c) {
float k = 1-t;
c.r = k*c1.r+t*c2.r;
c.g = k*c1.g+t*c2.g;
c.b = k*c1.b+t*c2.b;
}
__fastcall void MMXBlendColor(float t,color c1,color c2,color& c) {
DWORD a,b;
DWORD x = 256;
if (t==0) {c = c1;goto skip;}
if (t==1) {c = c2;goto skip;}
__asm {
fld t
fimul x
fistp a
mov eax,256
sub eax,a
mov b,eax
emms
imul eax,a,010101h //ecx // eax = 0aaa
movd mm2,eax
imul ebx,b,010101h //ebx =0bbb
movd mm3,ebx
pxor mm4,mm4
punpcklbw mm2,mm4 // mm2 =w(0,a,a,a)
punpcklbw mm3,mm4 // mm3 =w(0,b,b,b)
mov eax,dword ptr c2
movd mm0,eax
punpcklbw mm0,mm4 // mm0 =(0,b1,g1,r1)
mov eax,dword ptr c1
movd mm1,eax
punpcklbw mm1,mm4 // mm1 = (0,b2,g2,r2)
pmullw mm0,mm2 // mm0 = (0,a*b1,a*g1,a*r1)
pmullw mm1,mm3 // mm1 = (0,b*b2,b*g2,b*r2)
paddw mm0,mm1 // mm0 = (0,a*b1+b*b2,a*g1+b*g2,a*r1+b*r2)
psrlw mm0,8 // mm0/256
packuswb mm0,mm0 // mm0 =(0,0,0,0,0,r,g,b)
movd eax,mm0
mov ebx,c
mov [ebx],eax
emms
}
skip: ;
}
int main(int argc, char* argv[])
{color c={0,0,0,0};
color c1={255,20,20};
color c2 = {255,200,0};
float t = 0.2;
MMXBlendColor(t,c1,c2,c);
printf("mmx ->%d %d %d\n",c.r,c.g,c.b);
FPUBlendColor(t,c1,c2,c);
printf("fpu ->%d %d %d\n",c.r,c.g,c.b);
getch();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire