lp_test.h revision efc82aef35a2aac5d2ed9774f6d28f2626796416
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 <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 "gallivm/lp_bld.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_dump.h" 55 56#include "gallivm/lp_bld_type.h" 57 58 59#define LP_TEST_NUM_SAMPLES 32 60 61 62void 63write_tsv_header(FILE *fp); 64 65 66boolean 67test_some(struct gallivm_state *gallivm,unsigned verbose, FILE *fp, 68 unsigned long n); 69 70boolean 71test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp); 72 73boolean 74test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp); 75 76 77#if defined(PIPE_CC_MSVC) 78 79unsigned __int64 __rdtsc(); 80#pragma intrinsic(__rdtsc) 81#define rdtsc() __rdtsc() 82 83#elif defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)) 84 85static INLINE uint64_t 86rdtsc(void) 87{ 88 uint32_t hi, lo; 89 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); 90 return ((uint64_t)lo) | (((uint64_t)hi) << 32); 91} 92 93#else 94 95#define rdtsc() 0 96 97#endif 98 99 100 101float 102random_float(void); 103 104 105void 106dump_type(FILE *fp, struct lp_type type); 107 108 109double 110read_elem(struct lp_type type, const void *src, unsigned index); 111 112 113void 114write_elem(struct lp_type type, void *dst, unsigned index, double src); 115 116 117void 118random_elem(struct lp_type type, void *dst, unsigned index); 119 120 121void 122read_vec(struct lp_type type, const void *src, double *dst); 123 124 125void 126write_vec(struct lp_type type, void *dst, const double *src); 127 128 129void 130random_vec(struct lp_type type, void *dst); 131 132 133boolean 134compare_vec_with_eps(struct lp_type type, const void *res, const void *ref, double eps); 135 136 137boolean 138compare_vec(struct lp_type type, const void *res, const void *ref); 139 140 141void 142dump_vec(FILE *fp, struct lp_type type, const void *src); 143 144 145#endif /* !LP_TEST_H */ 146