summaryrefslogtreecommitdiff
path: root/xc/extras/Mesa/src/X86/katmai_norm_raw.S
blob: 6ac046d5fdfe5b609473d7c1c6139a3cea641930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "assyntax.h"
/** TODO:
  * - insert PREFETCH instructions to avoid cache-misses !
  * - some more optimizations are possible...
  * - for 40-50% more performance in the SSE-functions, the
  *   data (trans-matrix, src_vert, dst_vert) needs to be 16byte aligned !	
  */
	
   SEG_TEXT


#if !defined(NASM_ASSEMBLER) && !defined(MASM_ASSEMBLER)
#define LLBL(a) .L ## a
#else
#define LLBL(a) a
#endif

#define OFFSET_MAT 4
#define OFFSET_SCALE 8
#define OFFSET_IN 12
#define OFFSET_LENGTHS 16
#define OFFSET_MASK 20
#define OFFSET_DEST 24

#define ARG_MAT         REGOFF(FRAME_OFFSET+OFFSET_MAT, ESP)
#define ARG_SCALE       REGOFF(FRAME_OFFSET+OFFSET_SCALE, ESP)
#define ARG_IN          REGOFF(FRAME_OFFSET+OFFSET_IN, ESP)
#define ARG_LENGTHS     REGOFF(FRAME_OFFSET+OFFSET_LENGTHS, ESP)
#define ARG_MASK        REGOFF(FRAME_OFFSET+OFFSET_MASK, ESP)
#define ARG_DEST        REGOFF(FRAME_OFFSET+OFFSET_DEST, ESP)


#define V3F_START       4
#define V3F_COUNT       8
#define V3F_STRIDE      12

#define MAT_INV         64

#define M(i)    REGOFF(i * 4, EDX)
#define S(i)	REGOFF(i * 4, ESI)
#define D(i)	REGOFF(i * 4, EDI)
#define STRIDE  REGOFF(12, ESI)
	
#undef FRAME_OFFSET
		
/*
 *	Offsets for norm_func arguments
 *
 * static void TAG(transform_rescale_normals_no_rot)( const GLmatrix *mat,
 *						   GLfloat scale,
 *						   const GLvector3f *in,
 *						   const GLfloat *lengths,
 *						   const GLubyte mask[],
 *						   GLvector3f *dest )
 */

ALIGNTEXT16
GLOBL GLNAME(gl_katmai_transform_rescale_normals_no_rot_raw)
GLNAME(gl_katmai_transform_rescale_normals_no_rot_raw):

#define FRAME_OFFSET 8
	PUSH_L  ( ESI )
	PUSH_L  ( EDI )

	MOV_L	( ARG_IN, ESI )				/* ptr to source GLvector3f */
	MOV_L	( ARG_DEST, EDI )			/* ptr to dest GLvector3f */

	MOV_L	( ARG_MAT, EDX )			/* ptr to matrix */
	MOV_L	( REGOFF(MAT_INV, EDX), EDX)		/* matrix->inv */

	MOV_L	( REGOFF(V3F_COUNT, ESI), ECX ) 	/* source count */

	TEST_L	( ECX, ECX )
	JZ( LLBL(K_G3TRNNRR_finish) )			/* count was zero; go to finish */

	MOV_L	( STRIDE, EAX )				/* stride */
	MOV_L	( ECX, REGOFF(V3F_COUNT, EDI) )		/* set dest-count */

	IMUL_L( CONST(12), ECX )			/* count *= 12 */
	MOV_L( REGOFF(V3F_START, ESI), ESI )		/* ptr to first source vertex */

	MOV_L( REGOFF(V3F_START, EDI), EDI )		/* ptr to first dest vertex */
	ADD_L( EDI, ECX ) 				/* count += dest ptr */

ALIGNTEXT32
	MOVSS	( M(0), XMM1 )				/* m0 */
	MOVSS	( M(5), XMM2 )				/* m5 */
	UNPCKLPS( XMM2, XMM1 )				/* m5 | m0 */
	MOVSS	( ARG_SCALE, XMM0 )			/* scale */
	SHUFPS	( CONST(0x0), XMM0, XMM0 )		/* scale | scale */
	MULPS	( XMM0, XMM1 )				/* m5*scale | m0*scale */
	MULSS	( M(10), XMM0 )				/* m10*scale */

ALIGNTEXT32
LLBL(K_G3TRNNRR_top):
	MOVLPS	( S(0), XMM2 )				/* uy | ux */
	MULPS	( XMM1, XMM2 )				/* uy*m5*scale | ux*m0*scale */
	MOVLPS	( XMM2, D(0) )				/* ->D(1) | D(0) */

	MOVSS	( S(2), XMM2 )				/* uz */
	MULSS	( XMM0, XMM2 )				/* uz*m10*scale */
	MOVSS	( XMM2, D(2) )				/* ->D(2) */

LLBL(K_G3TRNNRR_skip):
	ADD_L	( CONST(12), EDI )
	ADD_L	( EAX, ESI )
	CMP_L	( ECX, EDI )
	JNE	( LLBL(K_G3TRNNRR_top) )

LLBL(K_G3TRNNRR_finish):
	POP_L	( EDI )
	POP_L	( ESI )
	RET
#undef FRAME_OFFSET

	

ALIGNTEXT16
GLOBL GLNAME(gl_katmai_transform_rescale_normals_raw)
GLNAME(gl_katmai_transform_rescale_normals_raw):

#define FRAME_OFFSET 8
	PUSH_L  ( ESI )
	PUSH_L  ( EDI )

	MOV_L	( ARG_IN, ESI )				/* ptr to source GLvector3f */
	MOV_L	( ARG_DEST, EDI )			/* ptr to dest GLvector3f */

	MOV_L	( ARG_MAT, EDX )			/* ptr to matrix */
	MOV_L	( REGOFF(MAT_INV, EDX), EDX)		/* matrix->inv */

	MOV_L	( REGOFF(V3F_COUNT, ESI), ECX ) 	/* source count */

	TEST_L	( ECX, ECX )
	JZ( LLBL(K_G3TRNR_finish) )			/* count was zero; go to finish */

	MOV_L	( STRIDE, EAX )				/* stride */
	MOV_L	( ECX, REGOFF(V3F_COUNT, EDI) )		/* set dest-count */

	IMUL_L( CONST(12), ECX )			/* count *= 12 */
	MOV_L( REGOFF(V3F_START, ESI), ESI )		/* ptr to first source vertex */

	MOV_L( REGOFF(V3F_START, EDI), EDI )		/* ptr to first dest vertex */
	ADD_L( EDI, ECX ) 				/* count += dest ptr */
	
ALIGNTEXT32
	MOVSS	( M(0), XMM0 )				/* m0 */
	MOVSS	( M(4), XMM1 )				/* m4 */
	UNPCKLPS( XMM1, XMM0 )				/* m4 | m0 */

	MOVSS	( ARG_SCALE, XMM4 )			/* scale */
	SHUFPS	( CONST(0x0), XMM4, XMM4 )		/* scale | scale */
	
	MULPS	( XMM4, XMM0 )				/* m4*scale | m0*scale */
	MOVSS	( M(1), XMM1 )				/* m1 */
	MOVSS	( M(5), XMM2 )				/* m5 */
	UNPCKLPS( XMM2, XMM1 )				/* m5 | m1 */
	MULPS	( XMM4, XMM1 )				/* m5*scale | m1*scale */
	MOVSS	( M(2), XMM2 )				/* m2 */
	MOVSS	( M(6), XMM3 )				/* m6 */
	UNPCKLPS( XMM3, XMM2 )				/* m6 | m2 */
	MULPS	( XMM4, XMM2 )				/* m6*scale | m2*scale */

	MOVSS	( M(8), XMM6 )				/* m8 */
	MULSS	( ARG_SCALE, XMM6 )			/* m8*scale */
	MOVSS	( M(9), XMM7 )				/* m9 */
	MULSS	( ARG_SCALE, XMM7 )			/* m9*scale */
	
ALIGNTEXT32
LLBL(K_G3TRNR_top):
	MOVSS	( S(0), XMM3 )				/* ux */
	SHUFPS	( CONST(0x0), XMM3, XMM3 )		/* ux | ux */
	MULPS	( XMM0, XMM3 )				/* ux*m4 | ux*m0 */
	MOVSS	( S(1), XMM4 )				/* uy */
	SHUFPS	( CONST(0x0), XMM4, XMM4 )		/* uy | uy */
	MULPS	( XMM1, XMM4 )				/* uy*m5 | uy*m1 */
	MOVSS	( S(2), XMM5 )				/* uz */
	SHUFPS	( CONST(0x0), XMM5, XMM5 )		/* uz | uz */
	MULPS	( XMM2, XMM5 )				/* uz*m6 | uz*m2 */

	ADDPS	( XMM4, XMM3 )
	ADDPS	( XMM5, XMM3 )
	MOVLPS	( XMM3, D(0) )

	MOVSS	( M(10), XMM3 )				/* m10 */
	MULSS	( ARG_SCALE, XMM3 )			/* m10*scale */
	MULSS	( S(2), XMM3 )				/* m10*scale*uz */
	MOVSS	( S(1), XMM4 )				/* uy */
	MULSS	( XMM7, XMM4 )				/* uy*m9*scale */
	MOVSS	( S(0), XMM5 )				/* ux */
	MULSS	( XMM6, XMM5 )				/* ux*m8*scale */

	ADDSS	( XMM4, XMM3 )
	ADDSS	( XMM5, XMM3 )
	MOVSS	( XMM3, D(2) )
	
LLBL(K_G3TRNR_skip):
	ADD_L	( CONST(12), EDI )
	ADD_L	( EAX, ESI )
	CMP_L	( ECX, EDI )
	JNE	( LLBL(K_G3TRNR_top) )

LLBL(K_G3TRNR_finish):
	POP_L	( EDI )
	POP_L	( ESI )
	RET
#undef FRAME_OFFSET


ALIGNTEXT16
GLOBL GLNAME(gl_katmai_transform_normals_no_rot_raw)
GLNAME(gl_katmai_transform_normals_no_rot_raw):

#define FRAME_OFFSET 8
	PUSH_L  ( ESI )
	PUSH_L  ( EDI )

	MOV_L	( ARG_IN, ESI )				/* ptr to source GLvector3f */
	MOV_L	( ARG_DEST, EDI )			/* ptr to dest GLvector3f */

	MOV_L	( ARG_MAT, EDX )			/* ptr to matrix */
	MOV_L	( REGOFF(MAT_INV, EDX), EDX)		/* matrix->inv */

	MOV_L	( REGOFF(V3F_COUNT, ESI), ECX ) 	/* source count */

	TEST_L	( ECX, ECX )
	JZ( LLBL(K_G3TNNRR_finish) )			/* count was zero; go to finish */

	MOV_L	( STRIDE, EAX )				/* stride */
	MOV_L	( ECX, REGOFF(V3F_COUNT, EDI) )		/* set dest-count */

	IMUL_L( CONST(12), ECX )			/* count *= 12 */
	MOV_L( REGOFF(V3F_START, ESI), ESI )		/* ptr to first source vertex */

	MOV_L( REGOFF(V3F_START, EDI), EDI )		/* ptr to first dest vertex */
	ADD_L( EDI, ECX ) 				/* count += dest ptr */

ALIGNTEXT32
	MOVSS( M(0), XMM0 )				/* m0 */
	MOVSS( M(5), XMM1 )				/* m5 */
	UNPCKLPS( XMM1, XMM0 )				/* m5 | m0 */
	MOVSS( M(10), XMM1 )				/* m10 */
	
ALIGNTEXT32
LLBL(K_G3TNNRR_top):
	MOVLPS( S(0), XMM2 )				/* uy | ux */
	MULPS( XMM0, XMM2 )				/* uy*m5 | ux*m0 */
	MOVLPS( XMM2, D(0) )

	MOVSS( S(2), XMM2 )				/* uz */
	MULSS( XMM1, XMM2 )				/* uz*m10 */
	MOVSS( XMM2, D(2) )
	
LLBL(K_G3TNNRR_skip):
	ADD_L	( CONST(12), EDI )
	ADD_L	( EAX, ESI )
	CMP_L	( ECX, EDI )
	JNE	( LLBL(K_G3TNNRR_top) )

LLBL(K_G3TNNRR_finish):
	POP_L	( EDI )
	POP_L	( ESI )
	RET
#undef FRAME_OFFSET