79e369ebd5daf33f9fde19cdef976d2a20256085
1 /* $Id: m_debug_util.h,v 1.2 2001/03/12 00:48:41 gareth Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Gareth Hughes <gareth@valinux.com>
30 #ifndef __M_DEBUG_UTIL_H__
31 #define __M_DEBUG_UTIL_H__
34 #ifdef DEBUG /* This code only used for debugging */
37 /* Comment this out to deactivate the cycle counter.
38 * NOTE: it works only on CPUs which know the 'rdtsc' command (586 or higher)
39 * (hope, you don't try to debug Mesa on a 386 ;)
41 #if defined(__GNUC__) && defined(__i386__) && defined(USE_X86_ASM)
42 #define RUN_DEBUG_BENCHMARK
45 #define TEST_COUNT 128 /* size of the tested vector array */
47 #define REQUIRED_PRECISION 10 /* allow 4 bits to miss */
48 #define MAX_PRECISION 24 /* max. precision possible */
51 #ifdef RUN_DEBUG_BENCHMARK
52 /* Overhead of profiling counter in cycles. Automatically adjusted to
53 * your machine at run time - counter initialization should give very
56 extern long counter_overhead
;
58 /* This is the value of the environment variable MESA_PROFILE, and is
59 * used to determine if we should benchmark the functions as well as
60 * verify their correctness.
62 extern char *mesa_profile
;
64 /* Modify the the number of tests if you like.
65 * We take the minimum of all results, because every error should be
66 * positive (time used by other processes, task switches etc).
67 * It is assumed that all calculations are done in the cache.
70 #if 1 /* PPro, PII, PIII version */
72 /* Profiling on the P6 architecture requires a little more work, due to
73 * the internal out-of-order execution. We must perform a serializing
74 * 'cpuid' instruction before and after the 'rdtsc' instructions to make
75 * sure no other uops are executed when we sample the timestamp counter.
77 #define INIT_COUNTER() \
80 counter_overhead = LONG_MAX; \
81 for ( cycle_i = 0 ; cycle_i < 8 ; cycle_i++ ) { \
82 long cycle_tmp1 = 0, cycle_tmp2 = 0; \
83 __asm__ __volatile__ ( "push %%ebx \n" \
84 "xor %%eax, %%eax \n" \
88 "xor %%eax, %%eax \n" \
92 "xor %%eax, %%eax \n" \
96 "xor %%eax, %%eax \n" \
99 : "=m" (cycle_tmp1), "=m" (cycle_tmp2) \
100 : : "eax", "ecx", "edx" ); \
101 if ( counter_overhead > (cycle_tmp2 - cycle_tmp1) ) { \
102 counter_overhead = cycle_tmp2 - cycle_tmp1; \
107 #define BEGIN_RACE(x) \
109 for ( cycle_i = 0 ; cycle_i < 10 ; cycle_i++ ) { \
110 long cycle_tmp1 = 0, cycle_tmp2 = 0; \
111 __asm__ __volatile__ ( "push %%ebx \n" \
112 "xor %%eax, %%eax \n" \
116 "xor %%eax, %%eax \n" \
119 : "=m" (cycle_tmp1) \
120 : : "eax", "ecx", "edx" );
122 #define END_RACE(x) \
123 __asm__ __volatile__ ( "push %%ebx \n" \
124 "xor %%eax, %%eax \n" \
128 "xor %%eax, %%eax \n" \
131 : "=m" (cycle_tmp2) \
132 : : "eax", "ecx", "edx" ); \
133 if ( x > (cycle_tmp2 - cycle_tmp1) ) { \
134 x = cycle_tmp2 - cycle_tmp1; \
137 x -= counter_overhead;
139 #else /* PPlain, PMMX version */
141 /* To ensure accurate results, we stall the pipelines with the
142 * non-pairable 'cdq' instruction. This ensures all the code being
143 * profiled is complete when the 'rdtsc' instruction executes.
145 #define INIT_COUNTER(x) \
149 for ( cycle_i = 0 ; cycle_i < 32 ; cycle_i++ ) { \
150 long cycle_tmp1, cycle_tmp2, dummy; \
151 __asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp1) ); \
152 __asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp2) ); \
155 __asm__ ( "rdtsc" : "=a" (cycle_tmp1), "=d" (dummy) ); \
158 __asm__ ( "rdtsc" : "=a" (cycle_tmp2), "=d" (dummy) ); \
159 if ( x > (cycle_tmp2 - cycle_tmp1) ) \
160 x = cycle_tmp2 - cycle_tmp1; \
164 #define BEGIN_RACE(x) \
166 for ( cycle_i = 0 ; cycle_i < 16 ; cycle_i++ ) { \
167 long cycle_tmp1, cycle_tmp2, dummy; \
168 __asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp1) ); \
169 __asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp2) ); \
172 __asm__ ( "rdtsc" : "=a" (cycle_tmp1), "=d" (dummy) );
175 #define END_RACE(x) \
178 __asm__ ( "rdtsc" : "=a" (cycle_tmp2), "=d" (dummy) ); \
179 if ( x > (cycle_tmp2 - cycle_tmp1) ) \
180 x = cycle_tmp2 - cycle_tmp1; \
182 x -= counter_overhead;
188 #define BEGIN_RACE(x)
194 /* ================================================================
198 static GLfloat
rnd( void )
200 GLfloat f
= (GLfloat
)rand() / (GLfloat
)RAND_MAX
;
201 GLfloat gran
= (GLfloat
)(1 << 13);
203 f
= (GLfloat
)(GLint
)(f
* gran
) / gran
;
205 return f
* 2.0 - 1.0;
208 static int significand_match( GLfloat a
, GLfloat b
)
211 int a_ex
, b_ex
, d_ex
;
214 return MAX_PRECISION
; /* Exact match */
217 if ( a
== 0.0F
|| b
== 0.0F
) {
218 /* It would probably be better to check if the
219 * non-zero number is denormalized and return
220 * the index of the highest set bit here.
236 enum { NIL
= 0, ONE
= 1, NEG
= -1, VAR
= 2 };
238 static void init_matrix( GLfloat
*m
)
240 m
[0] = 63.0; m
[4] = 43.0; m
[ 8] = 29.0; m
[12] = 43.0;
241 m
[1] = 55.0; m
[5] = 17.0; m
[ 9] = 31.0; m
[13] = 7.0;
242 m
[2] = 44.0; m
[6] = 9.0; m
[10] = 7.0; m
[14] = 3.0;
243 m
[3] = 11.0; m
[7] = 23.0; m
[11] = 91.0; m
[15] = 9.0;
247 /* Ensure our arrays are correctly aligned.
249 #if defined(__GNUC__)
250 # define ALIGN16 __attribute__ ((aligned (16)))
251 #elif defined(__MSC__)
252 # define ALIGN16 __declspec(align(16)) /* GH: Does this work? */
254 # warning "ALIGN16 will not 16-byte align!\n"
261 #endif /* __M_DEBUG_UTIL_H__ */