Major audit of all Mesa's x86 assembly code. This round is basically
[mesa.git] / src / mesa / x86 / 3dnow.c
1 /* $Id: 3dnow.c,v 1.8 2000/10/23 00:16:28 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 "vertices.h"
36 #include "xform.h"
37 #include "3dnow.h"
38
39 #ifdef DEBUG
40 #include "debug_xform.h"
41 #endif
42
43
44 #define XFORM_ARGS GLvector4f *to_vec, \
45 const GLfloat m[16], \
46 const GLvector4f *from_vec, \
47 const GLubyte *mask, \
48 const GLubyte flag
49
50
51 #define DECLARE_XFORM_GROUP( pfx, sz, masked ) \
52 extern void _ASMAPI gl_##pfx##_transform_points##sz##_general_##masked( XFORM_ARGS ); \
53 extern void _ASMAPI gl_##pfx##_transform_points##sz##_identity_##masked( XFORM_ARGS ); \
54 extern void _ASMAPI gl_##pfx##_transform_points##sz##_3d_no_rot_##masked( XFORM_ARGS ); \
55 extern void _ASMAPI gl_##pfx##_transform_points##sz##_perspective_##masked( XFORM_ARGS ); \
56 extern void _ASMAPI gl_##pfx##_transform_points##sz##_2d_##masked( XFORM_ARGS ); \
57 extern void _ASMAPI gl_##pfx##_transform_points##sz##_2d_no_rot_##masked( XFORM_ARGS ); \
58 extern void _ASMAPI gl_##pfx##_transform_points##sz##_3d_##masked( XFORM_ARGS );
59
60
61 #define ASSIGN_XFORM_GROUP( pfx, cma, sz, masked ) \
62 gl_transform_tab[cma][sz][MATRIX_GENERAL] = \
63 gl_##pfx##_transform_points##sz##_general_##masked; \
64 gl_transform_tab[cma][sz][MATRIX_IDENTITY] = \
65 gl_##pfx##_transform_points##sz##_identity_##masked; \
66 gl_transform_tab[cma][sz][MATRIX_3D_NO_ROT] = \
67 gl_##pfx##_transform_points##sz##_3d_no_rot_##masked; \
68 gl_transform_tab[cma][sz][MATRIX_PERSPECTIVE] = \
69 gl_##pfx##_transform_points##sz##_perspective_##masked; \
70 gl_transform_tab[cma][sz][MATRIX_2D] = \
71 gl_##pfx##_transform_points##sz##_2d_##masked; \
72 gl_transform_tab[cma][sz][MATRIX_2D_NO_ROT] = \
73 gl_##pfx##_transform_points##sz##_2d_no_rot_##masked; \
74 gl_transform_tab[cma][sz][MATRIX_3D] = \
75 gl_##pfx##_transform_points##sz##_3d_##masked;
76
77
78
79 #define NORM_ARGS const GLmatrix *mat, \
80 GLfloat scale, \
81 const GLvector3f *in, \
82 const GLfloat *lengths, \
83 const GLubyte mask[], \
84 GLvector3f *dest
85
86
87 #define DECLARE_NORM_GROUP( pfx, masked ) \
88 extern void _ASMAPI gl_##pfx##_rescale_normals_##masked( NORM_ARGS ); \
89 extern void _ASMAPI gl_##pfx##_normalize_normals_##masked( NORM_ARGS ); \
90 extern void _ASMAPI gl_##pfx##_transform_normals_##masked( NORM_ARGS ); \
91 extern void _ASMAPI gl_##pfx##_transform_normals_no_rot_##masked( NORM_ARGS ); \
92 extern void _ASMAPI gl_##pfx##_transform_rescale_normals_##masked( NORM_ARGS ); \
93 extern void _ASMAPI gl_##pfx##_transform_rescale_normals_no_rot_##masked( NORM_ARGS ); \
94 extern void _ASMAPI gl_##pfx##_transform_normalize_normals_##masked( NORM_ARGS ); \
95 extern void _ASMAPI gl_##pfx##_transform_normalize_normals_no_rot_##masked( NORM_ARGS );
96
97
98 #define ASSIGN_NORM_GROUP( pfx, cma, masked ) \
99 gl_normal_tab[NORM_RESCALE][cma] = \
100 gl_##pfx##_rescale_normals_##masked; \
101 gl_normal_tab[NORM_NORMALIZE][cma] = \
102 gl_##pfx##_normalize_normals_##masked; \
103 gl_normal_tab[NORM_TRANSFORM][cma] = \
104 gl_##pfx##_transform_normals_##masked; \
105 gl_normal_tab[NORM_TRANSFORM_NO_ROT][cma] = \
106 gl_##pfx##_transform_normals_no_rot_##masked; \
107 gl_normal_tab[NORM_TRANSFORM | NORM_RESCALE][cma] = \
108 gl_##pfx##_transform_rescale_normals_##masked; \
109 gl_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_RESCALE][cma] = \
110 gl_##pfx##_transform_rescale_normals_no_rot_##masked; \
111 gl_normal_tab[NORM_TRANSFORM | NORM_NORMALIZE][cma] = \
112 gl_##pfx##_transform_normalize_normals_##masked; \
113 gl_normal_tab[NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE][cma] = \
114 gl_##pfx##_transform_normalize_normals_no_rot_##masked;
115
116
117 #ifdef USE_3DNOW_ASM
118 DECLARE_XFORM_GROUP( 3dnow, 1, raw )
119 DECLARE_XFORM_GROUP( 3dnow, 2, raw )
120 DECLARE_XFORM_GROUP( 3dnow, 3, raw )
121 DECLARE_XFORM_GROUP( 3dnow, 4, raw )
122
123 DECLARE_XFORM_GROUP( 3dnow, 1, masked )
124 DECLARE_XFORM_GROUP( 3dnow, 2, masked )
125 DECLARE_XFORM_GROUP( 3dnow, 3, masked )
126 DECLARE_XFORM_GROUP( 3dnow, 4, masked )
127
128 DECLARE_NORM_GROUP( 3dnow, raw )
129 /*DECLARE_NORM_GROUP( 3dnow, masked )*/
130
131
132 extern void _ASMAPI gl_v16_3dnow_general_xform( GLfloat *first_vert,
133 const GLfloat *m,
134 const GLfloat *src,
135 GLuint src_stride,
136 GLuint count );
137
138 extern void _ASMAPI gl_3dnow_project_vertices( GLfloat *first,
139 GLfloat *last,
140 const GLfloat *m,
141 GLuint stride );
142
143 extern void _ASMAPI gl_3dnow_project_clipped_vertices( GLfloat *first,
144 GLfloat *last,
145 const GLfloat *m,
146 GLuint stride,
147 const GLubyte *clipmask );
148 #endif
149
150
151 void gl_init_3dnow_transform_asm( void )
152 {
153 #ifdef USE_3DNOW_ASM
154 ASSIGN_XFORM_GROUP( 3dnow, 0, 1, raw );
155 ASSIGN_XFORM_GROUP( 3dnow, 0, 2, raw );
156 ASSIGN_XFORM_GROUP( 3dnow, 0, 3, raw );
157 ASSIGN_XFORM_GROUP( 3dnow, 0, 4, raw );
158
159 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 1, masked );
160 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 2, masked );
161 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 3, masked );
162 ASSIGN_XFORM_GROUP( 3dnow, CULL_MASK_ACTIVE, 4, masked );
163
164 ASSIGN_NORM_GROUP( 3dnow, 0, raw );
165 /* ASSIGN_NORM_GROUP( 3dnow, CULL_MASK_ACTIVE, masked ); */
166
167 #ifdef DEBUG
168 gl_test_all_transform_functions( "3DNow!" );
169 gl_test_all_normal_transform_functions( "3DNow!" );
170 #endif
171 #endif
172 }
173
174 void gl_init_3dnow_vertex_asm( void )
175 {
176 #ifdef USE_3DNOW_ASM
177 gl_xform_points3_v16_general = gl_v16_3dnow_general_xform;
178 gl_project_v16 = gl_3dnow_project_vertices;
179 gl_project_clipped_v16 = gl_3dnow_project_clipped_vertices;
180
181 #if 0
182 gl_test_all_vertex_functions( "3DNow!" );
183 #endif
184 #endif
185 }