nir: Take a nir_shader and variable mode in assign_var_locations
[mesa.git] / src / mesa / math / m_debug_xform.c
index 9600bec804cdb77247710b5f0308d6c6575318d3..4795df286d655e7ced269bd348a0c0c4b7c45175 100644 (file)
@@ -1,10 +1,7 @@
-/* $Id: m_debug_xform.c,v 1.5 2001/03/12 00:48:41 gareth Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  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"),
  * 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.
  */
 
 /*
  * Updated for P6 architecture by Gareth Hughes.
  */
 
-#include "glheader.h"
-#include "context.h"
-#include "macros.h"
-#include "mem.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/macros.h"
 
 #include "m_matrix.h"
 #include "m_xform.h"
 #include "m_debug.h"
 #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 */
 
 
 /* Overhead of profiling counter in cycles.  Automatically adjusted to
@@ -106,7 +108,7 @@ static int *templates[7] = {
    m_2d_no_rot,
    m_3d
 };
-static int mtypes[7] = {
+static enum GLmatrixtype mtypes[7] = {
    MATRIX_GENERAL,
    MATRIX_IDENTITY,
    MATRIX_3D_NO_ROT,
@@ -126,24 +128,19 @@ static char *mstrings[7] = {
 };
 
 
-/* ================================================================
+/* =============================================================
  * Reference transformations
  */
 
 static void ref_transform( GLvector4f *dst,
                            const GLmatrix *mat,
-                           const GLvector4f *src,
-                           const GLubyte *clipmask,
-                           const GLubyte flag )
+                           const GLvector4f *src )
 {
    GLuint i;
    GLfloat *s = (GLfloat *)src->start;
    GLfloat (*d)[4] = (GLfloat (*)[4])dst->start;
    const GLfloat *m = mat->m;
 
-   (void) clipmask;
-   (void) flag;
-
    for ( i = 0 ; i < src->count ; i++ ) {
       TRANSFORM_POINT( d[i], m, s );
       s = (GLfloat *)((char *)s + src->stride);
@@ -151,21 +148,28 @@ static void ref_transform( GLvector4f *dst,
 }
 
 
-/* ================================================================
+/* =============================================================
  * Vertex transformation tests
  */
 
-static GLfloat s[TEST_COUNT][5] ALIGN16;
-static GLfloat d[TEST_COUNT][4] ALIGN16;
-static GLfloat r[TEST_COUNT][4] ALIGN16;
+static void init_matrix( GLfloat *m )
+{
+   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;
+}
+
+ALIGN16(static GLfloat, s[TEST_COUNT][4]);
+ALIGN16(static GLfloat, d[TEST_COUNT][4]);
+ALIGN16(static GLfloat, r[TEST_COUNT][4]);
 
-static int test_transform_function( transform_func func, int psize, int mtype,
-                                    int masked, long *cycles )
+static int test_transform_function( transform_func func, int psize,
+                                   int mtype, unsigned long *cycles )
 {
    GLvector4f source[1], dest[1], ref[1];
    GLmatrix mat[1];
    GLfloat *m;
-   GLubyte mask[TEST_COUNT];
    int i, j;
 #ifdef  RUN_DEBUG_BENCHMARK
    int cycle_i;                /* the counter for the benchmarks we run */
@@ -178,10 +182,11 @@ static int test_transform_function( transform_func func, int psize, int mtype,
       return 0;
    }
 
-   mat->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 );
+   mat->m = align_malloc( 16 * sizeof(GLfloat), 16 );
    mat->type = mtypes[mtype];
 
    m = mat->m;
+   assert( ((long)m & 15) == 0 );
 
    init_matrix( m );
 
@@ -200,13 +205,13 @@ static int test_transform_function( transform_func func, int psize, int mtype,
          case VAR:
             break;
          default:
-            abort();
+            assert(0);
+            return 0;
          }
       }
    }
 
    for ( i = 0 ; i < TEST_COUNT ; i++) {
-      mask[i] = i % 2;                         /* mask every 2nd element */
       ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 );
       ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 );
       for ( j = 0 ; j < psize ; j++ )
@@ -234,45 +239,32 @@ static int test_transform_function( transform_func func, int psize, int mtype,
    ref->size = 0;
    ref->flags = 0;
 
-   ref_transform( ref, mat, source, NULL, 0 );
+   ref_transform( ref, mat, source );
 
    if ( mesa_profile ) {
-      if ( masked ) {
-         BEGIN_RACE( *cycles );
-         func( dest, mat->m, source, mask, 1 );
-         END_RACE( *cycles );
-      } else {
-         BEGIN_RACE( *cycles );
-         func( dest, mat->m, source, NULL, 0 );
-         END_RACE( *cycles );
-     }
+      BEGIN_RACE( *cycles );
+      func( dest, mat->m, source );
+      END_RACE( *cycles );
    }
    else {
-      if ( masked ) {
-         func( dest, mat->m, source, mask, 1 );
-      } else {
-         func( dest, mat->m, source, NULL, 0 );
-      }
+      func( dest, mat->m, source );
    }
 
    for ( i = 0 ; i < TEST_COUNT ; i++ ) {
-      if ( masked && (mask[i] & 1) )
-         continue;
-
       for ( j = 0 ; j < 4 ; j++ ) {
          if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) {
-            printf( "-----------------------------\n" );
-            printf( "(i = %i, j = %i)\n", i, j );
-            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
+            printf("-----------------------------\n" );
+            printf("(i = %i, j = %i)\n", i, j );
+            printf("%f \t %f \t [diff = %e - %i bit missed]\n",
                    d[i][0], r[i][0], r[i][0]-d[i][0],
                    MAX_PRECISION - significand_match( d[i][0], r[i][0] ) );
-            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
+            printf("%f \t %f \t [diff = %e - %i bit missed]\n",
                    d[i][1], r[i][1], r[i][1]-d[i][1],
                    MAX_PRECISION - significand_match( d[i][1], r[i][1] ) );
-            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
+            printf("%f \t %f \t [diff = %e - %i bit missed]\n",
                    d[i][2], r[i][2], r[i][2]-d[i][2],
                    MAX_PRECISION - significand_match( d[i][2], r[i][2] ) );
-            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
+            printf("%f \t %f \t [diff = %e - %i bit missed]\n",
                    d[i][3], r[i][3], r[i][3]-d[i][3],
                    MAX_PRECISION - significand_match( d[i][3], r[i][3] ) );
             return 0;
@@ -280,14 +272,14 @@ static int test_transform_function( transform_func func, int psize, int mtype,
       }
    }
 
-   ALIGN_FREE( mat->m );
+   align_free( mat->m );
    return 1;
 }
 
 void _math_test_all_transform_functions( char *description )
 {
-   int masked, psize, mtype;
-   long benchmark_tab[2][4][7];
+   int psize, mtype;
+   unsigned long benchmark_tab[4][7];
    static int first_time = 1;
 
    if ( first_time ) {
@@ -299,54 +291,48 @@ void _math_test_all_transform_functions( char *description )
    if ( mesa_profile ) {
       if ( !counter_overhead ) {
         INIT_COUNTER();
-        printf( "counter overhead: %ld cycles\n\n", counter_overhead );
+        printf("counter overhead: %lu cycles\n\n", counter_overhead );
       }
-      printf( "transform results after hooking in %s functions:\n", description );
+      printf("transform results after hooking in %s functions:\n", description );
    }
 #endif
 
-   for ( masked = 0 ; masked <= 1 ; masked++ ) {
-      int cma = masked ? 1 : 0;
-      char *cmastring = masked ? "CULL_MASK_ACTIVE" : "0";
-
 #ifdef RUN_DEBUG_BENCHMARK
-      if ( mesa_profile ) {
-         printf( "\n culling: %s \n", masked ? "CULL_MASK_ACTIVE" : "0" );
-         for ( psize = 1 ; psize <= 4 ; psize++ ) {
-            printf( " p%d\t", psize );
-         }
-         printf( "\n--------------------------------------------------------\n" );
+   if ( mesa_profile ) {
+      printf("\n" );
+      for ( psize = 1 ; psize <= 4 ; psize++ ) {
+        printf(" p%d\t", psize );
       }
+      printf("\n--------------------------------------------------------\n" );
+   }
 #endif
 
-      for ( mtype = 0 ; mtype < 7 ; mtype++ ) {
-         for ( psize = 1 ; psize <= 4 ; psize++ ) {
-            transform_func func = _mesa_transform_tab[cma][psize][mtypes[mtype]];
-            long *cycles = &(benchmark_tab[cma][psize-1][mtype]);
-
-            if ( test_transform_function( func, psize, mtype,
-                                         masked, cycles ) == 0 ) {
-               char buf[100];
-               sprintf( buf, "_mesa_transform_tab[%s][%d][%s] failed test (%s)",
-                        cmastring, psize, mstrings[mtype], description );
-               _mesa_problem( NULL, buf );
-            }
+   for ( mtype = 0 ; mtype < 7 ; mtype++ ) {
+      for ( psize = 1 ; psize <= 4 ; psize++ ) {
+        transform_func func = _mesa_transform_tab[psize][mtypes[mtype]];
+        unsigned long *cycles = &(benchmark_tab[psize-1][mtype]);
+
+        if ( test_transform_function( func, psize, mtype, cycles ) == 0 ) {
+           char buf[100];
+           sprintf(buf, "_mesa_transform_tab[0][%d][%s] failed test (%s)",
+                   psize, mstrings[mtype], description );
+           _mesa_problem( NULL, "%s", buf );
+        }
 #ifdef RUN_DEBUG_BENCHMARK
-            if ( mesa_profile )
-               printf( " %li\t", benchmark_tab[cma][psize-1][mtype] );
-#endif
-         }
-#ifdef RUN_DEBUG_BENCHMARK
-         if ( mesa_profile )
-            printf( " | [%s]\n", mstrings[mtype] );
+        if ( mesa_profile )
+           printf(" %li\t", benchmark_tab[psize-1][mtype] );
 #endif
       }
 #ifdef RUN_DEBUG_BENCHMARK
       if ( mesa_profile )
-         printf( "\n" );
+        printf(" | [%s]\n", mstrings[mtype] );
 #endif
    }
+#ifdef RUN_DEBUG_BENCHMARK
+   if ( mesa_profile )
+      printf( "\n" );
+#endif
 }
 
 
-#endif /* DEBUG */
+#endif /* DEBUG_MATH */