xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/llvmpipe/lp_test.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2009 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 /**
29  * @file
30  * Shared testing code.
31  *
32  * @author Jose Fonseca <[email protected]>
33  */
34 
35 
36 #ifndef LP_TEST_H
37 #define LP_TEST_H
38 
39 
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <float.h>
43 
44 #include "gallivm/lp_bld.h"
45 
46 #include "pipe/p_state.h"
47 #include "util/format/u_format.h"
48 #include "util/u_math.h"
49 #include "util/u_dump.h"
50 
51 #include "gallivm/lp_bld_type.h"
52 
53 
54 #define LP_TEST_NUM_SAMPLES 32
55 
56 
57 void
58 write_tsv_header(FILE *fp);
59 
60 
61 bool
62 test_some(unsigned verbose, FILE *fp,
63           unsigned long n);
64 
65 bool
66 test_single(unsigned verbose, FILE *fp);
67 
68 bool
69 test_all(unsigned verbose, FILE *fp);
70 
71 
72 #if DETECT_CC_MSVC
73 
74 #include <intrin.h>
75 #define rdtsc() __rdtsc()
76 
77 #elif DETECT_CC_GCC && (DETECT_ARCH_X86 || DETECT_ARCH_X86_64)
78 
79 static inline uint64_t
rdtsc(void)80 rdtsc(void)
81 {
82    uint32_t hi, lo;
83    __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
84    return ((uint64_t)lo) | (((uint64_t)hi) << 32);
85 }
86 
87 #else
88 
89 #define rdtsc() 0
90 
91 #endif
92 
93 
94 
95 float
96 random_float(void);
97 
98 
99 void
100 dump_type(FILE *fp, struct lp_type type);
101 
102 
103 double
104 read_elem(struct lp_type type, const void *src, unsigned index);
105 
106 
107 void
108 write_elem(struct lp_type type, void *dst, unsigned index, double src);
109 
110 
111 void
112 random_elem(struct lp_type type, void *dst, unsigned index);
113 
114 
115 void
116 read_vec(struct lp_type type, const void *src, double *dst);
117 
118 
119 void
120 write_vec(struct lp_type type, void *dst, const double *src);
121 
122 
123 void
124 random_vec(struct lp_type type, void *dst);
125 
126 
127 bool
128 compare_vec_with_eps(struct lp_type type, const void *res, const void *ref, double eps);
129 
130 
131 bool
132 compare_vec(struct lp_type type, const void *res, const void *ref);
133 
134 
135 void
136 dump_vec(FILE *fp, struct lp_type type, const void *src);
137 
138 
139 #endif /* !LP_TEST_H */
140