Consolidation of asm code in 3.5
[mesa.git] / src / mesa / x86 / sse.c
1 /* $Id: sse.c,v 1.1 2001/03/29 06:46:16 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 /*
28 * PentiumIII-SIMD (SSE) optimizations contributed by
29 * Andre Werthmann <wertmann@cs.uni-potsdam.de>
30 */
31
32 #include "glheader.h"
33 #include "context.h"
34 #include "mtypes.h"
35 #include "sse.h"
36
37 #include "math/m_vertices.h"
38 #include "math/m_xform.h"
39
40 #include "tnl/t_context.h"
41
42 #ifdef DEBUG
43 #include "math/m_debug.h"
44 #endif
45
46
47 #define XFORM_ARGS GLvector4f *to_vec, \
48 const GLfloat m[16], \
49 const GLvector4f *from_vec, \
50 const GLubyte *mask, \
51 const GLubyte flag
52
53
54 #define DECLARE_XFORM_GROUP( pfx, sz ) \
55 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_general( XFORM_ARGS ); \
56 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_identity( XFORM_ARGS ); \
57 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_3d_no_rot( XFORM_ARGS ); \
58 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_perspective( XFORM_ARGS ); \
59 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_2d( XFORM_ARGS ); \
60 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_2d_no_rot( XFORM_ARGS ); \
61 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_3d( XFORM_ARGS );
62
63
64 #define ASSIGN_XFORM_GROUP( pfx, sz ) \
65 _mesa_transform_tab[0][sz][MATRIX_GENERAL] = \
66 _mesa_##pfx##_transform_points##sz##_general; \
67 _mesa_transform_tab[0][sz][MATRIX_IDENTITY] = \
68 _mesa_##pfx##_transform_points##sz##_identity; \
69 _mesa_transform_tab[0][sz][MATRIX_3D_NO_ROT] = \
70 _mesa_##pfx##_transform_points##sz##_3d_no_rot; \
71 _mesa_transform_tab[0][sz][MATRIX_PERSPECTIVE] = \
72 _mesa_##pfx##_transform_points##sz##_perspective; \
73 _mesa_transform_tab[0][sz][MATRIX_2D] = \
74 _mesa_##pfx##_transform_points##sz##_2d; \
75 _mesa_transform_tab[0][sz][MATRIX_2D_NO_ROT] = \
76 _mesa_##pfx##_transform_points##sz##_2d_no_rot; \
77 _mesa_transform_tab[0][sz][MATRIX_3D] = \
78 _mesa_##pfx##_transform_points##sz##_3d;
79
80
81
82 #define NORM_ARGS const GLmatrix *mat, \
83 GLfloat scale, \
84 const GLvector3f *in, \
85 const GLfloat *lengths, \
86 const GLubyte mask[], \
87 GLvector3f *dest
88
89
90 #define DECLARE_NORM_GROUP( pfx ) \
91 extern void _ASMAPI _mesa_##pfx##_rescale_normals( NORM_ARGS ); \
92 extern void _ASMAPI _mesa_##pfx##_normalize_normals( NORM_ARGS ); \
93 extern void _ASMAPI _mesa_##pfx##_transform_normals( NORM_ARGS ); \
94 extern void _ASMAPI _mesa_##pfx##_transform_normals_no_rot( NORM_ARGS ); \
95 extern void _ASMAPI _mesa_##pfx##_transform_rescale_normals( NORM_ARGS ); \
96 extern void _ASMAPI _mesa_##pfx##_transform_rescale_normals_no_rot( NORM_ARGS ); \
97 extern void _ASMAPI _mesa_##pfx##_transform_normalize_normals( NORM_ARGS ); \
98 extern void _ASMAPI _mesa_##pfx##_transform_normalize_normals_no_rot( NORM_ARGS );
99
100
101 #define ASSIGN_NORM_GROUP( pfx ) \
102 _mesa_normal_tab[NORM_RESCALE][0] = \
103 _mesa_##pfx##_rescale_normals; \
104 _mesa_normal_tab[NORM_NORMALIZE][0] = \
105 _mesa_##pfx##_normalize_normals; \
106 _mesa_normal_tab[NORM_TRANSFORM][0] = \
107 _mesa_##pfx##_transform_normals; \
108 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT][0] = \
109 _mesa_##pfx##_transform_normals_no_rot; \
110 _mesa_normal_tab[NORM_TRANSFORM|NORM_RESCALE][0] = \
111 _mesa_##pfx##_transform_rescale_normals; \
112 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT|NORM_RESCALE][0] = \
113 _mesa_##pfx##_transform_rescale_normals_no_rot; \
114 _mesa_normal_tab[NORM_TRANSFORM|NORM_NORMALIZE][0] = \
115 _mesa_##pfx##_transform_normalize_normals; \
116 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT|NORM_NORMALIZE][0] = \
117 _mesa_##pfx##_transform_normalize_normals_no_rot;
118
119
120 #ifdef USE_SSE_ASM
121 DECLARE_XFORM_GROUP( sse, 2 )
122 DECLARE_XFORM_GROUP( sse, 3 )
123
124 #if 1
125 /* Some functions are not written in SSE-assembly, because the fpu ones are faster */
126 extern void _mesa_sse_transform_normals_no_rot( NORM_ARGS );
127 extern void _mesa_sse_transform_rescale_normals( NORM_ARGS );
128 extern void _mesa_sse_transform_rescale_normals_no_rot( NORM_ARGS );
129
130 extern void _mesa_sse_transform_points4_general( XFORM_ARGS );
131 extern void _mesa_sse_transform_points4_3d( XFORM_ARGS );
132 extern void _mesa_sse_transform_points4_identity( XFORM_ARGS );
133 #else
134 DECLARE_NORM_GROUP( sse )
135 #endif
136
137
138 extern void _ASMAPI
139 _mesa_v16_sse_general_xform( GLfloat *first_vert,
140 const GLfloat *m,
141 const GLfloat *src,
142 GLuint src_stride,
143 GLuint count );
144
145 extern void _ASMAPI
146 _mesa_sse_project_vertices( GLfloat *first,
147 GLfloat *last,
148 const GLfloat *m,
149 GLuint stride );
150
151 extern void _ASMAPI
152 _mesa_sse_project_clipped_vertices( GLfloat *first,
153 GLfloat *last,
154 const GLfloat *m,
155 GLuint stride,
156 const GLubyte *clipmask );
157 #endif
158
159
160 void _mesa_init_sse_transform_asm( void )
161 {
162 #ifdef USE_SSE_ASM
163 ASSIGN_XFORM_GROUP( sse, 2 );
164 ASSIGN_XFORM_GROUP( sse, 3 );
165
166 #if 1
167 /* TODO: Finish these off.
168 */
169 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT][0] =
170 _mesa_sse_transform_normals_no_rot;
171 _mesa_normal_tab[NORM_TRANSFORM|NORM_RESCALE][0] =
172 _mesa_sse_transform_rescale_normals;
173 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT|NORM_RESCALE][0] =
174 _mesa_sse_transform_rescale_normals_no_rot;
175
176 _mesa_transform_tab[0][4][MATRIX_GENERAL] =
177 _mesa_sse_transform_points4_general;
178 _mesa_transform_tab[0][4][MATRIX_3D] =
179 _mesa_sse_transform_points4_3d;
180 _mesa_transform_tab[0][4][MATRIX_IDENTITY] =
181 _mesa_sse_transform_points4_identity;
182 #else
183 ASSIGN_NORM_GROUP( sse );
184 #endif
185
186 #ifdef DEBUG
187 _math_test_all_transform_functions( "SSE" );
188 _math_test_all_normal_transform_functions( "SSE" );
189 #endif
190 #endif
191 }
192
193 void _mesa_init_sse_vertex_asm( void )
194 {
195 #ifdef USE_SSE_ASM
196 _mesa_xform_points3_v16_general = _mesa_v16_sse_general_xform;
197 #if 0
198 /* GH: These are broken. I'm fixing them now.
199 */
200 _mesa_project_v16 = _mesa_sse_project_vertices;
201 _mesa_project_clipped_v16 = _mesa_sse_project_clipped_vertices;
202 #endif
203
204 #ifdef DEBUG_NOT
205 _math_test_all_vertex_functions( "SSE" );
206 #endif
207 #endif
208 }