2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Updated for P6 architecture by Gareth Hughes.
38 #include "m_debug_util.h"
41 /* The linker doesn't like empty files */
45 #ifdef DEBUG /* This code only used for debugging */
48 /* Overhead of profiling counter in cycles. Automatically adjusted to
49 * your machine at run time - counter initialization should give very
52 long counter_overhead
= 0;
54 /* This is the value of the environment variable MESA_PROFILE, and is
55 * used to determine if we should benchmark the functions as well as
56 * verify their correctness.
58 char *mesa_profile
= NULL
;
61 static int m_general
[16] = {
67 static int m_identity
[16] = {
73 static int m_2d
[16] = {
79 static int m_2d_no_rot
[16] = {
85 static int m_3d
[16] = {
91 static int m_3d_no_rot
[16] = {
97 static int m_perspective
[16] = {
103 static int *templates
[7] = {
112 static enum GLmatrixtype mtypes
[7] = {
121 static char *mstrings
[7] = {
125 "MATRIX_PERSPECTIVE",
132 /* =============================================================
133 * Reference transformations
136 static void ref_transform( GLvector4f
*dst
,
138 const GLvector4f
*src
)
141 GLfloat
*s
= (GLfloat
*)src
->start
;
142 GLfloat (*d
)[4] = (GLfloat (*)[4])dst
->start
;
143 const GLfloat
*m
= mat
->m
;
145 for ( i
= 0 ; i
< src
->count
; i
++ ) {
146 TRANSFORM_POINT( d
[i
], m
, s
);
147 s
= (GLfloat
*)((char *)s
+ src
->stride
);
152 /* =============================================================
153 * Vertex transformation tests
156 static void init_matrix( GLfloat
*m
)
158 m
[0] = 63.0; m
[4] = 43.0; m
[ 8] = 29.0; m
[12] = 43.0;
159 m
[1] = 55.0; m
[5] = 17.0; m
[ 9] = 31.0; m
[13] = 7.0;
160 m
[2] = 44.0; m
[6] = 9.0; m
[10] = 7.0; m
[14] = 3.0;
161 m
[3] = 11.0; m
[7] = 23.0; m
[11] = 91.0; m
[15] = 9.0;
164 ALIGN16(static GLfloat
, s
[TEST_COUNT
][4]);
165 ALIGN16(static GLfloat
, d
[TEST_COUNT
][4]);
166 ALIGN16(static GLfloat
, r
[TEST_COUNT
][4]);
168 static int test_transform_function( transform_func func
, int psize
,
169 int mtype
, unsigned long *cycles
)
171 GLvector4f source
[1], dest
[1], ref
[1];
175 #ifdef RUN_DEBUG_BENCHMARK
176 int cycle_i
; /* the counter for the benchmarks we run */
182 _mesa_problem( NULL
, "test_transform_function called with psize > 4\n" );
186 mat
->m
= (GLfloat
*) ALIGN_MALLOC( 16 * sizeof(GLfloat
), 16 );
187 mat
->type
= mtypes
[mtype
];
190 ASSERT( ((long)m
& 15) == 0 );
194 for ( i
= 0 ; i
< 4 ; i
++ ) {
195 for ( j
= 0 ; j
< 4 ; j
++ ) {
196 switch ( templates
[mtype
][i
* 4 + j
] ) {
214 for ( i
= 0 ; i
< TEST_COUNT
; i
++) {
215 ASSIGN_4V( d
[i
], 0.0, 0.0, 0.0, 1.0 );
216 ASSIGN_4V( s
[i
], 0.0, 0.0, 0.0, 1.0 );
217 for ( j
= 0 ; j
< psize
; j
++ )
221 source
->data
= (GLfloat(*)[4])s
;
222 source
->start
= (GLfloat
*)s
;
223 source
->count
= TEST_COUNT
;
224 source
->stride
= sizeof(s
[0]);
228 dest
->data
= (GLfloat(*)[4])d
;
229 dest
->start
= (GLfloat
*)d
;
230 dest
->count
= TEST_COUNT
;
231 dest
->stride
= sizeof(float[4]);
235 ref
->data
= (GLfloat(*)[4])r
;
236 ref
->start
= (GLfloat
*)r
;
237 ref
->count
= TEST_COUNT
;
238 ref
->stride
= sizeof(float[4]);
242 ref_transform( ref
, mat
, source
);
244 if ( mesa_profile
) {
245 BEGIN_RACE( *cycles
);
246 func( dest
, mat
->m
, source
);
250 func( dest
, mat
->m
, source
);
253 for ( i
= 0 ; i
< TEST_COUNT
; i
++ ) {
254 for ( j
= 0 ; j
< 4 ; j
++ ) {
255 if ( significand_match( d
[i
][j
], r
[i
][j
] ) < REQUIRED_PRECISION
) {
256 _mesa_printf("-----------------------------\n" );
257 _mesa_printf("(i = %i, j = %i)\n", i
, j
);
258 _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
259 d
[i
][0], r
[i
][0], r
[i
][0]-d
[i
][0],
260 MAX_PRECISION
- significand_match( d
[i
][0], r
[i
][0] ) );
261 _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
262 d
[i
][1], r
[i
][1], r
[i
][1]-d
[i
][1],
263 MAX_PRECISION
- significand_match( d
[i
][1], r
[i
][1] ) );
264 _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
265 d
[i
][2], r
[i
][2], r
[i
][2]-d
[i
][2],
266 MAX_PRECISION
- significand_match( d
[i
][2], r
[i
][2] ) );
267 _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
268 d
[i
][3], r
[i
][3], r
[i
][3]-d
[i
][3],
269 MAX_PRECISION
- significand_match( d
[i
][3], r
[i
][3] ) );
275 ALIGN_FREE( mat
->m
);
279 void _math_test_all_transform_functions( char *description
)
282 unsigned long benchmark_tab
[4][7];
283 static int first_time
= 1;
287 mesa_profile
= getenv( "MESA_PROFILE" );
290 #ifdef RUN_DEBUG_BENCHMARK
291 if ( mesa_profile
) {
292 if ( !counter_overhead
) {
294 _mesa_printf("counter overhead: %lu cycles\n\n", counter_overhead
);
296 _mesa_printf("transform results after hooking in %s functions:\n", description
);
300 #ifdef RUN_DEBUG_BENCHMARK
301 if ( mesa_profile
) {
303 for ( psize
= 1 ; psize
<= 4 ; psize
++ ) {
304 _mesa_printf(" p%d\t", psize
);
306 _mesa_printf("\n--------------------------------------------------------\n" );
310 for ( mtype
= 0 ; mtype
< 7 ; mtype
++ ) {
311 for ( psize
= 1 ; psize
<= 4 ; psize
++ ) {
312 transform_func func
= _mesa_transform_tab
[psize
][mtypes
[mtype
]];
313 unsigned long *cycles
= &(benchmark_tab
[psize
-1][mtype
]);
315 if ( test_transform_function( func
, psize
, mtype
, cycles
) == 0 ) {
317 _mesa_sprintf(buf
, "_mesa_transform_tab[0][%d][%s] failed test (%s)",
318 psize
, mstrings
[mtype
], description
);
319 _mesa_problem( NULL
, buf
);
321 #ifdef RUN_DEBUG_BENCHMARK
323 _mesa_printf(" %li\t", benchmark_tab
[psize
-1][mtype
] );
326 #ifdef RUN_DEBUG_BENCHMARK
328 _mesa_printf(" | [%s]\n", mstrings
[mtype
] );
331 #ifdef RUN_DEBUG_BENCHMARK
333 _mesa_printf( "\n" );