3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * 3Dnow assembly code by Holger Waechtler
34 #include "norm_args.h"
38 #define M(i) REGOFF(i * 4, ECX)
39 #define STRIDE REGOFF(12, ESI)
43 GLOBL GLNAME(_mesa_3dnow_transform_normalize_normals)
44 HIDDEN(_mesa_3dnow_transform_normalize_normals)
45 GLNAME(_mesa_3dnow_transform_normalize_normals):
47 #define FRAME_OFFSET 12
53 MOV_L ( ARG_LENGTHS, EDI )
55 MOV_L ( ARG_DEST, EAX )
56 MOV_L ( REGOFF(V4F_COUNT, ESI), EBP ) /* dest->count = in->count */
57 MOV_L ( EBP, REGOFF(V4F_COUNT, EAX) )
58 MOV_L ( REGOFF(V4F_START, ESI), EDX ) /* in->start */
59 MOV_L ( REGOFF(V4F_START, EAX), EAX ) /* dest->start */
60 MOV_L ( ARG_MAT, ECX )
61 MOV_L ( REGOFF(MATRIX_INV, ECX), ECX ) /* mat->inv */
63 CMP_L ( CONST(0), EBP ) /* count > 0 ?? */
64 JE ( LLBL (G3TN_end) )
66 MOV_L ( REGOFF (V4F_COUNT, ESI), EBP )
71 PUSH_L ( EDX ) /* save counter & pointer for */
72 /* the normalize pass */
74 #define FRAME_OFFSET 24
76 MOVQ ( M(0), MM3 ) /* m1 | m0 */
77 MOVQ ( M(4), MM4 ) /* m5 | m4 */
79 MOVD ( M(2), MM5 ) /* | m2 */
80 PUNPCKLDQ ( M(6), MM5 ) /* m6 | m2 */
82 MOVQ ( M(8), MM6 ) /* m9 | m8 */
83 MOVQ ( M(10), MM7 ) /* | m10 */
85 CMP_L ( CONST(0), EDI ) /* lengths == 0 ? */
86 JNE ( LLBL (G3TN_scale_end ) )
88 MOVD ( ARG_SCALE, MM0 ) /* | scale */
89 PUNPCKLDQ ( MM0, MM0 ) /* scale | scale */
91 PFMUL ( MM0, MM3 ) /* scale * m1 | scale * m0 */
92 PFMUL ( MM0, MM4 ) /* scale * m5 | scale * m4 */
93 PFMUL ( MM0, MM5 ) /* scale * m6 | scale * m2 */
94 PFMUL ( MM0, MM6 ) /* scale * m9 | scale * m8 */
95 PFMUL ( MM0, MM7 ) /* | scale * m10 */
98 LLBL (G3TN_scale_end):
99 LLBL (G3TN_transform):
100 MOVQ ( REGIND (EDX), MM0 ) /* x1 | x0 */
101 MOVD ( REGOFF (8, EDX), MM2 ) /* | x2 */
103 MOVQ ( MM0, MM1 ) /* x1 | x0 */
104 PUNPCKLDQ ( MM2, MM2 ) /* x2 | x2 */
106 PFMUL ( MM3, MM0 ) /* x1*m1 | x0*m0 */
107 ADD_L ( CONST(16), EAX ) /* next r */
109 PREFETCHW ( REGIND(EAX) )
111 PFMUL ( MM4, MM1 ) /* x1*m5 | x0*m4 */
112 PFACC ( MM1, MM0 ) /* x0*m4+x1*m5 | x0*m0+x1*m1 */
114 PFMUL ( MM5, MM2 ) /* x2*m6 | x2*m2 */
115 PFADD ( MM2, MM0 ) /* x0*m4+x1*m5+x2*m6| x0*m0+...+x2**/
117 MOVQ ( REGIND (EDX), MM1 ) /* x1 | x0 */
118 MOVQ ( MM0, REGOFF(-16, EAX) ) /* write r0, r1 */
120 PFMUL ( MM6, MM1 ) /* x1*m9 | x0*m8 */
121 MOVD ( REGOFF (8, EDX), MM2 ) /* | x2 */
123 PFMUL ( MM7, MM2 ) /* | x2*m10 */
124 PFACC ( MM1, MM1 ) /* *not used* | x0*m8+x1*m9 */
126 PFADD ( MM2, MM1 ) /* *not used* | x0*m8+x1*m9+x2*m*/
127 ADD_L ( STRIDE, EDX ) /* next normal */
129 PREFETCH ( REGIND(EDX) )
131 MOVD ( MM1, REGOFF(-8, EAX) ) /* write r2 */
132 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
133 JNZ ( LLBL (G3TN_transform) )
136 POP_L ( EDX ) /* end of transform --- */
137 POP_L ( EAX ) /* now normalizing ... */
140 CMP_L ( CONST(0), EDI ) /* lengths == 0 ? */
141 JE ( LLBL (G3TN_norm ) ) /* calculate lengths */
145 LLBL (G3TN_norm_w_lengths):
147 PREFETCHW ( REGOFF(12,EAX) )
149 MOVQ ( REGIND(EAX), MM0 ) /* x1 | x0 */
150 MOVD ( REGOFF(8, EAX), MM1 ) /* | x2 */
152 MOVD ( REGIND (EDI), MM3 ) /* | length (x) */
153 PFMUL ( MM3, MM1 ) /* | x2 (normalize*/
155 PUNPCKLDQ ( MM3, MM3 ) /* length (x) | length (x) */
156 PFMUL ( MM3, MM0 ) /* x1 (normalized) | x0 (normalize*/
158 ADD_L ( STRIDE, EDX ) /* next normal */
159 ADD_L ( CONST(4), EDI ) /* next length */
161 PREFETCH ( REGIND(EDI) )
163 MOVQ ( MM0, REGIND(EAX) ) /* write new x0, x1 */
164 MOVD ( MM1, REGOFF(8, EAX) ) /* write new x2 */
166 ADD_L ( CONST(16), EAX ) /* next r */
167 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
169 JNZ ( LLBL (G3TN_norm_w_lengths) )
170 JMP ( LLBL (G3TN_exit_3dnow) )
175 PREFETCHW ( REGIND(EAX) )
177 MOVQ ( REGIND (EAX), MM0 ) /* x1 | x0 */
178 MOVD ( REGOFF(8, EAX), MM1 ) /* | x2 */
180 MOVQ ( MM0, MM3 ) /* x1 | x0 */
181 MOVQ ( MM1, MM4 ) /* | x2 */
183 PFMUL ( MM0, MM3 ) /* x1*x1 | x0*x0 */
184 ADD_L ( CONST(16), EAX ) /* next r */
186 PFMUL ( MM1, MM4 ) /* | x2*x2 */
187 PFADD ( MM4, MM3 ) /* | x0*x0+x2*x2 */
189 PFACC ( MM3, MM3 ) /* **not used** | x0*x0+x1*x1+x2**/
190 PFRSQRT ( MM3, MM5 ) /* 1/sqrt (x0*x0+x1*x1+x2*x2) */
193 PUNPCKLDQ ( MM3, MM3 )
195 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
198 PFRSQIT1 ( MM3, MM5 )
199 PFRCPIT2 ( MM4, MM5 )
201 PFMUL ( MM5, MM0 ) /* x1 (normalized) | x0 (normalize*/
203 MOVQ ( MM0, REGOFF(-16, EAX) ) /* write new x0, x1 */
204 PFMUL ( MM5, MM1 ) /* | x2 (normalize*/
206 MOVD ( MM1, REGOFF(-8, EAX) ) /* write new x2 */
207 JNZ ( LLBL (G3TN_norm) )
209 LLBL (G3TN_exit_3dnow):
221 GLOBL GLNAME(_mesa_3dnow_transform_normalize_normals_no_rot)
222 HIDDEN(_mesa_3dnow_transform_normalize_normals_no_rot)
223 GLNAME(_mesa_3dnow_transform_normalize_normals_no_rot):
226 #define FRAME_OFFSET 12
232 MOV_L ( ARG_LENGTHS, EDI )
233 MOV_L ( ARG_IN, ESI )
234 MOV_L ( ARG_DEST, EAX )
235 MOV_L ( REGOFF(V4F_COUNT, ESI), EBP ) /* dest->count = in->count */
236 MOV_L ( EBP, REGOFF(V4F_COUNT, EAX) )
237 MOV_L ( ARG_MAT, ECX )
238 MOV_L ( REGOFF(V4F_START, EAX), EAX ) /* dest->start */
239 MOV_L ( REGOFF(MATRIX_INV, ECX), ECX ) /* mat->inv */
240 MOV_L ( REGOFF(V4F_START, ESI), EDX ) /* in->start */
242 CMP_L ( CONST(0), EBP ) /* count > 0 ?? */
243 JE ( LLBL (G3TNNR_end) )
247 MOVD ( M(0), MM0 ) /* | m0 */
248 PUNPCKLDQ ( M(5), MM0 ) /* m5 | m0 */
250 MOVD ( M(10), MM2 ) /* | m10 */
251 PUNPCKLDQ ( MM2, MM2 ) /* m10 | m10 */
253 CMP_L ( CONST(0), EDI ) /* lengths == 0 ? */
254 JNE ( LLBL (G3TNNR_scale_end ) )
256 MOVD ( ARG_SCALE, MM7 ) /* | scale */
257 PUNPCKLDQ ( MM7, MM7 ) /* scale | scale */
259 PFMUL ( MM7, MM0 ) /* scale * m5 | scale * m0 */
260 PFMUL ( MM7, MM2 ) /* scale * m10 | scale * m10 */
263 LLBL (G3TNNR_scale_end):
264 CMP_L ( CONST(0), EDI ) /* lengths == 0 ? */
265 JE ( LLBL (G3TNNR_norm) ) /* need to calculate lengths */
267 MOVD ( REGIND(EDI), MM3 ) /* | length (x) */
271 LLBL (G3TNNR_norm_w_lengths): /* use precalculated lengths */
273 PREFETCHW ( REGIND(EAX) )
275 MOVQ ( REGIND(EDX), MM6 ) /* x1 | x0 */
276 MOVD ( REGOFF(8, EDX), MM7 ) /* | x2 */
278 PFMUL ( MM0, MM6 ) /* x1*m5 | x0*m0 */
279 ADD_L ( STRIDE, EDX ) /* next normal */
281 PREFETCH ( REGIND(EDX) )
283 PFMUL ( MM2, MM7 ) /* | x2*m10 */
284 ADD_L ( CONST(16), EAX ) /* next r */
286 PFMUL ( MM3, MM7 ) /* | x2 (normalized) */
287 PUNPCKLDQ ( MM3, MM3 ) /* length (x) | length (x) */
289 ADD_L ( CONST(4), EDI ) /* next length */
290 PFMUL ( MM3, MM6 ) /* x1 (normalized) | x0 (normalized) */
292 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
293 MOVQ ( MM6, REGOFF(-16, EAX) ) /* write r0, r1 */
295 MOVD ( MM7, REGOFF(-8, EAX) ) /* write r2 */
296 MOVD ( REGIND(EDI), MM3 ) /* | length (x) */
298 JNZ ( LLBL (G3TNNR_norm_w_lengths) )
299 JMP ( LLBL (G3TNNR_exit_3dnow) )
302 LLBL (G3TNNR_norm): /* need to calculate lengths */
304 PREFETCHW ( REGIND(EAX) )
306 MOVQ ( REGIND(EDX), MM6 ) /* x1 | x0 */
307 MOVD ( REGOFF(8, EDX), MM7 ) /* | x2 */
309 PFMUL ( MM0, MM6 ) /* x1*m5 | x0*m0 */
310 ADD_L ( CONST(16), EAX ) /* next r */
312 PFMUL ( MM2, MM7 ) /* | x2*m10 */
313 MOVQ ( MM6, MM3 ) /* x1 (transformed)| x0 (transformed) */
315 MOVQ ( MM7, MM4 ) /* | x2 (transformed) */
316 PFMUL ( MM6, MM3 ) /* x1*x1 | x0*x0 */
319 PFMUL ( MM7, MM4 ) /* | x2*x2 */
320 PFACC ( MM3, MM3 ) /* **not used** | x0*x0+x1*x1 */
322 PFADD ( MM4, MM3 ) /* | x0*x0+x1*x1+x2*x2*/
323 ADD_L ( STRIDE, EDX ) /* next normal */
325 PREFETCH ( REGIND(EDX) )
327 PFRSQRT ( MM3, MM5 ) /* 1/sqrt (x0*x0+x1*x1+x2*x2) */
330 PUNPCKLDQ ( MM3, MM3 )
333 PFRSQIT1 ( MM3, MM5 )
334 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
336 PFRCPIT2 ( MM4, MM5 )
337 PFMUL ( MM5, MM6 ) /* x1 (normalized) | x0 (normalized) */
339 MOVQ ( MM6, REGOFF(-16, EAX) ) /* write r0, r1 */
340 PFMUL ( MM5, MM7 ) /* | x2 (normalized) */
342 MOVD ( MM7, REGOFF(-8, EAX) ) /* write r2 */
343 JNZ ( LLBL (G3TNNR_norm) )
346 LLBL (G3TNNR_exit_3dnow):
361 GLOBL GLNAME(_mesa_3dnow_transform_rescale_normals_no_rot)
362 HIDDEN(_mesa_3dnow_transform_rescale_normals_no_rot)
363 GLNAME(_mesa_3dnow_transform_rescale_normals_no_rot):
366 #define FRAME_OFFSET 12
372 MOV_L ( ARG_IN, EAX )
373 MOV_L ( ARG_DEST, EDX )
374 MOV_L ( REGOFF(V4F_COUNT, EAX), EBP ) /* dest->count = in->count */
375 MOV_L ( EBP, REGOFF(V4F_COUNT, EDX) )
376 MOV_L ( ARG_IN, ESI )
377 MOV_L ( ARG_MAT, ECX )
378 MOV_L ( REGOFF(MATRIX_INV, ECX), ECX ) /* mat->inv */
379 MOV_L ( REGOFF(V4F_START, EDX), EAX ) /* dest->start */
380 MOV_L ( REGOFF(V4F_START, ESI), EDX ) /* in->start */
382 CMP_L ( CONST(0), EBP )
383 JE ( LLBL (G3TRNR_end) )
387 MOVD ( ARG_SCALE, MM6 ) /* | scale */
388 PUNPCKLDQ ( MM6, MM6 ) /* scale | scale */
390 MOVD ( REGIND(ECX), MM0 ) /* | m0 */
391 PUNPCKLDQ ( REGOFF(20, ECX), MM0 ) /* m5 | m0 */
393 PFMUL ( MM6, MM0 ) /* scale*m5 | scale*m0 */
394 MOVD ( REGOFF(40, ECX), MM2 ) /* | m10 */
396 PFMUL ( MM6, MM2 ) /* | scale*m10 */
399 LLBL (G3TRNR_rescale):
401 PREFETCHW ( REGIND(EAX) )
403 MOVQ ( REGIND(EDX), MM4 ) /* x1 | x0 */
404 MOVD ( REGOFF(8, EDX), MM5 ) /* | x2 */
406 PFMUL ( MM0, MM4 ) /* x1*m5 | x0*m0 */
407 ADD_L ( STRIDE, EDX ) /* next normal */
409 PREFETCH ( REGIND(EDX) )
411 PFMUL ( MM2, MM5 ) /* | x2*m10 */
412 ADD_L ( CONST(16), EAX ) /* next r */
414 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
415 MOVQ ( MM4, REGOFF(-16, EAX) ) /* write r0, r1 */
417 MOVD ( MM5, REGOFF(-8, EAX) ) /* write r2 */
418 JNZ ( LLBL (G3TRNR_rescale) ) /* cnt > 0 ? -> process next normal */
433 GLOBL GLNAME(_mesa_3dnow_transform_rescale_normals)
434 HIDDEN(_mesa_3dnow_transform_rescale_normals)
435 GLNAME(_mesa_3dnow_transform_rescale_normals):
438 #define FRAME_OFFSET 8
443 MOV_L ( ARG_IN, ESI )
444 MOV_L ( ARG_DEST, EAX )
445 MOV_L ( ARG_MAT, ECX )
446 MOV_L ( REGOFF(V4F_COUNT, ESI), EDI ) /* dest->count = in->count */
447 MOV_L ( EDI, REGOFF(V4F_COUNT, EAX) )
448 MOV_L ( REGOFF(V4F_START, EAX), EAX ) /* dest->start */
449 MOV_L ( REGOFF(V4F_START, ESI), EDX ) /* in->start */
450 MOV_L ( REGOFF(MATRIX_INV, ECX), ECX ) /* mat->inv */
452 CMP_L ( CONST(0), EDI )
453 JE ( LLBL (G3TR_end) )
457 MOVQ ( REGIND(ECX), MM3 ) /* m1 | m0 */
459 MOVQ ( REGOFF(16,ECX), MM4 ) /* m5 | m4 */
460 MOVD ( ARG_SCALE, MM0 ) /* scale */
462 MOVD ( REGOFF(8,ECX), MM5 ) /* | m2 */
463 PUNPCKLDQ ( MM0, MM0 ) /* scale | scale */
465 PUNPCKLDQ ( REGOFF(24, ECX), MM5 )
466 PFMUL ( MM0, MM3 ) /* scale*m1 | scale*m0 */
468 MOVQ ( REGOFF(32, ECX), MM6 ) /* m9 | m8*/
469 PFMUL ( MM0, MM4 ) /* scale*m5 | scale*m4 */
471 MOVD ( REGOFF(40, ECX), MM7 ) /* | m10 */
472 PFMUL ( MM0, MM5 ) /* scale*m6 | scale*m2 */
474 PFMUL ( MM0, MM6 ) /* scale*m9 | scale*m8 */
476 PFMUL ( MM0, MM7 ) /* | scale*m10 */
481 PREFETCHW ( REGIND(EAX) )
483 MOVQ ( REGIND(EDX), MM0 ) /* x1 | x0 */
484 MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */
486 MOVQ ( MM0, MM1 ) /* x1 | x0 */
487 PUNPCKLDQ ( MM2, MM2 ) /* x2 | x2 */
489 PFMUL ( MM3, MM0 ) /* x1*m1 | x0*m0 */
490 ADD_L ( CONST(16), EAX ) /* next r */
492 PFMUL ( MM4, MM1 ) /* x1*m5 | x0*m4 */
493 PFACC ( MM1, MM0 ) /* x0*m4+x1*m5 | x0*m0+x1*m1 */
495 MOVQ ( REGIND(EDX), MM1 ) /* x1 | x0 */
497 PFMUL ( MM5, MM2 ) /* x2*m6 | x2*m2 */
498 PFADD ( MM2, MM0 ) /* x0*m4...+x2*m6| x0*m0+x1*m1+x2*m2 */
500 MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */
501 ADD_L ( STRIDE, EDX ) /* next normal */
503 PREFETCH ( REGIND(EDX) )
505 MOVQ ( MM0, REGOFF(-16, EAX) ) /* write r0, r1 */
506 PFMUL ( MM6, MM1 ) /* x1*m9 | x0*m8 */
508 PFMUL ( MM7, MM2 ) /* | x2*m10 */
509 PFACC ( MM1, MM1 ) /* *not used* | x0*m8+x1*m9 */
511 PFADD ( MM2, MM1 ) /* *not used* | x0*m8+x1*m9+x2*m10 */
512 MOVD ( MM1, REGOFF(-8, EAX) ) /* write r2 */
514 SUB_L ( CONST(1), EDI ) /* decrement normal counter */
515 JNZ ( LLBL (G3TR_rescale) )
531 GLOBL GLNAME(_mesa_3dnow_transform_normals_no_rot)
532 HIDDEN(_mesa_3dnow_transform_normals_no_rot)
533 GLNAME(_mesa_3dnow_transform_normals_no_rot):
536 #define FRAME_OFFSET 8
541 MOV_L ( ARG_IN, ESI )
542 MOV_L ( ARG_DEST, EAX )
543 MOV_L ( ARG_MAT, ECX )
544 MOV_L ( REGOFF(V4F_COUNT, ESI), EDI ) /* dest->count = in->count */
545 MOV_L ( EDI, REGOFF(V4F_COUNT, EAX) )
546 MOV_L ( REGOFF(V4F_START, EAX), EAX ) /* dest->start */
547 MOV_L ( REGOFF(V4F_START, ESI), EDX ) /* in->start */
548 MOV_L ( REGOFF(MATRIX_INV, ECX), ECX ) /* mat->inv */
550 CMP_L ( CONST(0), EDI )
551 JE ( LLBL (G3TNR_end) )
555 MOVD ( REGIND(ECX), MM0 ) /* | m0 */
556 PUNPCKLDQ ( REGOFF(20, ECX), MM0 ) /* m5 | m0 */
558 MOVD ( REGOFF(40, ECX), MM2 ) /* | m10 */
559 PUNPCKLDQ ( MM2, MM2 ) /* m10 | m10 */
562 LLBL (G3TNR_transform):
564 PREFETCHW ( REGIND(EAX) )
566 MOVQ ( REGIND(EDX), MM4 ) /* x1 | x0 */
567 MOVD ( REGOFF(8, EDX), MM5 ) /* | x2 */
569 PFMUL ( MM0, MM4 ) /* x1*m5 | x0*m0 */
570 ADD_L ( STRIDE, EDX) /* next normal */
572 PREFETCH ( REGIND(EDX) )
574 PFMUL ( MM2, MM5 ) /* | x2*m10 */
575 ADD_L ( CONST(16), EAX ) /* next r */
577 SUB_L ( CONST(1), EDI ) /* decrement normal counter */
578 MOVQ ( MM4, REGOFF(-16, EAX) ) /* write r0, r1 */
580 MOVD ( MM5, REGOFF(-8, EAX) ) /* write r2 */
581 JNZ ( LLBL (G3TNR_transform) )
598 GLOBL GLNAME(_mesa_3dnow_transform_normals)
599 HIDDEN(_mesa_3dnow_transform_normals)
600 GLNAME(_mesa_3dnow_transform_normals):
603 #define FRAME_OFFSET 8
608 MOV_L ( ARG_IN, ESI )
609 MOV_L ( ARG_DEST, EAX )
610 MOV_L ( ARG_MAT, ECX )
611 MOV_L ( REGOFF(V4F_COUNT, ESI), EDI ) /* dest->count = in->count */
612 MOV_L ( EDI, REGOFF(V4F_COUNT, EAX) )
613 MOV_L ( REGOFF(V4F_START, EAX), EAX ) /* dest->start */
614 MOV_L ( REGOFF(V4F_START, ESI), EDX ) /* in->start */
615 MOV_L ( REGOFF(MATRIX_INV, ECX), ECX ) /* mat->inv */
617 CMP_L ( CONST(0), EDI ) /* count > 0 ?? */
618 JE ( LLBL (G3T_end) )
622 MOVQ ( REGIND(ECX), MM3 ) /* m1 | m0 */
623 MOVQ ( REGOFF(16, ECX), MM4 ) /* m5 | m4 */
625 MOVD ( REGOFF(8, ECX), MM5 ) /* | m2 */
626 PUNPCKLDQ ( REGOFF(24, ECX), MM5 ) /* m6 | m2 */
628 MOVQ ( REGOFF(32, ECX), MM6 ) /* m9 | m8 */
629 MOVD ( REGOFF(40, ECX), MM7 ) /* | m10 */
632 LLBL (G3T_transform):
634 PREFETCHW ( REGIND(EAX) )
636 MOVQ ( REGIND(EDX), MM0 ) /* x1 | x0 */
637 MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */
639 MOVQ ( MM0, MM1 ) /* x1 | x0 */
640 PUNPCKLDQ ( MM2, MM2 ) /* x2 | x2 */
642 PFMUL ( MM3, MM0 ) /* x1*m1 | x0*m0 */
643 ADD_L ( CONST(16), EAX ) /* next r */
645 PFMUL ( MM4, MM1 ) /* x1*m5 | x0*m4 */
646 PFACC ( MM1, MM0 ) /* x0*m4+x1*m5 | x0*m0+x1*m1 */
648 PFMUL ( MM5, MM2 ) /* x2*m6 | x2*m2 */
649 PFADD ( MM2, MM0 ) /* x0*m4...+x2*m6| x0*m0+x1*m1+x2*m2 */
651 MOVQ ( REGIND(EDX), MM1 ) /* x1 | x0 */
652 MOVQ ( MM0, REGOFF(-16, EAX) ) /* write r0, r1 */
654 PFMUL ( MM6, MM1 ) /* x1*m9 | x0*m8 */
655 MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */
657 PFMUL ( MM7, MM2 ) /* | x2*m10 */
658 ADD_L ( STRIDE, EDX ) /* next normal */
660 PREFETCH ( REGIND(EDX) )
662 PFACC ( MM1, MM1 ) /* *not used* | x0*m8+x1*m9 */
663 PFADD ( MM2, MM1 ) /* *not used* | x0*m8+x1*m9+x2*m10 */
665 MOVD ( MM1, REGOFF(-8, EAX) ) /* write r2 */
666 SUB_L ( CONST(1), EDI ) /* decrement normal counter */
668 JNZ ( LLBL (G3T_transform) )
683 GLOBL GLNAME(_mesa_3dnow_normalize_normals)
684 HIDDEN(_mesa_3dnow_normalize_normals)
685 GLNAME(_mesa_3dnow_normalize_normals):
688 #define FRAME_OFFSET 12
694 MOV_L ( ARG_IN, ESI )
695 MOV_L ( ARG_DEST, EAX )
696 MOV_L ( REGOFF(V4F_COUNT, ESI), EBP ) /* dest->count = in->count */
697 MOV_L ( EBP, REGOFF(V4F_COUNT, EAX) )
698 MOV_L ( REGOFF(V4F_START, EAX), EAX ) /* dest->start */
699 MOV_L ( REGOFF(V4F_START, ESI), ECX ) /* in->start */
700 MOV_L ( ARG_LENGTHS, EDX )
702 CMP_L ( CONST(0), EBP ) /* count > 0 ?? */
703 JE ( LLBL (G3N_end) )
707 CMP_L ( CONST(0), EDX ) /* lengths == 0 ? */
708 JE ( LLBL (G3N_norm2) ) /* calculate lengths */
711 LLBL (G3N_norm1): /* use precalculated lengths */
713 PREFETCH ( REGIND(EAX) )
715 MOVQ ( REGIND(ECX), MM0 ) /* x1 | x0 */
716 MOVD ( REGOFF(8, ECX), MM1 ) /* | x2 */
718 MOVD ( REGIND(EDX), MM3 ) /* | length (x) */
719 PFMUL ( MM3, MM1 ) /* | x2 (normalized) */
721 PUNPCKLDQ ( MM3, MM3 ) /* length (x) | length (x) */
722 ADD_L ( STRIDE, ECX ) /* next normal */
724 PREFETCH ( REGIND(ECX) )
726 PFMUL ( MM3, MM0 ) /* x1 (normalized) | x0 (normalized) */
727 MOVQ ( MM0, REGIND(EAX) ) /* write new x0, x1 */
729 MOVD ( MM1, REGOFF(8, EAX) ) /* write new x2 */
730 ADD_L ( CONST(16), EAX ) /* next r */
732 ADD_L ( CONST(4), EDX ) /* next length */
733 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
735 JNZ ( LLBL (G3N_norm1) )
737 JMP ( LLBL (G3N_end1) )
740 LLBL (G3N_norm2): /* need to calculate lengths */
742 PREFETCHW ( REGIND(EAX) )
744 PREFETCH ( REGIND(ECX) )
746 MOVQ ( REGIND(ECX), MM0 ) /* x1 | x0 */
747 MOVD ( REGOFF(8, ECX), MM1 ) /* | x2 */
749 MOVQ ( MM0, MM3 ) /* x1 | x0 */
750 ADD_L ( STRIDE, ECX ) /* next normal */
752 PFMUL ( MM0, MM3 ) /* x1*x1 | x0*x0 */
753 MOVQ ( MM1, MM4 ) /* | x2 */
755 ADD_L ( CONST(16), EAX ) /* next r */
756 PFMUL ( MM1, MM4 ) /* | x2*x2 */
758 PFADD ( MM4, MM3 ) /* | x0*x0+x2*x2 */
759 PFACC ( MM3, MM3 ) /* x0*x0+...+x2*x2 | x0*x0+x1*x1+x2*x2*/
761 PFRSQRT ( MM3, MM5 ) /* 1/sqrt (x0*x0+x1*x1+x2*x2) */
764 PUNPCKLDQ ( MM3, MM3 )
767 PFRSQIT1 ( MM3, MM5 )
768 SUB_L ( CONST(1), EBP ) /* decrement normal counter */
770 PFRCPIT2 ( MM4, MM5 )
772 PFMUL ( MM5, MM0 ) /* x1 (normalized) | x0 (normalized) */
773 MOVQ ( MM0, REGOFF(-16, EAX) ) /* write new x0, x1 */
775 PFMUL ( MM5, MM1 ) /* | x2 (normalized) */
776 MOVD ( MM1, REGOFF(-8, EAX) ) /* write new x2 */
778 JNZ ( LLBL (G3N_norm2) )
795 GLOBL GLNAME(_mesa_3dnow_rescale_normals)
796 HIDDEN(_mesa_3dnow_rescale_normals)
797 GLNAME(_mesa_3dnow_rescale_normals):
800 #define FRAME_OFFSET 8
804 MOV_L ( ARG_IN, ESI )
805 MOV_L ( ARG_DEST, EAX )
806 MOV_L ( REGOFF(V4F_COUNT, ESI), EDX ) /* dest->count = in->count */
807 MOV_L ( EDX, REGOFF(V4F_COUNT, EAX) )
808 MOV_L ( REGOFF(V4F_START, EAX), EAX ) /* dest->start */
809 MOV_L ( REGOFF(V4F_START, ESI), ECX ) /* in->start */
811 CMP_L ( CONST(0), EDX )
812 JE ( LLBL (G3R_end) )
816 MOVD ( ARG_SCALE, MM0 ) /* scale */
817 PUNPCKLDQ ( MM0, MM0 )
822 PREFETCHW ( REGIND(EAX) )
824 MOVQ ( REGIND(ECX), MM1 ) /* x1 | x0 */
825 MOVD ( REGOFF(8, ECX), MM2 ) /* | x2 */
827 PFMUL ( MM0, MM1 ) /* x1*scale | x0*scale */
828 ADD_L ( STRIDE, ECX ) /* next normal */
830 PREFETCH ( REGIND(ECX) )
832 PFMUL ( MM0, MM2 ) /* | x2*scale */
833 ADD_L ( CONST(16), EAX ) /* next r */
835 MOVQ ( MM1, REGOFF(-16, EAX) ) /* write r0, r1 */
836 MOVD ( MM2, REGOFF(-8, EAX) ) /* write r2 */
838 SUB_L ( CONST(1), EDX ) /* decrement normal counter */
839 JNZ ( LLBL (G3R_rescale) )
850 #if defined (__ELF__) && defined (__linux__)
851 .section .note.GNU-stack,"",%progbits