14a49301eSmrg/**************************************************************************
24a49301eSmrg *
34a49301eSmrg * Copyright 2009 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
54a49301eSmrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
134a49301eSmrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
174a49301eSmrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
214a49301eSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254a49301eSmrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
284a49301eSmrg/**
294a49301eSmrg * @file
304a49301eSmrg * Shared testing code.
314a49301eSmrg *
324a49301eSmrg * @author Jose Fonseca <jfonseca@vmware.com>
334a49301eSmrg */
344a49301eSmrg
354a49301eSmrg
364a49301eSmrg#ifndef LP_TEST_H
374a49301eSmrg#define LP_TEST_H
384a49301eSmrg
394a49301eSmrg
404a49301eSmrg#include <stdlib.h>
414a49301eSmrg#include <stdio.h>
424a49301eSmrg#include <float.h>
434a49301eSmrg
443464ebd5Sriastradh#include "gallivm/lp_bld.h"
454a49301eSmrg
464a49301eSmrg#include "pipe/p_state.h"
477ec681f3Smrg#include "util/format/u_format.h"
484a49301eSmrg#include "util/u_math.h"
49cdc920a0Smrg#include "util/u_dump.h"
504a49301eSmrg
51cdc920a0Smrg#include "gallivm/lp_bld_type.h"
524a49301eSmrg
534a49301eSmrg
544a49301eSmrg#define LP_TEST_NUM_SAMPLES 32
554a49301eSmrg
564a49301eSmrg
574a49301eSmrgvoid
584a49301eSmrgwrite_tsv_header(FILE *fp);
594a49301eSmrg
604a49301eSmrg
614a49301eSmrgboolean
62af69d88dSmrgtest_some(unsigned verbose, FILE *fp,
633464ebd5Sriastradh          unsigned long n);
644a49301eSmrg
653464ebd5Sriastradhboolean
66af69d88dSmrgtest_single(unsigned verbose, FILE *fp);
674a49301eSmrg
684a49301eSmrgboolean
69af69d88dSmrgtest_all(unsigned verbose, FILE *fp);
704a49301eSmrg
714a49301eSmrg
724a49301eSmrg#if defined(PIPE_CC_MSVC)
734a49301eSmrg
7401e04c3fSmrg#include <intrin.h>
754a49301eSmrg#define rdtsc() __rdtsc()
764a49301eSmrg
774a49301eSmrg#elif defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
784a49301eSmrg
7901e04c3fSmrgstatic inline uint64_t
804a49301eSmrgrdtsc(void)
814a49301eSmrg{
824a49301eSmrg   uint32_t hi, lo;
834a49301eSmrg   __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
844a49301eSmrg   return ((uint64_t)lo) | (((uint64_t)hi) << 32);
854a49301eSmrg}
864a49301eSmrg
874a49301eSmrg#else
884a49301eSmrg
894a49301eSmrg#define rdtsc() 0
904a49301eSmrg
914a49301eSmrg#endif
924a49301eSmrg
934a49301eSmrg
944a49301eSmrg
954a49301eSmrgfloat
964a49301eSmrgrandom_float(void);
974a49301eSmrg
984a49301eSmrg
994a49301eSmrgvoid
1004a49301eSmrgdump_type(FILE *fp, struct lp_type type);
1014a49301eSmrg
1024a49301eSmrg
1034a49301eSmrgdouble
1044a49301eSmrgread_elem(struct lp_type type, const void *src, unsigned index);
1054a49301eSmrg
1064a49301eSmrg
1074a49301eSmrgvoid
1084a49301eSmrgwrite_elem(struct lp_type type, void *dst, unsigned index, double src);
1094a49301eSmrg
1104a49301eSmrg
1114a49301eSmrgvoid
1124a49301eSmrgrandom_elem(struct lp_type type, void *dst, unsigned index);
1134a49301eSmrg
1144a49301eSmrg
1154a49301eSmrgvoid
1164a49301eSmrgread_vec(struct lp_type type, const void *src, double *dst);
1174a49301eSmrg
1184a49301eSmrg
1194a49301eSmrgvoid
1204a49301eSmrgwrite_vec(struct lp_type type, void *dst, const double *src);
1214a49301eSmrg
1224a49301eSmrg
1234a49301eSmrgvoid
1244a49301eSmrgrandom_vec(struct lp_type type, void *dst);
1254a49301eSmrg
1264a49301eSmrg
1274a49301eSmrgboolean
1284a49301eSmrgcompare_vec_with_eps(struct lp_type type, const void *res, const void *ref, double eps);
1294a49301eSmrg
1304a49301eSmrg
1314a49301eSmrgboolean
1324a49301eSmrgcompare_vec(struct lp_type type, const void *res, const void *ref);
1334a49301eSmrg
1344a49301eSmrg
1354a49301eSmrgvoid
1364a49301eSmrgdump_vec(FILE *fp, struct lp_type type, const void *src);
1374a49301eSmrg
1384a49301eSmrg
1394a49301eSmrg#endif /* !LP_TEST_H */
140