1e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca/**************************************************************************
2e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca *
3e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * Copyright 2009 VMware, Inc.
4e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * All Rights Reserved.
5e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca *
6e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * Permission is hereby granted, free of charge, to any person obtaining a
7e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * copy of this software and associated documentation files (the
8e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * "Software"), to deal in the Software without restriction, including
9e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * without limitation the rights to use, copy, modify, merge, publish,
10e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * distribute, sub license, and/or sell copies of the Software, and to
11e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * permit persons to whom the Software is furnished to do so, subject to
12e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * the following conditions:
13e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca *
14e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * The above copyright notice and this permission notice (including the
15e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * next paragraph) shall be included in all copies or substantial portions
16e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * of the Software.
17e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca *
18e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca *
26e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca **************************************************************************/
27e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
28e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca/**
29e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * @file
30e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * Shared testing code.
31e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca *
32e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca * @author Jose Fonseca <jfonseca@vmware.com>
33e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca */
34e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
35e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
36e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#ifndef LP_TEST_H
37e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#define LP_TEST_H
38e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
39e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
40e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#include <stdlib.h>
41e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#include <stdio.h>
42e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#include <float.h>
43e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
440d71ba46e613230c84165106c1fcc9027dec4cd3Brian Paul#include "gallivm/lp_bld.h"
45e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
46e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#include "pipe/p_state.h"
47e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#include "util/u_format.h"
48e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#include "util/u_math.h"
49abdcdb3db73316c5ebca88bda04b90b6659782e8José Fonseca#include "util/u_dump.h"
50e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
51c61bf363937f40624a5632745630d4f2b9907082Zack Rusin#include "gallivm/lp_bld_type.h"
52e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
53e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
549aafa1fbd247cd6d1bb0ab47bc5b318bd0d67bc5José Fonseca#define LP_TEST_NUM_SAMPLES 32
559aafa1fbd247cd6d1bb0ab47bc5b318bd0d67bc5José Fonseca
569aafa1fbd247cd6d1bb0ab47bc5b318bd0d67bc5José Fonseca
57e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
58e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecawrite_tsv_header(FILE *fp);
59e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
60e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
61e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecaboolean
623469715a8a171512cf9b528702e70393f01c6041José Fonsecatest_some(unsigned verbose, FILE *fp,
63efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul          unsigned long n);
64e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
654f067ada47bfeef792e5adbed4f3e215b704212aBrian Paulboolean
663469715a8a171512cf9b528702e70393f01c6041José Fonsecatest_single(unsigned verbose, FILE *fp);
67e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
68e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecaboolean
693469715a8a171512cf9b528702e70393f01c6041José Fonsecatest_all(unsigned verbose, FILE *fp);
70e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
71e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
72ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca#if defined(PIPE_CC_MSVC)
73ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca
74ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonsecaunsigned __int64 __rdtsc();
75ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca#pragma intrinsic(__rdtsc)
76ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca#define rdtsc() __rdtsc()
77ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca
78ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca#elif defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
79ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca
80e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecastatic INLINE uint64_t
81e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecardtsc(void)
82e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca{
83e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca   uint32_t hi, lo;
84e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca   __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
85e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca   return ((uint64_t)lo) | (((uint64_t)hi) << 32);
86ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca}
87ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca
88e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#else
89ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca
90ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca#define rdtsc() 0
91ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca
92e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#endif
93ba8c11923a13bdec53128988ffc26ceb5c4f7310José Fonseca
94e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
95e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
96e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecafloat
97e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecarandom_float(void);
98e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
99e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
100e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
101b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecadump_type(FILE *fp, struct lp_type type);
102e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
103e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
104e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecadouble
105b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecaread_elem(struct lp_type type, const void *src, unsigned index);
106e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
107e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
108e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
109b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecawrite_elem(struct lp_type type, void *dst, unsigned index, double src);
110e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
111e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
112e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
113b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecarandom_elem(struct lp_type type, void *dst, unsigned index);
114e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
115e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
116e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
117b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecaread_vec(struct lp_type type, const void *src, double *dst);
118e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
119e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
120e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
121b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecawrite_vec(struct lp_type type, void *dst, const double *src);
122e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
123e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
124e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
125b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecarandom_vec(struct lp_type type, void *dst);
126e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
127e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
128e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecaboolean
129b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecacompare_vec_with_eps(struct lp_type type, const void *res, const void *ref, double eps);
1303dbf00f9ab0d2e771c72a74d9db32c048ce7df4eJosé Fonseca
1313dbf00f9ab0d2e771c72a74d9db32c048ce7df4eJosé Fonseca
1323dbf00f9ab0d2e771c72a74d9db32c048ce7df4eJosé Fonsecaboolean
133b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecacompare_vec(struct lp_type type, const void *res, const void *ref);
134e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
135e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
136e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonsecavoid
137b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecadump_vec(FILE *fp, struct lp_type type, const void *src);
138e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
139e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca
140e6ebebc4853c98aa387b2c39a886a0c1173e93fbJosé Fonseca#endif /* !LP_TEST_H */
141