1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar/*
2c83ed049af2a2ed7ab94b8206fc0fec4da7e26dbDouglas Gregor * Written by Jos� Fonseca <j_r_fonseca@yahoo.co.uk>
3b5a57a69e5fdac6dd9a92be717e279486c4a0128Sebastian Redl */
4b5a57a69e5fdac6dd9a92be717e279486c4a0128Sebastian Redl
54c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
64c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/*
74c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl * void _mesa_mmx_blend( struct gl_context *ctx,
83cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl *                       GLuint n,
93cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl *                       const GLubyte mask[],
104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl *                       GLchan rgba[][4],
117c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall *                       CONST GLchan dest[][4] )
12636a7c42d42800f69caadcdea433312fd642a4b3Sebastian Redl *
13636a7c42d42800f69caadcdea433312fd642a4b3Sebastian Redl */
14636a7c42d42800f69caadcdea433312fd642a4b3Sebastian RedlALIGNTEXT16
159afe1308ed19dffc281dca5cfbe521826754980fSebastian RedlGLOBL GLNAME( TAG(_mesa_mmx_blend) )
16636a7c42d42800f69caadcdea433312fd642a4b3Sebastian RedlHIDDEN( TAG(_mesa_mmx_blend) )
177f6623914e779e41eb3d85f9a2dc3affea5de1e8Sebastian RedlGLNAME( TAG(_mesa_mmx_blend) ):
187f6623914e779e41eb3d85f9a2dc3affea5de1e8Sebastian Redl
197f6623914e779e41eb3d85f9a2dc3affea5de1e8Sebastian Redl    PUSH_L     ( EBP )
204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    MOV_L      ( ESP, EBP )
216e790ab61bf4835944971955e84279112833ef0cDouglas Gregor    PUSH_L     ( ESI )
226e790ab61bf4835944971955e84279112833ef0cDouglas Gregor    PUSH_L     ( EDI )
233cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl    PUSH_L     ( EBX )
243cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl
25fc27d268cb34cbb8d186c6ad7cc043d41581ce71Anders Carlsson    MOV_L      ( REGOFF(12, EBP), ECX )		/* n */
26b5a57a69e5fdac6dd9a92be717e279486c4a0128Sebastian Redl    CMP_L      ( CONST(0), ECX)
273caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor    JE         ( LLTAG(GMB_return) )
283caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor
294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    MOV_L      ( REGOFF(16, EBP), EBX )		/* mask */
304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    MOV_L      ( REGOFF(20, EBP), EDI )         /* rgba */
314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    MOV_L      ( REGOFF(24, EBP), ESI )         /* dest */
324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    INIT
344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    TEST_L     ( CONST(4), EDI )		/* align rgba on an 8-byte boundary */
364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    JZ         ( LLTAG(GMB_align_end) )
37cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    CMP_B      ( CONST(0), REGIND(EBX) )	/* *mask == 0 */
394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    JE         ( LLTAG(GMB_align_continue) )
404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
41fb4ccd7152723ac6190eb379250cfe7516cfd1b8Sebastian Redl    /* runin */
42636a7c42d42800f69caadcdea433312fd642a4b3Sebastian Redl#define ONE(x)	x
435d64e5b6bc03462e8b7d0cd804565829afb1b508Douglas Gregor#define TWO(x)
44fc27d268cb34cbb8d186c6ad7cc043d41581ce71Anders Carlsson    MAIN       ( EDI, ESI )
45fc27d268cb34cbb8d186c6ad7cc043d41581ce71Anders Carlsson#undef ONE
46ac18b2e3af8d0c5304f74e362a1d4207363e4c94Anders Carlsson#undef TWO
47ac18b2e3af8d0c5304f74e362a1d4207363e4c94Anders Carlsson
483caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas GregorLLTAG(GMB_align_continue):
493caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor
503caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor    DEC_L      ( ECX )				/* n -= 1 */
513caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor    INC_L      ( EBX )		                /* mask += 1 */
523caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor    ADD_L      ( CONST(4), EDI )		/* rgba += 1 */
533caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor    ADD_L      ( CONST(4), ESI )		/* dest += 1 */
543caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas Gregor
553caf04ea0c01ff6822209c4621c3fa64a48029a4Douglas GregorLLTAG(GMB_align_end):
564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    CMP_L      ( CONST(2), ECX)
58e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas Gregor    JB         ( LLTAG(GMB_loop_end) )
59e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas Gregor
60e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas GregorALIGNTEXT16
61e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas GregorLLTAG(GMB_loop_begin):
62c83ed049af2a2ed7ab94b8206fc0fec4da7e26dbDouglas Gregor
634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    CMP_W      ( CONST(0), REGIND(EBX) )	/* *mask == 0 && *(mask + 1) == 0 */
644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    JE         ( LLTAG(GMB_loop_continue) )
654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    /* main loop */
674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl#define ONE(x)
68cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl#define TWO(x)	x
694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    MAIN       ( EDI, ESI )
704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl#undef ONE
714bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor#undef TWO
727c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall
7399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas GregorLLTAG(GMB_loop_continue):
744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
757c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall    DEC_L      ( ECX )
7699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    DEC_L      ( ECX )				/* n -= 2 */
77a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    ADD_L      ( CONST(2), EBX )		/* mask += 2 */
78cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    ADD_L      ( CONST(8), EDI )		/* rgba += 2 */
79cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    ADD_L      ( CONST(8), ESI )		/* dest += 2 */
807c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall    CMP_L      ( CONST(2), ECX )
81fb4ccd7152723ac6190eb379250cfe7516cfd1b8Sebastian Redl    JAE        ( LLTAG(GMB_loop_begin) )
82b5a57a69e5fdac6dd9a92be717e279486c4a0128Sebastian Redl
837f6623914e779e41eb3d85f9a2dc3affea5de1e8Sebastian RedlLLTAG(GMB_loop_end):
84636a7c42d42800f69caadcdea433312fd642a4b3Sebastian Redl
85636a7c42d42800f69caadcdea433312fd642a4b3Sebastian Redl    CMP_L      ( CONST(1), ECX )
869afe1308ed19dffc281dca5cfbe521826754980fSebastian Redl    JB         ( LLTAG(GMB_done) )
879afe1308ed19dffc281dca5cfbe521826754980fSebastian Redl
8800e68e2cc5ce37cb95beb801cae73c0d1e9dda37Sebastian Redl    CMP_B      ( CONST(0), REGIND(EBX) )	/* *mask == 0 */
8900e68e2cc5ce37cb95beb801cae73c0d1e9dda37Sebastian Redl    JE         ( LLTAG(GMB_done) )
904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    /* runout */
924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl#define ONE(x)	x
934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl#define TWO(x)
944c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    MAIN       ( EDI, ESI )
954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl#undef ONE
964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl#undef TWO
974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
98fb4ccd7152723ac6190eb379250cfe7516cfd1b8Sebastian RedlLLTAG(GMB_done):
994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    EMMS
1014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian RedlLLTAG(GMB_return):
1034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    POP_L      ( EBX )
10528eb7e992b9a266abb300da25b6d3c1557cec361Chris Lattner    POP_L      ( EDI )
10694a615718d06704816c6e31a811f823c05e39f52Douglas Gregor    POP_L      ( ESI )
1074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    MOV_L      ( EBP, ESP )
108fb4ccd7152723ac6190eb379250cfe7516cfd1b8Sebastian Redl    POP_L      ( EBP )
1094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    RET
1109cd9f3f55d22f34f1d69db8bfc2735c4e1e082c3Douglas Gregor
1119cd9f3f55d22f34f1d69db8bfc2735c4e1e082c3Douglas Gregor#undef TAG
1129cd9f3f55d22f34f1d69db8bfc2735c4e1e082c3Douglas Gregor#undef LLTAG
1139cd9f3f55d22f34f1d69db8bfc2735c4e1e082c3Douglas Gregor#undef INIT
1149cd9f3f55d22f34f1d69db8bfc2735c4e1e082c3Douglas Gregor#undef MAIN
1159cd9f3f55d22f34f1d69db8bfc2735c4e1e082c3Douglas Gregor