blob: ca0f737b2953d8593e55857a383154dee6a4d91e [file] [log] [blame]
José Fonsecae6ebebc2009-08-07 01:20:01 +01001/**************************************************************************
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 <jfonseca@vmware.com>
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 <llvm-c/Core.h>
45#include <llvm-c/Analysis.h>
46#include <llvm-c/ExecutionEngine.h>
47#include <llvm-c/Target.h>
48#include <llvm-c/BitWriter.h>
49#include <llvm-c/Transforms/Scalar.h>
50
51#include "pipe/p_state.h"
52#include "util/u_format.h"
53#include "util/u_math.h"
54#include "util/u_debug_dump.h"
55
Zack Rusinc61bf362010-02-08 18:05:22 -050056#include "gallivm/lp_bld_type.h"
José Fonsecae6ebebc2009-08-07 01:20:01 +010057
58
José Fonseca9aafa1f2009-10-22 19:02:04 +010059#define LP_TEST_NUM_SAMPLES 32
60
61
José Fonsecae6ebebc2009-08-07 01:20:01 +010062void
63write_tsv_header(FILE *fp);
64
65
66boolean
67test_some(unsigned verbose, FILE *fp, unsigned long n);
68
69
70boolean
71test_all(unsigned verbose, FILE *fp);
72
73
José Fonsecaba8c1192009-10-22 19:02:42 +010074#if defined(PIPE_CC_MSVC)
75
76unsigned __int64 __rdtsc();
77#pragma intrinsic(__rdtsc)
78#define rdtsc() __rdtsc()
79
80#elif defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
81
José Fonsecae6ebebc2009-08-07 01:20:01 +010082static INLINE uint64_t
83rdtsc(void)
84{
José Fonsecae6ebebc2009-08-07 01:20:01 +010085 uint32_t hi, lo;
86 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
87 return ((uint64_t)lo) | (((uint64_t)hi) << 32);
José Fonsecae6ebebc2009-08-07 01:20:01 +010088}
89
José Fonsecaba8c1192009-10-22 19:02:42 +010090#else
91
92#define rdtsc() 0
93
94#endif
95
96
José Fonsecae6ebebc2009-08-07 01:20:01 +010097
98float
99random_float(void);
100
101
102void
José Fonsecab4835ea2009-09-14 11:05:06 +0100103dump_type(FILE *fp, struct lp_type type);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100104
105
106double
José Fonsecab4835ea2009-09-14 11:05:06 +0100107read_elem(struct lp_type type, const void *src, unsigned index);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100108
109
110void
José Fonsecab4835ea2009-09-14 11:05:06 +0100111write_elem(struct lp_type type, void *dst, unsigned index, double src);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100112
113
114void
José Fonsecab4835ea2009-09-14 11:05:06 +0100115random_elem(struct lp_type type, void *dst, unsigned index);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100116
117
118void
José Fonsecab4835ea2009-09-14 11:05:06 +0100119read_vec(struct lp_type type, const void *src, double *dst);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100120
121
122void
José Fonsecab4835ea2009-09-14 11:05:06 +0100123write_vec(struct lp_type type, void *dst, const double *src);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100124
125
126void
José Fonsecab4835ea2009-09-14 11:05:06 +0100127random_vec(struct lp_type type, void *dst);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100128
129
130boolean
José Fonsecab4835ea2009-09-14 11:05:06 +0100131compare_vec_with_eps(struct lp_type type, const void *res, const void *ref, double eps);
José Fonseca3dbf00f2009-08-21 07:35:49 +0100132
133
134boolean
José Fonsecab4835ea2009-09-14 11:05:06 +0100135compare_vec(struct lp_type type, const void *res, const void *ref);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100136
137
138void
José Fonsecab4835ea2009-09-14 11:05:06 +0100139dump_vec(FILE *fp, struct lp_type type, const void *src);
José Fonsecae6ebebc2009-08-07 01:20:01 +0100140
141
142#endif /* !LP_TEST_H */