- Fix tnl/t_context.h inclusion.
[mesa.git] / src / mesa / x86 / 3dnow.c
1 /* $Id: 3dnow.c,v 1.11 2000/11/19 02:18:33 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 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 * 3DNow! optimizations contributed by
29 * Holger Waechtler <holger@akaflieg.extern.tu-berlin.de>
30 */
31
32 #include "glheader.h"
33 #include "context.h"
34 #include "types.h"
35 #include "3dnow.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_xform.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, masked ) \
55 extern void _ASMAPI gl_##pfx##_transform_points##sz##_general_##masked( XFORM_ARGS ); \
56 extern void _ASMAPI gl_##pfx##_transform_points##sz##_identity_##masked( XFORM_ARGS ); \
57 extern void _ASMAPI gl_##pfx##_transform_points##sz##_3d_no_rot_##masked( XFORM_ARGS ); \
58 extern void _ASMAPI gl_##pfx##_transform_points##sz##_perspective_##masked( XFORM_ARGS ); \
59 extern void _ASMAPI gl_##pfx##_transform_points##sz##_2d_##masked( XFORM_ARGS ); \
60 extern void _ASMAPI gl_##pfx##_transform_points##sz##_2d_no_rot_##masked( XFORM_ARGS ); \
61 extern void _ASMAPI gl_##pfx##_transform_points##sz##_3d_##masked( XFORM_ARGS );
62
63
64 #define ASSIGN_XFORM_GROUP( pfx, cma, sz, masked ) \
65 gl_transform_tab[cma][sz][MATRIX_GENERAL] = \
66 gl_##pfx##_transform_points##sz##_general_##masked; \
67 gl_transform_tab[cma][sz][MATRIX_IDENTITY] = \
68 gl_##pfx##_transform_points##sz##_identity_##masked; \
69 gl_transform_tab[cma][sz][MATRIX_3D_NO_ROT] = \
70 gl_##pfx##_transform_points##sz##_3d_no_rot_##masked; \
71 gl_transform_tab[cma][sz][MATRIX_PERSPECTIVE] = \
72 gl_##pfx##_transform_points##sz##_perspective_##masked; \
73 gl_transform_tab[cma][sz][MATRIX_2D] = \
74 gl_##pfx##_transform_points##sz##_2d_##masked; \
75 gl_transform_tab[cma][sz][MATRIX_2D_NO_ROT] = \
76 gl_##pfx##_transform_points##sz##_2d_no_rot_##masked; \
77 gl_transform_tab[cma][sz][MATRIX_3D] = \
78 gl_##pfx##_transform_points##sz##_3d_##masked;
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, masked ) \
91 extern void _ASMAPI gl_##pfx##_rescale_normals_##masked( NORM_ARGS ); \
92 extern void _ASMAPI gl_##pfx##_normalize_normals_##masked( NORM_ARGS ); \
93 extern void _ASMAPI gl_##pfx##_transform_normals_##masked( NORM_ARGS ); \
94 extern void _ASMAPI gl_##pfx##_transform_normals_no_rot_##masked( NORM_ARGS ); \
95 extern void _ASMAPI gl_##pfx##_transform_rescale_normals_##masked( NORM_ARGS ); \
96 extern void _ASMAPI gl_##pfx##_transform_rescale_normals_no_rot_##masked( NORM_ARGS ); \
97 extern void _ASMAPI gl_##pfx##_transform_normalize_normals_##masked( NORM_ARGS ); \
98 extern void _ASMAPI gl_##pfx##_transform_normalize_normals_no_rot_##masked( NORM_ARGS );
99
100
101 #define ASSIGN_NORM_GROUP( pfx, cma, masked ) \
102 gl_normal_tab[NORM_RESCALE][cma] = \
103 gl_##pfx##_rescale_normals_##masked; \
104 gl_normal_tab[NORM_NORMALIZE][cma] = \
105 gl_##pfx##_normalize_normals_##masked; \
106 gl_normal_tab[NORM_TRANSFORM][cma] = \
107 gl_##pfx##_transform_normals_##masked; \
108 gl_normal_tab[NORM_TRANSFORM_NO_ROT][cma] = \
109 gl_##pfx##_transform_normals_no_rot_##masked; \
110 gl_normal_tab[NORM_TRANSFORM | NORM_RESCALE][cma] = \
111 gl_##pfx##_transform_rescale_normals_##masked; \
112 gl_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_RESCALE][cma] = \
113 gl_##pfx##_transform_rescale_normals_no_rot_##masked; \
114 gl_normal_tab[NORM_TRANSFORM | NORM_NORMALIZE][cma] = \
115 gl_##pfx##_transform_normalize_normals_##masked; \
116 gl_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE][cma] = \
117 gl_##pfx##_transform_normalize_normals_no_rot_##masked;
118
119
120 #ifdef USE_3DNOW_ASM
121 DECLARE_XFORM_GROUP( 3dnow, 1, raw )
122 DECLARE_XFORM_GROUP( 3dnow, 2, raw )
123 DECLARE_XFORM_GROUP( 3dnow, 3, raw )
124 DECLARE_XFORM_GROUP( 3dnow, 4, raw )
125
126 DECLARE_XFORM_GROUP( 3dnow, 1, masked )
127 DECLARE_XFORM_GROUP( 3dnow, 2, masked )
128 DECLARE_XFORM_GROUP( 3dnow, 3, masked )
129 DECLARE_XFORM_GROUP( 3dnow, 4, masked )
130
131 DECLARE_NORM_GROUP( 3dnow, raw )
132 /*DECLARE_NORM_GROUP( 3dnow, masked )*/
133
134
135 extern void _ASMAPI gl_v16_3dnow_general_xform( GLfloat *first_vert,
136 const GLfloat *m,
137 const GLfloat *src,
138 GLuint src_stride,
139 GLuint count );
140
141 extern void _ASMAPI gl_3dnow_project_vertices( GLfloat *first,
142 GLfloat *last,
143 const GLfloat *m,
144 GLuint stride );
145
146 extern void _ASMAPI gl_3dnow_project_clipped_vertices( GLfloat *first,
147 GLfloat *last,
148 const GLfloat *m,
149 GLuint stride,
150 const GLubyte *clipmask );
151 #endif
152
153
154 void gl_init_3dnow_transform_asm( void )
155 {
156 #ifdef USE_3DNOW_ASM
157 ASSIGN_XFORM_GROUP( 3dnow, 0, 1, raw );
158 ASSIGN_XFORM_GROUP( 3dnow, 0, 2, raw );
159 ASSIGN_XFORM_GROUP( 3dnow, 0, 3, raw );
160 ASSIGN_XFORM_GROUP( 3dnow, 0, 4, raw );
161
162 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 1, masked );
163 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 2, masked );
164 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 3, masked );
165 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 4, masked );
166
167 ASSIGN_NORM_GROUP( 3dnow, 0, raw );
168 /* ASSIGN_NORM_GROUP( 3dnow, CULL_MASK_ACTIVE, masked ); */
169
170 #ifdef DEBUG
171 gl_test_all_transform_functions( "3DNow!" );
172 gl_test_all_normal_transform_functions( "3DNow!" );
173 #endif
174 #endif
175 }
176
177 void gl_init_3dnow_vertex_asm( void )
178 {
179 #ifdef USE_3DNOW_ASM
180 gl_xform_points3_v16_general = gl_v16_3dnow_general_xform;
181 gl_project_v16 = gl_3dnow_project_vertices;
182 gl_project_clipped_v16 = gl_3dnow_project_clipped_vertices;
183
184 #ifdef DEBUG_NOT
185 gl_test_all_vertex_functions( "3DNow!" );
186 #endif
187 #endif
188 }