m_debug_xform.c revision 99ae9e8d7d57ae37629754edd5b1e3716611827f
123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* 223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Mesa 3-D graphics library 3b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paul * Version: 6.1 423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 5b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paul * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * copy of this software and associated documentation files (the "Software"), 923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to deal in the Software without restriction, including without limitation 1023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the 1223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Software is furnished to do so, subject to the following conditions: 1323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 1423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * The above copyright notice and this permission notice shall be included 1523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * in all copies or substantial portions of the Software. 1623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 1723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 2423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 2523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* 2623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Updated for P6 architecture by Gareth Hughes. 2723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 2823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 29101d1a658a614d1e2ec02b1e697f6161291af653José Fonseca#include "main/glheader.h" 30101d1a658a614d1e2ec02b1e697f6161291af653José Fonseca#include "main/context.h" 31101d1a658a614d1e2ec02b1e697f6161291af653José Fonseca#include "main/macros.h" 32101d1a658a614d1e2ec02b1e697f6161291af653José Fonseca#include "main/imports.h" 3323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 3423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_matrix.h" 3523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_xform.h" 3623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 37fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#include "m_debug.h" 38fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#include "m_debug_util.h" 3923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 40462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane#ifdef __UNIXOS2__ 41462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane/* The linker doesn't like empty files */ 42462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihanestatic char dummy; 43462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane#endif 44462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane 4581a22ef53953d950052c7bd5a282e96107a25f24Brian Paul#ifdef DEBUG_MATH /* This code only used for debugging */ 4623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 4723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 4823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* Overhead of profiling counter in cycles. Automatically adjusted to 4923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * your machine at run time - counter initialization should give very 5023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * consistent results. 5123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 52fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hugheslong counter_overhead = 0; 5323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 54fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes/* This is the value of the environment variable MESA_PROFILE, and is 55fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes * used to determine if we should benchmark the functions as well as 56fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes * verify their correctness. 5723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 58fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hugheschar *mesa_profile = NULL; 5923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 6023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 6123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int m_general[16] = { 6223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, VAR, VAR, 6323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, VAR, VAR, 6423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, VAR, VAR, 6523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, VAR, VAR 6623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 6723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int m_identity[16] = { 6823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ONE, NIL, NIL, NIL, 6923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, ONE, NIL, NIL, 7023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, ONE, NIL, 7123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, NIL, ONE 7223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 7323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int m_2d[16] = { 7423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, NIL, VAR, 7523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, NIL, VAR, 7623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, ONE, NIL, 7723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, NIL, ONE 7823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 7923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int m_2d_no_rot[16] = { 8023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, NIL, NIL, VAR, 8123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, VAR, NIL, VAR, 8223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, ONE, NIL, 8323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, NIL, ONE 8423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 8523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int m_3d[16] = { 8623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, VAR, VAR, 8723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, VAR, VAR, 8823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, VAR, VAR, VAR, 8923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, NIL, ONE 9023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 9123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int m_3d_no_rot[16] = { 9223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, NIL, NIL, VAR, 9323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, VAR, NIL, VAR, 9423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, VAR, VAR, 9523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, NIL, ONE 9623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 9723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int m_perspective[16] = { 9823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell VAR, NIL, VAR, NIL, 9923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, VAR, VAR, NIL, 10023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, VAR, VAR, 10123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell NIL, NIL, NEG, NIL 10223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 10323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic int *templates[7] = { 10423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m_general, 10523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m_identity, 10623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m_3d_no_rot, 10723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m_perspective, 10823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m_2d, 10923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m_2d_no_rot, 11023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m_3d 11123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 1126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwellstatic enum GLmatrixtype mtypes[7] = { 11323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MATRIX_GENERAL, 11423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MATRIX_IDENTITY, 11523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MATRIX_3D_NO_ROT, 11623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MATRIX_PERSPECTIVE, 11723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MATRIX_2D, 11823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MATRIX_2D_NO_ROT, 11923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MATRIX_3D 12023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 12123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic char *mstrings[7] = { 12223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell "MATRIX_GENERAL", 12323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell "MATRIX_IDENTITY", 12423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell "MATRIX_3D_NO_ROT", 12523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell "MATRIX_PERSPECTIVE", 12623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell "MATRIX_2D", 12723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell "MATRIX_2D_NO_ROT", 12823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell "MATRIX_3D" 12923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}; 13023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 13123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 1325e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes/* ============================================================= 13323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Reference transformations 13423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 13523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 13623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellstatic void ref_transform( GLvector4f *dst, 13723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell const GLmatrix *mat, 1385e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes const GLvector4f *src ) 13923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{ 14001915e90e6912f06d43d443a09157f7bbc96ddc5Brian Paul GLuint i; 14123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat *s = (GLfloat *)src->start; 14223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat (*d)[4] = (GLfloat (*)[4])dst->start; 14323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell const GLfloat *m = mat->m; 14423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 14523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell for ( i = 0 ; i < src->count ; i++ ) { 146fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes TRANSFORM_POINT( d[i], m, s ); 14723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell s = (GLfloat *)((char *)s + src->stride); 14823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 14923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell} 15023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 15123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 1525e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes/* ============================================================= 15323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Vertex transformation tests 15423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 15523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 1564e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paulstatic void init_matrix( GLfloat *m ) 1574e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul{ 1584e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0; 1594e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] = 7.0; 1604e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul m[2] = 44.0; m[6] = 9.0; m[10] = 7.0; m[14] = 3.0; 1614e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul m[3] = 11.0; m[7] = 23.0; m[11] = 91.0; m[15] = 9.0; 1624e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul} 1634e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul 164b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian PaulALIGN16(static GLfloat, s[TEST_COUNT][4]); 165b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian PaulALIGN16(static GLfloat, d[TEST_COUNT][4]); 166b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian PaulALIGN16(static GLfloat, r[TEST_COUNT][4]); 16723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 1681b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughesstatic int test_transform_function( transform_func func, int psize, 16942fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul int mtype, unsigned long *cycles ) 17023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{ 17123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLvector4f source[1], dest[1], ref[1]; 17223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLmatrix mat[1]; 17323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat *m; 17423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell int i, j; 175fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 17623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell int cycle_i; /* the counter for the benchmarks we run */ 17723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif 17823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 17923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell (void) cycles; 18023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 18123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell if ( psize > 4 ) { 18208836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_problem( NULL, "test_transform_function called with psize > 4\n" ); 18323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell return 0; 18423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 18523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 18699ae9e8d7d57ae37629754edd5b1e3716611827fKristian Høgsberg mat->m = (GLfloat *) _mesa_align_malloc( 16 * sizeof(GLfloat), 16 ); 18723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell mat->type = mtypes[mtype]; 18823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 18923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m = mat->m; 19042fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul ASSERT( ((long)m & 15) == 0 ); 19123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 192fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes init_matrix( m ); 19323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 19423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell for ( i = 0 ; i < 4 ; i++ ) { 19523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell for ( j = 0 ; j < 4 ; j++ ) { 19623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell switch ( templates[mtype][i * 4 + j] ) { 19723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell case NIL: 19823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m[j * 4 + i] = 0.0; 19923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell break; 20023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell case ONE: 20123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m[j * 4 + i] = 1.0; 20223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell break; 20323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell case NEG: 20423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell m[j * 4 + i] = -1.0; 20523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell break; 20623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell case VAR: 20723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell break; 20823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell default: 209c921a29b3a696f6fa99b648d6cd975dbcf106429José Fonseca ASSERT(0); 210c921a29b3a696f6fa99b648d6cd975dbcf106429José Fonseca return 0; 21123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 21223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 21323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 21423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 21523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell for ( i = 0 ; i < TEST_COUNT ; i++) { 216fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 ); 217fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 ); 21823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell for ( j = 0 ; j < psize ; j++ ) 21923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell s[i][j] = rnd(); 22023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 22123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 22223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell source->data = (GLfloat(*)[4])s; 22323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell source->start = (GLfloat *)s; 22423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell source->count = TEST_COUNT; 22523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell source->stride = sizeof(s[0]); 22623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell source->size = 4; 22723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell source->flags = 0; 22823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 22923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell dest->data = (GLfloat(*)[4])d; 23023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell dest->start = (GLfloat *)d; 23123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell dest->count = TEST_COUNT; 23223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell dest->stride = sizeof(float[4]); 23323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell dest->size = 0; 23423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell dest->flags = 0; 23523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 23623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ref->data = (GLfloat(*)[4])r; 23723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ref->start = (GLfloat *)r; 23823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ref->count = TEST_COUNT; 23923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ref->stride = sizeof(float[4]); 24023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ref->size = 0; 24123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ref->flags = 0; 24223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 2435e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes ref_transform( ref, mat, source ); 24423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 24523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell if ( mesa_profile ) { 2461b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes BEGIN_RACE( *cycles ); 2475e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes func( dest, mat->m, source ); 2481b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes END_RACE( *cycles ); 24923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 25023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell else { 2515e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes func( dest, mat->m, source ); 25223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 25323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 25423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell for ( i = 0 ; i < TEST_COUNT ; i++ ) { 25523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell for ( j = 0 ; j < 4 ; j++ ) { 25623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) { 257298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("-----------------------------\n" ); 258298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("(i = %i, j = %i)\n", i, j ); 259298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("%f \t %f \t [diff = %e - %i bit missed]\n", 26023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell d[i][0], r[i][0], r[i][0]-d[i][0], 26123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAX_PRECISION - significand_match( d[i][0], r[i][0] ) ); 262298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("%f \t %f \t [diff = %e - %i bit missed]\n", 26323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell d[i][1], r[i][1], r[i][1]-d[i][1], 26423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAX_PRECISION - significand_match( d[i][1], r[i][1] ) ); 265298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("%f \t %f \t [diff = %e - %i bit missed]\n", 26623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell d[i][2], r[i][2], r[i][2]-d[i][2], 26723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAX_PRECISION - significand_match( d[i][2], r[i][2] ) ); 268298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("%f \t %f \t [diff = %e - %i bit missed]\n", 26923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell d[i][3], r[i][3], r[i][3]-d[i][3], 27023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAX_PRECISION - significand_match( d[i][3], r[i][3] ) ); 27123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell return 0; 27223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 27323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 27423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 27523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 27699ae9e8d7d57ae37629754edd5b1e3716611827fKristian Høgsberg _mesa_align_free( mat->m ); 27723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell return 1; 27823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell} 27923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 280fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughesvoid _math_test_all_transform_functions( char *description ) 28123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{ 2821b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes int psize, mtype; 28342fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul unsigned long benchmark_tab[4][7]; 28423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell static int first_time = 1; 28523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 28623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell if ( first_time ) { 28723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell first_time = 0; 288b3aefd1cfb6aacd1695c52911dd39da50d893eceBrian Paul mesa_profile = _mesa_getenv( "MESA_PROFILE" ); 28923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 29023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 291fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 29223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell if ( mesa_profile ) { 293fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes if ( !counter_overhead ) { 29423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell INIT_COUNTER(); 295298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("counter overhead: %lu cycles\n\n", counter_overhead ); 29623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 297298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("transform results after hooking in %s functions:\n", description ); 29823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 29923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif 30023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 301fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 3021b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes if ( mesa_profile ) { 303298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("\n" ); 3041b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes for ( psize = 1 ; psize <= 4 ; psize++ ) { 305298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf(" p%d\t", psize ); 30623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 307298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("\n--------------------------------------------------------\n" ); 3081b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes } 30923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif 31023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 3111b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes for ( mtype = 0 ; mtype < 7 ; mtype++ ) { 3121b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes for ( psize = 1 ; psize <= 4 ; psize++ ) { 3135e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes transform_func func = _mesa_transform_tab[psize][mtypes[mtype]]; 31442fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul unsigned long *cycles = &(benchmark_tab[psize-1][mtype]); 3151b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes 3161b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes if ( test_transform_function( func, psize, mtype, cycles ) == 0 ) { 3171b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes char buf[100]; 318298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg sprintf(buf, "_mesa_transform_tab[0][%d][%s] failed test (%s)", 319298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg psize, mstrings[mtype], description ); 3201b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes _mesa_problem( NULL, buf ); 3211b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes } 322fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 3231b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes if ( mesa_profile ) 324298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf(" %li\t", benchmark_tab[psize-1][mtype] ); 32523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif 32623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 327fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 32823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell if ( mesa_profile ) 329298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf(" | [%s]\n", mstrings[mtype] ); 33023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif 33123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 3321b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 3331b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes if ( mesa_profile ) 334298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf( "\n" ); 3351b2fef5c28a40cd001598071e25b876ad4fccdd1Gareth Hughes#endif 33623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell} 33723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 33823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 33981a22ef53953d950052c7bd5a282e96107a25f24Brian Paul#endif /* DEBUG_MATH */ 340