New type system for assembly code. Asm files should now include
[mesa.git] / src / mesa / x86 / 3dnow.c
1 /* $Id: 3dnow.c,v 1.17 2001/03/28 20:44:43 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 * 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 "mtypes.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.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 _mesa_##pfx##_transform_points##sz##_general_##masked( XFORM_ARGS ); \
56 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_identity_##masked( XFORM_ARGS ); \
57 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_3d_no_rot_##masked( XFORM_ARGS ); \
58 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_perspective_##masked( XFORM_ARGS ); \
59 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_2d_##masked( XFORM_ARGS ); \
60 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_2d_no_rot_##masked( XFORM_ARGS ); \
61 extern void _ASMAPI _mesa_##pfx##_transform_points##sz##_3d_##masked( XFORM_ARGS );
62
63
64 #define ASSIGN_XFORM_GROUP( pfx, cma, sz, masked ) \
65 _mesa_transform_tab[cma][sz][MATRIX_GENERAL] = \
66 _mesa_##pfx##_transform_points##sz##_general_##masked; \
67 _mesa_transform_tab[cma][sz][MATRIX_IDENTITY] = \
68 _mesa_##pfx##_transform_points##sz##_identity_##masked; \
69 _mesa_transform_tab[cma][sz][MATRIX_3D_NO_ROT] = \
70 _mesa_##pfx##_transform_points##sz##_3d_no_rot_##masked; \
71 _mesa_transform_tab[cma][sz][MATRIX_PERSPECTIVE] = \
72 _mesa_##pfx##_transform_points##sz##_perspective_##masked; \
73 _mesa_transform_tab[cma][sz][MATRIX_2D] = \
74 _mesa_##pfx##_transform_points##sz##_2d_##masked; \
75 _mesa_transform_tab[cma][sz][MATRIX_2D_NO_ROT] = \
76 _mesa_##pfx##_transform_points##sz##_2d_no_rot_##masked; \
77 _mesa_transform_tab[cma][sz][MATRIX_3D] = \
78 _mesa_##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 _mesa_##pfx##_rescale_normals_##masked( NORM_ARGS ); \
92 extern void _ASMAPI _mesa_##pfx##_normalize_normals_##masked( NORM_ARGS ); \
93 extern void _ASMAPI _mesa_##pfx##_transform_normals_##masked( NORM_ARGS ); \
94 extern void _ASMAPI _mesa_##pfx##_transform_normals_no_rot_##masked( NORM_ARGS ); \
95 extern void _ASMAPI _mesa_##pfx##_transform_rescale_normals_##masked( NORM_ARGS ); \
96 extern void _ASMAPI _mesa_##pfx##_transform_rescale_normals_no_rot_##masked( NORM_ARGS ); \
97 extern void _ASMAPI _mesa_##pfx##_transform_normalize_normals_##masked( NORM_ARGS ); \
98 extern void _ASMAPI _mesa_##pfx##_transform_normalize_normals_no_rot_##masked( NORM_ARGS );
99
100
101 #define ASSIGN_NORM_GROUP( pfx, cma, masked ) \
102 _mesa_normal_tab[NORM_RESCALE][cma] = \
103 _mesa_##pfx##_rescale_normals_##masked; \
104 _mesa_normal_tab[NORM_NORMALIZE][cma] = \
105 _mesa_##pfx##_normalize_normals_##masked; \
106 _mesa_normal_tab[NORM_TRANSFORM][cma] = \
107 _mesa_##pfx##_transform_normals_##masked; \
108 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT][cma] = \
109 _mesa_##pfx##_transform_normals_no_rot_##masked; \
110 _mesa_normal_tab[NORM_TRANSFORM | NORM_RESCALE][cma] = \
111 _mesa_##pfx##_transform_rescale_normals_##masked; \
112 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_RESCALE][cma] = \
113 _mesa_##pfx##_transform_rescale_normals_no_rot_##masked; \
114 _mesa_normal_tab[NORM_TRANSFORM | NORM_NORMALIZE][cma] = \
115 _mesa_##pfx##_transform_normalize_normals_##masked; \
116 _mesa_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE][cma] = \
117 _mesa_##pfx##_transform_normalize_normals_no_rot_##masked;
118
119
120 #ifdef USE_3DNOW_ASM
121 DECLARE_XFORM_GROUP( 3dnow, 2, raw )
122 DECLARE_XFORM_GROUP( 3dnow, 3, raw )
123 DECLARE_XFORM_GROUP( 3dnow, 4, raw )
124
125 DECLARE_XFORM_GROUP( 3dnow, 2, masked )
126 DECLARE_XFORM_GROUP( 3dnow, 3, masked )
127 DECLARE_XFORM_GROUP( 3dnow, 4, masked )
128
129 DECLARE_NORM_GROUP( 3dnow, raw )
130 /*DECLARE_NORM_GROUP( 3dnow, masked )*/
131
132
133 extern void _ASMAPI
134 _mesa_v16_3dnow_general_xform( GLfloat *first_vert,
135 const GLfloat *m,
136 const GLfloat *src,
137 GLuint src_stride,
138 GLuint count );
139
140 extern void _ASMAPI
141 _mesa_3dnow_project_vertices( GLfloat *first,
142 GLfloat *last,
143 const GLfloat *m,
144 GLuint stride );
145
146 extern void _ASMAPI
147 _mesa_3dnow_project_clipped_vertices( GLfloat *first,
148 GLfloat *last,
149 const GLfloat *m,
150 GLuint stride,
151 const GLubyte *clipmask );
152 #endif
153
154
155 void _mesa_init_3dnow_transform_asm( void )
156 {
157 #ifdef USE_3DNOW_ASM
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, 2, masked ); */
163 /* ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 3, masked ); */
164 /* ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 4, masked ); */
165
166 ASSIGN_NORM_GROUP( 3dnow, 0, raw );
167 /* ASSIGN_NORM_GROUP( 3dnow, CULL_MASK_ACTIVE, masked ); */
168
169 #ifdef DEBUG
170 _math_test_all_transform_functions( "3DNow!" );
171 _math_test_all_normal_transform_functions( "3DNow!" );
172 #endif
173 #endif
174 }
175
176 void _mesa_init_3dnow_vertex_asm( void )
177 {
178 #ifdef USE_3DNOW_ASM
179 _mesa_xform_points3_v16_general = _mesa_v16_3dnow_general_xform;
180 _mesa_project_v16 = _mesa_3dnow_project_vertices;
181 _mesa_project_clipped_v16 = _mesa_3dnow_project_clipped_vertices;
182
183 #ifdef DEBUG_NOT
184 _math_test_all_vertex_functions( "3DNow!" );
185 #endif
186 #endif
187 }