mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / math / m_debug_util.h
index 79e369ebd5daf33f9fde19cdef976d2a20256085..dc5c65682fb641a1c896436cd92a31afb9adf9a4 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: m_debug_util.h,v 1.2 2001/03/12 00:48:41 gareth Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  6.1
  *
- * 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
+ * THE AUTHORS 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.
  *
  * Authors:
- *    Gareth Hughes <gareth@valinux.com>
+ *    Gareth Hughes
  */
 
 #ifndef __M_DEBUG_UTIL_H__
 #define __M_DEBUG_UTIL_H__
 
 
-#ifdef DEBUG  /* This code only used for debugging */
+#ifdef DEBUG_MATH  /* This code only used for debugging */
 
 
 /* Comment this out to deactivate the cycle counter.
  * NOTE: it works only on CPUs which know the 'rdtsc' command (586 or higher)
  * (hope, you don't try to debug Mesa on a 386 ;)
  */
-#if defined(__GNUC__) && defined(__i386__) && defined(USE_X86_ASM)
+#if defined(__GNUC__) && \
+    ((defined(__i386__) && defined(USE_X86_ASM)) || \
+     (defined(__sparc__) && defined(USE_SPARC_ASM)))
 #define  RUN_DEBUG_BENCHMARK
 #endif
 
@@ -61,12 +61,14 @@ extern long counter_overhead;
  */
 extern char *mesa_profile;
 
-/* Modify the the number of tests if you like.
+/* Modify the number of tests if you like.
  * We take the minimum of all results, because every error should be
  * positive (time used by other processes, task switches etc).
  * It is assumed that all calculations are done in the cache.
  */
 
+#if defined(__i386__)
+
 #if 1 /* PPro, PII, PIII version */
 
 /* Profiling on the P6 architecture requires a little more work, due to
@@ -183,6 +185,68 @@ extern char *mesa_profile;
 
 #endif
 
+#elif defined(__x86_64__)
+
+#define rdtscll(val) do { \
+     unsigned int a,d; \
+     __asm__ volatile("rdtsc" : "=a" (a), "=d" (d)); \
+     (val) = ((unsigned long)a) | (((unsigned long)d)<<32); \
+} while(0) 
+
+/* Copied from i386 PIII version */
+#define  INIT_COUNTER()                                                        \
+   do {                                                                        \
+      int cycle_i;                                                     \
+      counter_overhead = LONG_MAX;                                     \
+      for ( cycle_i = 0 ; cycle_i < 16 ; cycle_i++ ) {                 \
+        unsigned long cycle_tmp1, cycle_tmp2;                          \
+        rdtscll(cycle_tmp1);                                           \
+        rdtscll(cycle_tmp2);                                           \
+        if ( counter_overhead > (cycle_tmp2 - cycle_tmp1) ) {          \
+           counter_overhead = cycle_tmp2 - cycle_tmp1;                 \
+        }                                                              \
+      }                                                                        \
+   } while (0)
+
+
+#define  BEGIN_RACE(x)                                                 \
+   x = LONG_MAX;                                                       \
+   for ( cycle_i = 0 ; cycle_i < 10 ; cycle_i++ ) {                    \
+      unsigned long cycle_tmp1, cycle_tmp2;                            \
+      rdtscll(cycle_tmp1);                                             \
+
+#define END_RACE(x)                                                    \
+      rdtscll(cycle_tmp2);                                             \
+      if ( x > (cycle_tmp2 - cycle_tmp1) ) {                           \
+        x = cycle_tmp2 - cycle_tmp1;                                   \
+      }                                                                        \
+   }                                                                   \
+   x -= counter_overhead;
+
+#elif defined(__sparc__)
+
+#define  INIT_COUNTER()        \
+        do { counter_overhead = 5; } while(0)
+
+#define  BEGIN_RACE(x)                                                        \
+x = LONG_MAX;                                                                 \
+for (cycle_i = 0; cycle_i <10; cycle_i++) {                                   \
+   register long cycle_tmp1 __asm__("l0");                                   \
+   register long cycle_tmp2 __asm__("l1");                                   \
+   /* rd %tick, %l0 */                                                       \
+   __asm__ __volatile__ (".word 0xa1410000" : "=r" (cycle_tmp1));  /*  save timestamp   */
+
+#define END_RACE(x)                                                           \
+   /* rd %tick, %l1 */                                                       \
+   __asm__ __volatile__ (".word 0xa3410000" : "=r" (cycle_tmp2));            \
+   if (x > (cycle_tmp2-cycle_tmp1)) x = cycle_tmp2 - cycle_tmp1;              \
+}                                                                             \
+x -= counter_overhead;
+
+#else
+#error Your processor is not supported for RUN_XFORM_BENCHMARK
+#endif
+
 #else
 
 #define BEGIN_RACE(x)
@@ -191,7 +255,7 @@ extern char *mesa_profile;
 #endif
 
 
-/* ================================================================
+/* =============================================================
  * Helper functions
  */
 
@@ -222,9 +286,9 @@ static int significand_match( GLfloat a, GLfloat b )
       return 0;
    }
 
-   frexp( a, &a_ex );
-   frexp( b, &b_ex );
-   frexp( d, &d_ex );
+   FREXPF( a, &a_ex );
+   FREXPF( b, &b_ex );
+   FREXPF( d, &d_ex );
 
    if ( a_ex < b_ex ) {
       return a_ex - d_ex;
@@ -235,27 +299,22 @@ static int significand_match( GLfloat a, GLfloat b )
 
 enum { NIL = 0, ONE = 1, NEG = -1, VAR = 2 };
 
-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;
-}
-
-
 /* Ensure our arrays are correctly aligned.
  */
 #if defined(__GNUC__)
-#  define ALIGN16      __attribute__ ((aligned (16)))
-#elif defined(__MSC__)
-#  define ALIGN16      __declspec(align(16)) /* GH: Does this work? */
+#  define ALIGN16(type, array) type array __attribute__ ((aligned (16)))
+#elif defined(_MSC_VER)
+#  define ALIGN16(type, array) type array __declspec(align(16)) /* GH: Does this work? */
+#elif defined(__WATCOMC__)
+#  define ALIGN16(type, array)                     /* Watcom does not support this */ 
+#elif defined(__xlC__)
+#  define ALIGN16(type, array)       type __align (16) array 
 #else
 #  warning "ALIGN16 will not 16-byte align!\n"
 #  define ALIGN16
 #endif
 
 
-#endif /* DEBUG */
+#endif /* DEBUG_MATH */
 
 #endif /* __M_DEBUG_UTIL_H__ */