3
* Mesa 3-D graphics library
6
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
* Gareth Hughes <gareth@valinux.com>
29
#ifndef __M_DEBUG_UTIL_H__
30
#define __M_DEBUG_UTIL_H__
33
#ifdef DEBUG /* This code only used for debugging */
36
/* Comment this out to deactivate the cycle counter.
37
* NOTE: it works only on CPUs which know the 'rdtsc' command (586 or higher)
38
* (hope, you don't try to debug Mesa on a 386 ;)
40
#if defined(__GNUC__) && \
41
((defined(__i386__) && defined(USE_X86_ASM)) || \
42
(defined(__sparc__) && defined(USE_SPARC_ASM)))
43
#define RUN_DEBUG_BENCHMARK
46
#define TEST_COUNT 128 /* size of the tested vector array */
48
#define REQUIRED_PRECISION 10 /* allow 4 bits to miss */
49
#define MAX_PRECISION 24 /* max. precision possible */
52
#ifdef RUN_DEBUG_BENCHMARK
53
/* Overhead of profiling counter in cycles. Automatically adjusted to
54
* your machine at run time - counter initialization should give very
57
extern long counter_overhead;
59
/* This is the value of the environment variable MESA_PROFILE, and is
60
* used to determine if we should benchmark the functions as well as
61
* verify their correctness.
63
extern char *mesa_profile;
65
/* Modify the the number of tests if you like.
66
* We take the minimum of all results, because every error should be
67
* positive (time used by other processes, task switches etc).
68
* It is assumed that all calculations are done in the cache.
73
#if 1 /* PPro, PII, PIII version */
75
/* Profiling on the P6 architecture requires a little more work, due to
76
* the internal out-of-order execution. We must perform a serializing
77
* 'cpuid' instruction before and after the 'rdtsc' instructions to make
78
* sure no other uops are executed when we sample the timestamp counter.
80
#define INIT_COUNTER() \
83
counter_overhead = LONG_MAX; \
84
for ( cycle_i = 0 ; cycle_i < 8 ; cycle_i++ ) { \
85
long cycle_tmp1 = 0, cycle_tmp2 = 0; \
86
__asm__ __volatile__ ( "push %%ebx \n" \
87
"xor %%eax, %%eax \n" \
91
"xor %%eax, %%eax \n" \
95
"xor %%eax, %%eax \n" \
99
"xor %%eax, %%eax \n" \
102
: "=m" (cycle_tmp1), "=m" (cycle_tmp2) \
103
: : "eax", "ecx", "edx" ); \
104
if ( counter_overhead > (cycle_tmp2 - cycle_tmp1) ) { \
105
counter_overhead = cycle_tmp2 - cycle_tmp1; \
110
#define BEGIN_RACE(x) \
112
for ( cycle_i = 0 ; cycle_i < 10 ; cycle_i++ ) { \
113
long cycle_tmp1 = 0, cycle_tmp2 = 0; \
114
__asm__ __volatile__ ( "push %%ebx \n" \
115
"xor %%eax, %%eax \n" \
119
"xor %%eax, %%eax \n" \
122
: "=m" (cycle_tmp1) \
123
: : "eax", "ecx", "edx" );
125
#define END_RACE(x) \
126
__asm__ __volatile__ ( "push %%ebx \n" \
127
"xor %%eax, %%eax \n" \
131
"xor %%eax, %%eax \n" \
134
: "=m" (cycle_tmp2) \
135
: : "eax", "ecx", "edx" ); \
136
if ( x > (cycle_tmp2 - cycle_tmp1) ) { \
137
x = cycle_tmp2 - cycle_tmp1; \
140
x -= counter_overhead;
142
#else /* PPlain, PMMX version */
144
/* To ensure accurate results, we stall the pipelines with the
145
* non-pairable 'cdq' instruction. This ensures all the code being
146
* profiled is complete when the 'rdtsc' instruction executes.
148
#define INIT_COUNTER(x) \
152
for ( cycle_i = 0 ; cycle_i < 32 ; cycle_i++ ) { \
153
long cycle_tmp1, cycle_tmp2, dummy; \
154
__asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp1) ); \
155
__asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp2) ); \
158
__asm__ ( "rdtsc" : "=a" (cycle_tmp1), "=d" (dummy) ); \
161
__asm__ ( "rdtsc" : "=a" (cycle_tmp2), "=d" (dummy) ); \
162
if ( x > (cycle_tmp2 - cycle_tmp1) ) \
163
x = cycle_tmp2 - cycle_tmp1; \
167
#define BEGIN_RACE(x) \
169
for ( cycle_i = 0 ; cycle_i < 16 ; cycle_i++ ) { \
170
long cycle_tmp1, cycle_tmp2, dummy; \
171
__asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp1) ); \
172
__asm__ ( "mov %%eax, %0" : "=a" (cycle_tmp2) ); \
175
__asm__ ( "rdtsc" : "=a" (cycle_tmp1), "=d" (dummy) );
178
#define END_RACE(x) \
181
__asm__ ( "rdtsc" : "=a" (cycle_tmp2), "=d" (dummy) ); \
182
if ( x > (cycle_tmp2 - cycle_tmp1) ) \
183
x = cycle_tmp2 - cycle_tmp1; \
185
x -= counter_overhead;
189
#elif defined(__sparc__)
191
#define INIT_COUNTER() \
192
do { counter_overhead = 5; } while(0)
194
#define BEGIN_RACE(x) \
196
for (cycle_i = 0; cycle_i <10; cycle_i++) { \
197
register long cycle_tmp1 asm("l0"); \
198
register long cycle_tmp2 asm("l1"); \
199
/* rd %tick, %l0 */ \
200
__asm__ __volatile__ (".word 0xa1410000" : "=r" (cycle_tmp1)); /* save timestamp */
202
#define END_RACE(x) \
203
/* rd %tick, %l1 */ \
204
__asm__ __volatile__ (".word 0xa3410000" : "=r" (cycle_tmp2)); \
205
if (x > (cycle_tmp2-cycle_tmp1)) x = cycle_tmp2 - cycle_tmp1; \
207
x -= counter_overhead;
210
#error Your processor is not supported for RUN_XFORM_BENCHMARK
215
#define BEGIN_RACE(x)
221
/* =============================================================
225
static GLfloat rnd( void )
227
GLfloat f = (GLfloat)rand() / (GLfloat)RAND_MAX;
228
GLfloat gran = (GLfloat)(1 << 13);
230
f = (GLfloat)(GLint)(f * gran) / gran;
232
return f * 2.0 - 1.0;
235
static int significand_match( GLfloat a, GLfloat b )
238
int a_ex, b_ex, d_ex;
241
return MAX_PRECISION; /* Exact match */
244
if ( a == 0.0F || b == 0.0F ) {
245
/* It would probably be better to check if the
246
* non-zero number is denormalized and return
247
* the index of the highest set bit here.
263
enum { NIL = 0, ONE = 1, NEG = -1, VAR = 2 };
265
static void init_matrix( GLfloat *m )
267
m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0;
268
m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] = 7.0;
269
m[2] = 44.0; m[6] = 9.0; m[10] = 7.0; m[14] = 3.0;
270
m[3] = 11.0; m[7] = 23.0; m[11] = 91.0; m[15] = 9.0;
274
/* Ensure our arrays are correctly aligned.
276
#if defined(__GNUC__)
277
# define ALIGN16 __attribute__ ((aligned (16)))
278
#elif defined(__MSC__)
279
# define ALIGN16 __declspec(align(16)) /* GH: Does this work? */
281
# warning "ALIGN16 will not 16-byte align!\n"
288
#endif /* __M_DEBUG_UTIL_H__ */