svga: Don't advertise pixel shader addr register support.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_test_sincos.c
1 /**************************************************************************
2 *
3 * Copyright 2010 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 #include <stdlib.h>
30 #include <stdio.h>
31
32 #include "util/u_pointer.h"
33
34 #include "gallivm/lp_bld.h"
35 #include "gallivm/lp_bld_init.h"
36 #include "gallivm/lp_bld_arit.h"
37
38 #include "lp_test.h"
39
40
41 void
42 write_tsv_header(FILE *fp)
43 {
44 fprintf(fp,
45 "result\t"
46 "format\n");
47
48 fflush(fp);
49 }
50
51
52 #ifdef PIPE_ARCH_SSE
53
54 #define USE_SSE2
55 #include "sse_mathfun.h"
56
57 typedef __m128 (*test_sincos_t)(__m128);
58
59 static LLVMValueRef
60 add_sincos_test(struct gallivm_state *gallivm, LLVMModuleRef module,
61 LLVMContextRef context, boolean sin)
62 {
63 LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(context), 4);
64 LLVMTypeRef args[1] = { v4sf };
65 LLVMValueRef func = LLVMAddFunction(module, "sincos", LLVMFunctionType(v4sf, args, 1, 0));
66 LLVMValueRef arg1 = LLVMGetParam(func, 0);
67 LLVMBuilderRef builder = gallivm->builder;
68 LLVMBasicBlockRef block = LLVMAppendBasicBlockInContext(context, func, "entry");
69 LLVMValueRef ret;
70 struct lp_build_context bld;
71
72 lp_build_context_init(&bld, gallivm, lp_float32_vec4_type());
73
74 LLVMSetFunctionCallConv(func, LLVMCCallConv);
75
76 LLVMPositionBuilderAtEnd(builder, block);
77 ret = sin ? lp_build_sin(&bld, arg1) : lp_build_cos(&bld, arg1);
78 LLVMBuildRet(builder, ret);
79 return func;
80 }
81
82 static void
83 printv(char* string, v4sf value)
84 {
85 v4sf v = value;
86 uint32_t *p = (uint32_t *) &v;
87 float *f = (float *)&v;
88 printf("%s: %f(%x) %f(%x) %f(%x) %f(%x)\n", string,
89 f[0], p[0], f[1], p[1], f[2], p[2], f[3], p[3]);
90 }
91
92 PIPE_ALIGN_STACK
93 static boolean
94 test_sincos(struct gallivm_state *gallivm, unsigned verbose, FILE *fp)
95 {
96 LLVMModuleRef module = gallivm->module;
97 LLVMValueRef test_sin = NULL, test_cos = NULL;
98 LLVMExecutionEngineRef engine = gallivm->engine;
99 LLVMContextRef context = gallivm->context;
100 char *error = NULL;
101 test_sincos_t sin_func;
102 test_sincos_t cos_func;
103 float unpacked[4];
104 boolean success = TRUE;
105
106 test_sin = add_sincos_test(gallivm, module, context, TRUE);
107 test_cos = add_sincos_test(gallivm, module, context,FALSE);
108
109 if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) {
110 printf("LLVMVerifyModule: %s\n", error);
111 LLVMDumpModule(module);
112 abort();
113 }
114 LLVMDisposeMessage(error);
115
116 sin_func = (test_sincos_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_sin));
117 cos_func = (test_sincos_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_cos));
118
119 memset(unpacked, 0, sizeof unpacked);
120
121
122 // LLVMDumpModule(module);
123 {
124 v4sf src = {3.14159/4.0, -3.14159/4.0, 1.0, -1.0};
125 printv("ref ",sin_ps(src));
126 printv("llvm", sin_func(src));
127 printv("ref ",cos_ps(src));
128 printv("llvm",cos_func(src));
129 }
130
131 LLVMFreeMachineCodeForFunction(engine, test_sin);
132 LLVMFreeMachineCodeForFunction(engine, test_cos);
133
134 return success;
135 }
136
137 #else /* !PIPE_ARCH_SSE */
138
139 static boolean
140 test_sincos(struct gallivm_state *gallivm, unsigned verbose, FILE *fp)
141 {
142 return TRUE;
143 }
144
145 #endif /* !PIPE_ARCH_SSE */
146
147
148 boolean
149 test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp)
150 {
151 boolean success = TRUE;
152
153 test_sincos(gallivm, verbose, fp);
154
155 return success;
156 }
157
158
159 boolean
160 test_some(struct gallivm_state *gallivm, unsigned verbose, FILE *fp,
161 unsigned long n)
162 {
163 return test_all(gallivm, verbose, fp);
164 }
165
166 boolean
167 test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp)
168 {
169 printf("no test_single()");
170 return TRUE;
171 }