disable under _SOLO build
[mesa.git] / src / mesa / drivers / dri / r200 / r200_vtxfmt_x86.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_vtxfmt_x86.c,v 1.2 2002/12/16 16:18:56 dawes Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #include "glheader.h"
37 #include "imports.h"
38 #include "simple_list.h"
39 #include "r200_vtxfmt.h"
40
41 #if defined(USE_X86_ASM)
42
43 #define EXTERN( FUNC ) \
44 extern const char *FUNC; \
45 extern const char *FUNC##_end
46
47 EXTERN ( _x86_Attribute2fv );
48 EXTERN ( _x86_Attribute2f );
49 EXTERN ( _x86_Attribute3fv );
50 EXTERN ( _x86_Attribute3f );
51 EXTERN ( _x86_Vertex3fv_6 );
52 EXTERN ( _x86_Vertex3fv_8 );
53 EXTERN ( _x86_Vertex3fv );
54 EXTERN ( _x86_Vertex3f_4 );
55 EXTERN ( _x86_Vertex3f_6 );
56 EXTERN ( _x86_Vertex3f );
57 EXTERN ( _x86_Color4ubv_ub );
58 EXTERN ( _x86_Color4ubv_4f );
59 EXTERN ( _x86_Color4ub_ub );
60 EXTERN ( _x86_MultiTexCoord2fv );
61 EXTERN ( _x86_MultiTexCoord2fv_2 );
62 EXTERN ( _x86_MultiTexCoord2f );
63 EXTERN ( _x86_MultiTexCoord2f_2 );
64
65
66 /* Build specialized versions of the immediate calls on the fly for
67 * the current state. Generic x86 versions.
68 */
69
70 struct dynfn *r200_makeX86Vertex3f( GLcontext *ctx, const int *key )
71 {
72 r200ContextPtr rmesa = R200_CONTEXT(ctx);
73 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
74
75 if (R200_DEBUG & DEBUG_CODEGEN)
76 fprintf(stderr, "%s 0x%08x 0x%08x %d\n", __FUNCTION__,
77 key[0], key[1], rmesa->vb.vertex_size );
78
79 switch (rmesa->vb.vertex_size) {
80 case 4: {
81
82 DFN ( _x86_Vertex3f_4, rmesa->vb.dfn_cache.Vertex3f );
83 FIXUP(dfn->code, 2, 0x0, (int)&rmesa->vb.dmaptr);
84 FIXUP(dfn->code, 25, 0x0, (int)&rmesa->vb.vertex[3]);
85 FIXUP(dfn->code, 36, 0x0, (int)&rmesa->vb.counter);
86 FIXUP(dfn->code, 46, 0x0, (int)&rmesa->vb.dmaptr);
87 FIXUP(dfn->code, 51, 0x0, (int)&rmesa->vb.counter);
88 FIXUP(dfn->code, 60, 0x0, (int)&rmesa->vb.notify);
89 break;
90 }
91 case 6: {
92
93 DFN ( _x86_Vertex3f_6, rmesa->vb.dfn_cache.Vertex3f );
94 FIXUP(dfn->code, 3, 0x0, (int)&rmesa->vb.dmaptr);
95 FIXUP(dfn->code, 28, 0x0, (int)&rmesa->vb.vertex[3]);
96 FIXUP(dfn->code, 34, 0x0, (int)&rmesa->vb.vertex[4]);
97 FIXUP(dfn->code, 40, 0x0, (int)&rmesa->vb.vertex[5]);
98 FIXUP(dfn->code, 57, 0x0, (int)&rmesa->vb.counter);
99 FIXUP(dfn->code, 63, 0x0, (int)&rmesa->vb.dmaptr);
100 FIXUP(dfn->code, 70, 0x0, (int)&rmesa->vb.counter);
101 FIXUP(dfn->code, 79, 0x0, (int)&rmesa->vb.notify);
102 break;
103 }
104 default: {
105
106 DFN ( _x86_Vertex3f, rmesa->vb.dfn_cache.Vertex3f );
107 FIXUP(dfn->code, 3, 0x0, (int)&rmesa->vb.vertex[3]);
108 FIXUP(dfn->code, 9, 0x0, (int)&rmesa->vb.dmaptr);
109 FIXUP(dfn->code, 37, 0x0, rmesa->vb.vertex_size-3);
110 FIXUP(dfn->code, 44, 0x0, (int)&rmesa->vb.counter);
111 FIXUP(dfn->code, 50, 0x0, (int)&rmesa->vb.dmaptr);
112 FIXUP(dfn->code, 56, 0x0, (int)&rmesa->vb.counter);
113 FIXUP(dfn->code, 67, 0x0, (int)&rmesa->vb.notify);
114 break;
115 }
116 }
117
118 return dfn;
119 }
120
121
122
123 struct dynfn *r200_makeX86Vertex3fv( GLcontext *ctx, const int *key )
124 {
125 r200ContextPtr rmesa = R200_CONTEXT(ctx);
126 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
127
128 if (R200_DEBUG & DEBUG_CODEGEN)
129 fprintf(stderr, "%s 0x%08x 0x%08x %d\n", __FUNCTION__,
130 key[0], key[1], rmesa->vb.vertex_size );
131
132 switch (rmesa->vb.vertex_size) {
133 case 6: {
134
135 DFN ( _x86_Vertex3fv_6, rmesa->vb.dfn_cache.Vertex3fv );
136 FIXUP(dfn->code, 1, 0x00000000, (int)&rmesa->vb.dmaptr);
137 FIXUP(dfn->code, 27, 0x0000001c, (int)&rmesa->vb.vertex[3]);
138 FIXUP(dfn->code, 33, 0x00000020, (int)&rmesa->vb.vertex[4]);
139 FIXUP(dfn->code, 45, 0x00000024, (int)&rmesa->vb.vertex[5]);
140 FIXUP(dfn->code, 56, 0x00000000, (int)&rmesa->vb.dmaptr);
141 FIXUP(dfn->code, 61, 0x00000004, (int)&rmesa->vb.counter);
142 FIXUP(dfn->code, 67, 0x00000004, (int)&rmesa->vb.counter);
143 FIXUP(dfn->code, 76, 0x00000008, (int)&rmesa->vb.notify);
144 break;
145 }
146
147
148 case 8: {
149
150 DFN ( _x86_Vertex3fv_8, rmesa->vb.dfn_cache.Vertex3fv );
151 FIXUP(dfn->code, 1, 0x00000000, (int)&rmesa->vb.dmaptr);
152 FIXUP(dfn->code, 27, 0x0000001c, (int)&rmesa->vb.vertex[3]);
153 FIXUP(dfn->code, 33, 0x00000020, (int)&rmesa->vb.vertex[4]);
154 FIXUP(dfn->code, 45, 0x0000001c, (int)&rmesa->vb.vertex[5]);
155 FIXUP(dfn->code, 51, 0x00000020, (int)&rmesa->vb.vertex[6]);
156 FIXUP(dfn->code, 63, 0x00000024, (int)&rmesa->vb.vertex[7]);
157 FIXUP(dfn->code, 74, 0x00000000, (int)&rmesa->vb.dmaptr);
158 FIXUP(dfn->code, 79, 0x00000004, (int)&rmesa->vb.counter);
159 FIXUP(dfn->code, 85, 0x00000004, (int)&rmesa->vb.counter);
160 FIXUP(dfn->code, 94, 0x00000008, (int)&rmesa->vb.notify);
161 break;
162 }
163
164
165
166 default: {
167
168 DFN ( _x86_Vertex3fv, rmesa->vb.dfn_cache.Vertex3fv );
169 FIXUP(dfn->code, 8, 0x01010101, (int)&rmesa->vb.dmaptr);
170 FIXUP(dfn->code, 32, 0x00000006, rmesa->vb.vertex_size-3);
171 FIXUP(dfn->code, 37, 0x00000058, (int)&rmesa->vb.vertex[3]);
172 FIXUP(dfn->code, 45, 0x01010101, (int)&rmesa->vb.dmaptr);
173 FIXUP(dfn->code, 50, 0x02020202, (int)&rmesa->vb.counter);
174 FIXUP(dfn->code, 58, 0x02020202, (int)&rmesa->vb.counter);
175 FIXUP(dfn->code, 67, 0x0, (int)&rmesa->vb.notify);
176 break;
177 }
178 }
179
180 return dfn;
181 }
182
183 static struct dynfn *
184 r200_makeX86Attribute2fv( struct dynfn * cache, const int *key,
185 const char * name, void * dest )
186 {
187 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
188
189 if (R200_DEBUG & DEBUG_CODEGEN)
190 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
191
192 DFN ( _x86_Attribute2fv, (*cache) );
193 FIXUP(dfn->code, 11, 0x0, (int)dest);
194 FIXUP(dfn->code, 16, 0x4, 4+(int)dest);
195
196 return dfn;
197 }
198
199 static struct dynfn *
200 r200_makeX86Attribute2f( struct dynfn * cache, const int *key,
201 const char * name, void * dest )
202 {
203 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
204
205 if (R200_DEBUG & DEBUG_CODEGEN)
206 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
207
208 DFN ( _x86_Attribute2f, (*cache) );
209 FIXUP(dfn->code, 1, 0x0, (int)dest);
210
211 return dfn;
212 }
213
214
215 static struct dynfn *
216 r200_makeX86Attribute3fv( struct dynfn * cache, const int *key,
217 const char * name, void * dest )
218 {
219 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
220
221 if (R200_DEBUG & DEBUG_CODEGEN)
222 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
223
224 DFN ( _x86_Attribute3fv, (*cache) );
225 FIXUP(dfn->code, 14, 0x0, (int)dest);
226 FIXUP(dfn->code, 20, 0x4, 4+(int)dest);
227 FIXUP(dfn->code, 25, 0x8, 8+(int)dest);
228
229 return dfn;
230 }
231
232 static struct dynfn *
233 r200_makeX86Attribute3f( struct dynfn * cache, const int *key,
234 const char * name, void * dest )
235 {
236 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
237
238 if (R200_DEBUG & DEBUG_CODEGEN)
239 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
240
241 DFN ( _x86_Attribute3f, (*cache) );
242 FIXUP(dfn->code, 14, 0x0, (int)dest);
243 FIXUP(dfn->code, 20, 0x4, 4+(int)dest);
244 FIXUP(dfn->code, 25, 0x8, 8+(int)dest);
245
246 return dfn;
247 }
248
249 struct dynfn *r200_makeX86Normal3fv( GLcontext *ctx, const int *key )
250 {
251 r200ContextPtr rmesa = R200_CONTEXT(ctx);
252
253 return r200_makeX86Attribute3fv( & rmesa->vb.dfn_cache.Normal3fv, key,
254 __FUNCTION__, rmesa->vb.normalptr );
255 }
256
257 struct dynfn *r200_makeX86Normal3f( GLcontext *ctx, const int *key )
258 {
259 r200ContextPtr rmesa = R200_CONTEXT(ctx);
260
261 return r200_makeX86Attribute3f( & rmesa->vb.dfn_cache.Normal3f, key,
262 __FUNCTION__, rmesa->vb.normalptr );
263 }
264
265 struct dynfn *r200_makeX86Color4ubv( GLcontext *ctx, const int *key )
266 {
267 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
268 r200ContextPtr rmesa = R200_CONTEXT(ctx);
269
270
271 if (R200_DEBUG & DEBUG_CODEGEN)
272 fprintf(stderr, "%s 0x%08x\n", __FUNCTION__, key[0] );
273
274 if (VTX_COLOR(key[0],0) == R200_VTX_PK_RGBA) {
275 DFN ( _x86_Color4ubv_ub, rmesa->vb.dfn_cache.Color4ubv);
276 FIXUP(dfn->code, 5, 0x12345678, (int)rmesa->vb.colorptr);
277 return dfn;
278 }
279 else {
280
281 DFN ( _x86_Color4ubv_4f, rmesa->vb.dfn_cache.Color4ubv);
282 FIXUP(dfn->code, 2, 0x00000000, (int)_mesa_ubyte_to_float_color_tab);
283 FIXUP(dfn->code, 27, 0xdeadbeaf, (int)rmesa->vb.floatcolorptr);
284 FIXUP(dfn->code, 33, 0xdeadbeaf, (int)rmesa->vb.floatcolorptr+4);
285 FIXUP(dfn->code, 55, 0xdeadbeaf, (int)rmesa->vb.floatcolorptr+8);
286 FIXUP(dfn->code, 61, 0xdeadbeaf, (int)rmesa->vb.floatcolorptr+12);
287 return dfn;
288 }
289 }
290
291 struct dynfn *r200_makeX86Color4ub( GLcontext *ctx, const int *key )
292 {
293 if (R200_DEBUG & DEBUG_CODEGEN)
294 fprintf(stderr, "%s 0x%08x\n", __FUNCTION__, key[0] );
295
296 if (VTX_COLOR(key[0],0) == R200_VTX_PK_RGBA) {
297 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
298 r200ContextPtr rmesa = R200_CONTEXT(ctx);
299
300 DFN ( _x86_Color4ub_ub, rmesa->vb.dfn_cache.Color4ub );
301 FIXUP(dfn->code, 18, 0x0, (int)rmesa->vb.colorptr);
302 FIXUP(dfn->code, 24, 0x0, (int)rmesa->vb.colorptr+1);
303 FIXUP(dfn->code, 30, 0x0, (int)rmesa->vb.colorptr+2);
304 FIXUP(dfn->code, 36, 0x0, (int)rmesa->vb.colorptr+3);
305 return dfn;
306 }
307 else
308 return 0;
309 }
310
311
312 struct dynfn *r200_makeX86Color3fv( GLcontext *ctx, const int *key )
313 {
314 if (VTX_COLOR(key[0],0) != R200_VTX_FP_RGB)
315 return 0;
316 else
317 {
318 r200ContextPtr rmesa = R200_CONTEXT(ctx);
319
320 return r200_makeX86Attribute3fv( & rmesa->vb.dfn_cache.Color3fv, key,
321 __FUNCTION__, rmesa->vb.floatcolorptr );
322 }
323 }
324
325 struct dynfn *r200_makeX86Color3f( GLcontext *ctx, const int *key )
326 {
327 if (VTX_COLOR(key[0],0) != R200_VTX_FP_RGB)
328 return 0;
329 else
330 {
331 r200ContextPtr rmesa = R200_CONTEXT(ctx);
332
333 return r200_makeX86Attribute3f( & rmesa->vb.dfn_cache.Color3f, key,
334 __FUNCTION__, rmesa->vb.floatcolorptr );
335 }
336 }
337
338
339
340 struct dynfn *r200_makeX86TexCoord2fv( GLcontext *ctx, const int *key )
341 {
342 r200ContextPtr rmesa = R200_CONTEXT(ctx);
343
344 return r200_makeX86Attribute2fv( & rmesa->vb.dfn_cache.TexCoord2fv, key,
345 __FUNCTION__, rmesa->vb.texcoordptr[0] );
346 }
347
348 struct dynfn *r200_makeX86TexCoord2f( GLcontext *ctx, const int *key )
349 {
350 r200ContextPtr rmesa = R200_CONTEXT(ctx);
351
352 return r200_makeX86Attribute2f( & rmesa->vb.dfn_cache.TexCoord2f, key,
353 __FUNCTION__, rmesa->vb.texcoordptr[0] );
354 }
355
356 struct dynfn *r200_makeX86MultiTexCoord2fvARB( GLcontext *ctx, const int *key )
357 {
358 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
359 r200ContextPtr rmesa = R200_CONTEXT(ctx);
360
361 if (R200_DEBUG & DEBUG_CODEGEN)
362 fprintf(stderr, "%s 0x%08x 0x%08x\n", __FUNCTION__, key[0], key[1] );
363
364 if (rmesa->vb.texcoordptr[1] == rmesa->vb.texcoordptr[0]+4) {
365 DFN ( _x86_MultiTexCoord2fv, rmesa->vb.dfn_cache.MultiTexCoord2fvARB );
366 FIXUP(dfn->code, 21, 0xdeadbeef, (int)rmesa->vb.texcoordptr[0]);
367 FIXUP(dfn->code, 27, 0xdeadbeef, (int)rmesa->vb.texcoordptr[0]+4);
368 } else {
369 DFN ( _x86_MultiTexCoord2fv_2, rmesa->vb.dfn_cache.MultiTexCoord2fvARB );
370 FIXUP(dfn->code, 14, 0x0, (int)rmesa->vb.texcoordptr);
371 }
372 return dfn;
373 }
374
375 struct dynfn *r200_makeX86MultiTexCoord2fARB( GLcontext *ctx,
376 const int *key )
377 {
378 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
379 r200ContextPtr rmesa = R200_CONTEXT(ctx);
380
381 if (R200_DEBUG & DEBUG_CODEGEN)
382 fprintf(stderr, "%s 0x%08x 0x%08x\n", __FUNCTION__, key[0], key[1] );
383
384 if (rmesa->vb.texcoordptr[1] == rmesa->vb.texcoordptr[0]+4) {
385 DFN ( _x86_MultiTexCoord2f, rmesa->vb.dfn_cache.MultiTexCoord2fARB );
386 FIXUP(dfn->code, 20, 0xdeadbeef, (int)rmesa->vb.texcoordptr[0]);
387 FIXUP(dfn->code, 26, 0xdeadbeef, (int)rmesa->vb.texcoordptr[0]+4);
388 }
389 else {
390 /* Note: this might get generated multiple times, even though the
391 * actual emitted code is the same.
392 */
393 DFN ( _x86_MultiTexCoord2f_2, rmesa->vb.dfn_cache.MultiTexCoord2fARB );
394 FIXUP(dfn->code, 18, 0x0, (int)rmesa->vb.texcoordptr);
395 }
396 return dfn;
397 }
398
399
400 void r200InitX86Codegen( struct dfn_generators *gen )
401 {
402 gen->Vertex3f = r200_makeX86Vertex3f;
403 gen->Vertex3fv = r200_makeX86Vertex3fv;
404 gen->Color4ub = r200_makeX86Color4ub; /* PKCOLOR only */
405 gen->Color4ubv = r200_makeX86Color4ubv; /* PKCOLOR only */
406 gen->Normal3f = r200_makeX86Normal3f;
407 gen->Normal3fv = r200_makeX86Normal3fv;
408 gen->TexCoord2f = r200_makeX86TexCoord2f;
409 gen->TexCoord2fv = r200_makeX86TexCoord2fv;
410 gen->MultiTexCoord2fARB = r200_makeX86MultiTexCoord2fARB;
411 gen->MultiTexCoord2fvARB = r200_makeX86MultiTexCoord2fvARB;
412 gen->Color3f = r200_makeX86Color3f;
413 gen->Color3fv = r200_makeX86Color3fv;
414
415 /* Not done:
416 */
417 /* gen->Vertex2f = r200_makeX86Vertex2f; */
418 /* gen->Vertex2fv = r200_makeX86Vertex2fv; */
419 /* gen->Color3ub = r200_makeX86Color3ub; */
420 /* gen->Color3ubv = r200_makeX86Color3ubv; */
421 /* gen->Color4f = r200_makeX86Color4f; */
422 /* gen->Color4fv = r200_makeX86Color4fv; */
423 /* gen->TexCoord1f = r200_makeX86TexCoord1f; */
424 /* gen->TexCoord1fv = r200_makeX86TexCoord1fv; */
425 /* gen->MultiTexCoord1fARB = r200_makeX86MultiTexCoord1fARB; */
426 /* gen->MultiTexCoord1fvARB = r200_makeX86MultiTexCoord1fvARB; */
427 }
428
429
430 #else
431
432 void r200InitX86Codegen( struct dfn_generators *gen )
433 {
434 (void) gen;
435 }
436
437 #endif