fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / r200 / r200_vtxfmt_sse.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_vtxfmt_sse.c,v 1.1 2002/10/30 12:51:53 alanh 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_SSE_ASM)
42 #include "x86/common_x86_asm.h"
43
44 #define EXTERN( FUNC ) \
45 extern const char *FUNC; \
46 extern const char *FUNC##_end
47
48 EXTERN( _sse_Attribute2fv );
49 EXTERN( _sse_Attribute2f );
50 EXTERN( _sse_Attribute3fv );
51 EXTERN( _sse_Attribute3f );
52 EXTERN( _sse_MultiTexCoord2fv );
53 EXTERN( _sse_MultiTexCoord2f );
54 EXTERN( _sse_MultiTexCoord2fv_2 );
55 EXTERN( _sse_MultiTexCoord2f_2 );
56
57 /* Build specialized versions of the immediate calls on the fly for
58 * the current state.
59 */
60
61 static struct dynfn *r200_makeSSEAttribute2fv( struct dynfn * cache, const int * key,
62 const char * name, void * dest)
63 {
64 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
65
66 if (R200_DEBUG & DEBUG_CODEGEN)
67 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
68
69 DFN ( _sse_Attribute2fv, (*cache) );
70 FIXUP(dfn->code, 10, 0x0, (int)dest);
71 return dfn;
72 }
73
74 static struct dynfn *r200_makeSSEAttribute2f( struct dynfn * cache, const int * key,
75 const char * name, void * dest )
76 {
77 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
78
79 if (R200_DEBUG & DEBUG_CODEGEN)
80 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
81
82 DFN ( _sse_Attribute2f, (*cache) );
83 FIXUP(dfn->code, 8, 0x0, (int)dest);
84 return dfn;
85 }
86
87 static struct dynfn *r200_makeSSEAttribute3fv( struct dynfn * cache, const int * key,
88 const char * name, void * dest)
89 {
90 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
91
92 if (R200_DEBUG & DEBUG_CODEGEN)
93 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
94
95 DFN ( _sse_Attribute3fv, (*cache) );
96 FIXUP(dfn->code, 13, 0x0, (int)dest);
97 FIXUP(dfn->code, 18, 0x8, 8+(int)dest);
98 return dfn;
99 }
100
101 static struct dynfn *r200_makeSSEAttribute3f( struct dynfn * cache, const int * key,
102 const char * name, void * dest )
103 {
104 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
105
106 if (R200_DEBUG & DEBUG_CODEGEN)
107 fprintf(stderr, "%s 0x%08x\n", name, key[0] );
108
109 DFN ( _sse_Attribute3f, (*cache) );
110 FIXUP(dfn->code, 12, 0x0, (int)dest);
111 FIXUP(dfn->code, 17, 0x8, 8+(int)dest);
112 return dfn;
113 }
114
115 static struct dynfn *r200_makeSSENormal3fv( GLcontext *ctx, const int *key )
116 {
117 r200ContextPtr rmesa = R200_CONTEXT(ctx);
118
119 return r200_makeSSEAttribute3fv( & rmesa->vb.dfn_cache.Normal3fv, key,
120 __FUNCTION__, rmesa->vb.normalptr );
121 }
122
123 static struct dynfn *r200_makeSSENormal3f( GLcontext *ctx, const int * key )
124 {
125 r200ContextPtr rmesa = R200_CONTEXT(ctx);
126
127 return r200_makeSSEAttribute3f( & rmesa->vb.dfn_cache.Normal3f, key,
128 __FUNCTION__, rmesa->vb.normalptr );
129 }
130
131 static struct dynfn *r200_makeSSEColor3fv( GLcontext *ctx, const int * key )
132 {
133 if (VTX_COLOR(key[0],0) != R200_VTX_FP_RGB)
134 return NULL;
135 else
136 {
137 r200ContextPtr rmesa = R200_CONTEXT(ctx);
138
139 return r200_makeSSEAttribute3fv( & rmesa->vb.dfn_cache.Color3fv, key,
140 __FUNCTION__, rmesa->vb.floatcolorptr );
141 }
142 }
143
144 static struct dynfn *r200_makeSSEColor3f( GLcontext *ctx, const int * key )
145 {
146 if (VTX_COLOR(key[0],0) != R200_VTX_FP_RGB)
147 return NULL;
148 else
149 {
150 r200ContextPtr rmesa = R200_CONTEXT(ctx);
151
152 return r200_makeSSEAttribute3f( & rmesa->vb.dfn_cache.Color3f, key,
153 __FUNCTION__, rmesa->vb.floatcolorptr );
154 }
155 }
156
157 #if 0 /* Temporarily disabled as it is broken w/the new cubemap code. - idr */
158 static struct dynfn *r200_makeSSETexCoord2fv( GLcontext *ctx, const int * key )
159 {
160 r200ContextPtr rmesa = R200_CONTEXT(ctx);
161
162 return r200_makeSSEAttribute2fv( & rmesa->vb.dfn_cache.TexCoord2fv, key,
163 __FUNCTION__, rmesa->vb.texcoordptr[0] );
164 }
165
166 static struct dynfn *r200_makeSSETexCoord2f( GLcontext *ctx, const int * key )
167 {
168 r200ContextPtr rmesa = R200_CONTEXT(ctx);
169
170 return r200_makeSSEAttribute2f( & rmesa->vb.dfn_cache.TexCoord2f, key,
171 __FUNCTION__, rmesa->vb.texcoordptr[0] );
172 }
173
174 static struct dynfn *r200_makeSSEMultiTexCoord2fv( GLcontext *ctx, const int * key )
175 {
176 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
177 r200ContextPtr rmesa = R200_CONTEXT(ctx);
178
179 if (R200_DEBUG & DEBUG_CODEGEN)
180 fprintf(stderr, "%s 0x%08x\n", __FUNCTION__, key[0] );
181
182 if (rmesa->vb.texcoordptr[1] == rmesa->vb.texcoordptr[0]+4) {
183 DFN ( _sse_MultiTexCoord2fv, rmesa->vb.dfn_cache.MultiTexCoord2fvARB );
184 FIXUP(dfn->code, 18, 0xdeadbeef, (int)rmesa->vb.texcoordptr[0]);
185 } else {
186 DFN ( _sse_MultiTexCoord2fv_2, rmesa->vb.dfn_cache.MultiTexCoord2fvARB );
187 FIXUP(dfn->code, 14, 0x0, (int)rmesa->vb.texcoordptr);
188 }
189 return dfn;
190 }
191
192 static struct dynfn *r200_makeSSEMultiTexCoord2f( GLcontext *ctx, const int * key )
193 {
194 struct dynfn *dfn = MALLOC_STRUCT( dynfn );
195 r200ContextPtr rmesa = R200_CONTEXT(ctx);
196
197 if (R200_DEBUG & DEBUG_CODEGEN)
198 fprintf(stderr, "%s 0x%08x\n", __FUNCTION__, key[0] );
199
200 if (rmesa->vb.texcoordptr[1] == rmesa->vb.texcoordptr[0]+4) {
201 DFN ( _sse_MultiTexCoord2f, rmesa->vb.dfn_cache.MultiTexCoord2fARB );
202 FIXUP(dfn->code, 16, 0xdeadbeef, (int)rmesa->vb.texcoordptr[0]);
203 } else {
204 DFN ( _sse_MultiTexCoord2f_2, rmesa->vb.dfn_cache.MultiTexCoord2fARB );
205 FIXUP(dfn->code, 15, 0x0, (int)rmesa->vb.texcoordptr);
206 }
207 return dfn;
208 }
209 #endif
210
211 void r200InitSSECodegen( struct dfn_generators *gen )
212 {
213 if ( cpu_has_xmm ) {
214 gen->Normal3fv = (void *) r200_makeSSENormal3fv;
215 gen->Normal3f = (void *) r200_makeSSENormal3f;
216 gen->Color3fv = (void *) r200_makeSSEColor3fv;
217 gen->Color3f = (void *) r200_makeSSEColor3f;
218 #if 0 /* Temporarily disabled as it is broken w/the new cubemap code. - idr */
219 gen->TexCoord2fv = (void *) r200_makeSSETexCoord2fv;
220 gen->TexCoord2f = (void *) r200_makeSSETexCoord2f;
221 gen->MultiTexCoord2fvARB = (void *) r200_makeSSEMultiTexCoord2fv;
222 gen->MultiTexCoord2fARB = (void *) r200_makeSSEMultiTexCoord2f;
223 #endif
224 }
225 }
226
227 #else
228
229 void r200InitSSECodegen( struct dfn_generators *gen )
230 {
231 (void) gen;
232 }
233
234 #endif