X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmath%2Fm_debug_norm.c;h=8be07eecbe3eb92d1a5c242c41827a8463627c40;hb=5cc6425d708a9b8c660c2f43f5e277c507c98bf0;hp=9b7bafa7ca0f8213957aea45772c43441d3e022e;hpb=01915e90e6912f06d43d443a09157f7bbc96ddc5;p=mesa.git diff --git a/src/mesa/math/m_debug_norm.c b/src/mesa/math/m_debug_norm.c index 9b7bafa7ca0..8be07eecbe3 100644 --- a/src/mesa/math/m_debug_norm.c +++ b/src/mesa/math/m_debug_norm.c @@ -1,10 +1,8 @@ -/* $Id: m_debug_norm.c,v 1.4 2001/03/08 15:23:46 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 3.5 * - * Copyright (C) 1999 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -19,19 +17,20 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. * - * Author: - * Gareth Hughes + * Authors: + * Gareth Hughes */ -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "mem.h" -#include "mmath.h" +#include "c99_math.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/macros.h" +#include "main/imports.h" #include "m_matrix.h" #include "m_xform.h" @@ -40,7 +39,12 @@ #include "m_debug_util.h" -#ifdef DEBUG /* This code only used for debugging */ +#ifdef __UNIXOS2__ +/* The linker doesn't like empty files */ +static char dummy; +#endif + +#ifdef DEBUG_MATH /* This code only used for debugging */ static int m_norm_identity[16] = { @@ -113,23 +117,21 @@ static char *norm_strings[8] = { }; -/* ================================================================ +/* ============================================================= * Reference transformations */ static void ref_norm_transform_rescale( const GLmatrix *mat, GLfloat scale, - const GLvector3f *in, + const GLvector4f *in, const GLfloat *lengths, - const GLubyte mask[], - GLvector3f *dest ) + GLvector4f *dest ) { GLuint i; const GLfloat *s = in->start; const GLfloat *m = mat->inv; - GLfloat (*out)[3] = (GLfloat (*)[3])dest->start; + GLfloat (*out)[4] = (GLfloat (*)[4]) dest->start; - (void) mask; (void) lengths; for ( i = 0 ; i < in->count ; i++ ) { @@ -144,17 +146,14 @@ static void ref_norm_transform_rescale( const GLmatrix *mat, static void ref_norm_transform_normalize( const GLmatrix *mat, GLfloat scale, - const GLvector3f *in, + const GLvector4f *in, const GLfloat *lengths, - const GLubyte mask[], - GLvector3f *dest ) + GLvector4f *dest ) { GLuint i; const GLfloat *s = in->start; const GLfloat *m = mat->inv; - GLfloat (*out)[3] = (GLfloat (*)[3])dest->start; - - (void) mask; + GLfloat (*out)[4] = (GLfloat (*)[4]) dest->start; for ( i = 0 ; i < in->count ; i++ ) { GLfloat t[3]; @@ -167,13 +166,13 @@ static void ref_norm_transform_normalize( const GLmatrix *mat, /* Hmmm, don't know how we could test the precalculated * length case... */ - scale = 1.0 / sqrt( len ); + scale = 1.0f / sqrtf(len); SCALE_SCALAR_3V( out[i], scale, t ); } else { out[i][0] = out[i][1] = out[i][2] = 0; } } else { - scale = lengths[i];; + scale = lengths[i]; SCALE_SCALAR_3V( out[i], scale, t ); } @@ -182,20 +181,27 @@ static void ref_norm_transform_normalize( const GLmatrix *mat, } -/* ================================================================ +/* ============================================================= * Normal transformation tests */ -static int test_norm_function( normal_func func, int mtype, - int masked, long *cycles ) +static void init_matrix( GLfloat *m ) { - GLvector3f source[1], dest[1], dest2[1], ref[1], ref2[1]; + m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0; + m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] = 7.0; + m[2] = 44.0; m[6] = 9.0; m[10] = 7.0; m[14] = 3.0; + m[3] = 11.0; m[7] = 23.0; m[11] = 91.0; m[15] = 9.0; +} + + +static int test_norm_function( normal_func func, int mtype, long *cycles ) +{ + GLvector4f source[1], dest[1], dest2[1], ref[1], ref2[1]; GLmatrix mat[1]; - GLfloat s[TEST_COUNT][5], d[TEST_COUNT][3], r[TEST_COUNT][3]; - GLfloat d2[TEST_COUNT][3], r2[TEST_COUNT][3], length[TEST_COUNT]; + GLfloat s[TEST_COUNT][5], d[TEST_COUNT][4], r[TEST_COUNT][4]; + GLfloat d2[TEST_COUNT][4], r2[TEST_COUNT][4], length[TEST_COUNT]; GLfloat scale; GLfloat *m; - GLubyte mask[TEST_COUNT]; int i, j; #ifdef RUN_DEBUG_BENCHMARK int cycle_i; /* the counter for the benchmarks we run */ @@ -203,7 +209,7 @@ static int test_norm_function( normal_func func, int mtype, (void) cycles; - mat->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 ); + mat->m = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 ); mat->inv = m = mat->m; init_matrix( m ); @@ -225,84 +231,68 @@ static int test_norm_function( normal_func func, int mtype, case VAR: break; default: - abort(); + exit(1); } } } for ( i = 0 ; i < TEST_COUNT ; i++ ) { - mask[i] = i % 2; /* mask every 2nd element */ ASSIGN_3V( d[i], 0.0, 0.0, 0.0 ); ASSIGN_3V( s[i], 0.0, 0.0, 0.0 ); ASSIGN_3V( d2[i], 0.0, 0.0, 0.0 ); for ( j = 0 ; j < 3 ; j++ ) s[i][j] = rnd(); - length[i] = 1 / sqrt( LEN_SQUARED_3FV( s[i] ) ); + length[i] = 1.0f / sqrtf( LEN_SQUARED_3FV( s[i] ) ); } - source->data = (GLfloat(*)[3])s; - source->start = (GLfloat *)s; + source->data = (GLfloat(*)[4]) s; + source->start = (GLfloat *) s; source->count = TEST_COUNT; source->stride = sizeof(s[0]); source->flags = 0; - dest->data = (GLfloat(*)[3])d; - dest->start = (GLfloat *)d; + dest->data = d; + dest->start = (GLfloat *) d; dest->count = TEST_COUNT; - dest->stride = sizeof(float[3]); + dest->stride = sizeof(float[4]); dest->flags = 0; - dest2->data = (GLfloat(*)[3])d2; - dest2->start = (GLfloat *)d2; + dest2->data = d2; + dest2->start = (GLfloat *) d2; dest2->count = TEST_COUNT; - dest2->stride = sizeof(float[3]); + dest2->stride = sizeof(float[4]); dest2->flags = 0; - ref->data = (GLfloat(*)[3])r; - ref->start = (GLfloat *)r; + ref->data = r; + ref->start = (GLfloat *) r; ref->count = TEST_COUNT; - ref->stride = sizeof(float[3]); + ref->stride = sizeof(float[4]); ref->flags = 0; - ref2->data = (GLfloat(*)[3])r2; - ref2->start = (GLfloat *)r2; + ref2->data = r2; + ref2->start = (GLfloat *) r2; ref2->count = TEST_COUNT; - ref2->stride = sizeof(float[3]); + ref2->stride = sizeof(float[4]); ref2->flags = 0; if ( norm_normalize_types[mtype] == 0 ) { - ref_norm_transform_rescale( mat, scale, source, NULL, NULL, ref ); + ref_norm_transform_rescale( mat, scale, source, NULL, ref ); } else { - ref_norm_transform_normalize( mat, scale, source, NULL, NULL, ref ); - ref_norm_transform_normalize( mat, scale, source, length, NULL, ref2 ); + ref_norm_transform_normalize( mat, scale, source, NULL, ref ); + ref_norm_transform_normalize( mat, scale, source, length, ref2 ); } if ( mesa_profile ) { - if ( masked ) { - BEGIN_RACE( *cycles ); - func( mat, scale, source, NULL, mask, dest ); - END_RACE( *cycles ); - func( mat, scale, source, length, mask, dest2 ); - } else { - BEGIN_RACE( *cycles ); - func( mat, scale, source, NULL, NULL, dest ); - END_RACE( *cycles ); - func( mat, scale, source, length, NULL, dest2 ); - } + BEGIN_RACE( *cycles ); + func( mat, scale, source, NULL, dest ); + END_RACE( *cycles ); + func( mat, scale, source, length, dest2 ); } else { - if ( masked ) { - func( mat, scale, source, NULL, mask, dest ); - func( mat, scale, source, length, mask, dest2 ); - } else { - func( mat, scale, source, NULL, NULL, dest ); - func( mat, scale, source, length, NULL, dest2 ); - } + func( mat, scale, source, NULL, dest ); + func( mat, scale, source, length, dest2 ); } for ( i = 0 ; i < TEST_COUNT ; i++ ) { - if ( masked && !(mask[i] & 1) ) - continue; - for ( j = 0 ; j < 3 ; j++ ) { if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) { printf( "-----------------------------\n" ); @@ -338,15 +328,14 @@ static int test_norm_function( normal_func func, int mtype, } } - ALIGN_FREE( mat->m ); + _mesa_align_free( mat->m ); return 1; } void _math_test_all_normal_transform_functions( char *description ) { - int masked; int mtype; - long benchmark_tab[0xf][0x4]; + long benchmark_tab[0xf]; static int first_time = 1; if ( first_time ) { @@ -362,48 +351,34 @@ void _math_test_all_normal_transform_functions( char *description ) } printf( "normal transform results after hooking in %s functions:\n", description ); + printf( "\n-------------------------------------------------------\n" ); } #endif - for ( masked = 0 ; masked <= 1 ; masked++ ) { - int cma = masked ? 1 : 0; - char *cmastring = masked ? "CULL_MASK_ACTIVE" : "0"; + for ( mtype = 0 ; mtype < 8 ; mtype++ ) { + normal_func func = _mesa_normal_tab[norm_types[mtype]]; + long *cycles = &benchmark_tab[mtype]; -#ifdef RUN_DEBUG_BENCHMARK - if ( mesa_profile ) { - printf( "\n culling: %s \n", masked ? "CULL_MASK_ACTIVE" : "0" ); - printf( "\n-------------------------------------------------------\n" ); + if ( test_norm_function( func, mtype, cycles ) == 0 ) { + char buf[100]; + sprintf( buf, "_mesa_normal_tab[0][%s] failed test (%s)", + norm_strings[mtype], description ); + _mesa_problem( NULL, "%s", buf ); } -#endif - - for ( mtype = 0 ; mtype < 8 ; mtype++ ) { - normal_func func = _mesa_normal_tab[norm_types[mtype]][cma]; - long *cycles = &(benchmark_tab[mtype][cma]); - - if ( test_norm_function( func, mtype, masked, cycles ) == 0 ) { - char buf[100]; - sprintf( buf, "_mesa_normal_tab[%s][%s] failed test (%s)", - cmastring, norm_strings[mtype], description ); - _mesa_problem( NULL, buf ); - } #ifdef RUN_DEBUG_BENCHMARK - if ( mesa_profile ) { - printf( " %li\t", benchmark_tab[mtype][cma] ); - printf( " | [%s]\n", norm_strings[mtype] ); - } - } - if ( mesa_profile ) - printf( "\n" ); -#else + if ( mesa_profile ) { + printf( " %li\t", benchmark_tab[mtype] ); + printf( " | [%s]\n", norm_strings[mtype] ); } #endif } #ifdef RUN_DEBUG_BENCHMARK - if ( mesa_profile ) - fflush( stdout ); + if ( mesa_profile ) { + printf( "\n" ); + } #endif } -#endif /* DEBUG */ +#endif /* DEBUG_MATH */