1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 #include "util/u_pointer.h"
34 #include "gallivm/lp_bld.h"
35 #include "gallivm/lp_bld_init.h"
36 #include "gallivm/lp_bld_arit.h"
42 write_tsv_header(FILE *fp
)
55 #include "sse_mathfun.h"
57 typedef __m128 (*test_sincos_t
)(__m128
);
60 add_sincos_test(struct gallivm_state
*gallivm
, LLVMModuleRef module
,
61 LLVMContextRef context
, boolean sin
)
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");
70 struct lp_build_context bld
;
72 lp_build_context_init(&bld
, gallivm
, lp_float32_vec4_type());
74 LLVMSetFunctionCallConv(func
, LLVMCCallConv
);
76 LLVMPositionBuilderAtEnd(builder
, block
);
77 ret
= sin
? lp_build_sin(&bld
, arg1
) : lp_build_cos(&bld
, arg1
);
78 LLVMBuildRet(builder
, ret
);
83 printv(char* string
, v4sf 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]);
94 test_sincos(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
)
96 LLVMModuleRef module
= gallivm
->module
;
97 LLVMValueRef test_sin
= NULL
, test_cos
= NULL
;
98 LLVMExecutionEngineRef engine
= gallivm
->engine
;
99 LLVMContextRef context
= gallivm
->context
;
101 test_sincos_t sin_func
;
102 test_sincos_t cos_func
;
104 boolean success
= TRUE
;
106 test_sin
= add_sincos_test(gallivm
, module
, context
, TRUE
);
107 test_cos
= add_sincos_test(gallivm
, module
, context
,FALSE
);
109 if(LLVMVerifyModule(module
, LLVMPrintMessageAction
, &error
)) {
110 printf("LLVMVerifyModule: %s\n", error
);
111 LLVMDumpModule(module
);
114 LLVMDisposeMessage(error
);
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
));
119 memset(unpacked
, 0, sizeof unpacked
);
122 // LLVMDumpModule(module);
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
));
131 LLVMFreeMachineCodeForFunction(engine
, test_sin
);
132 LLVMFreeMachineCodeForFunction(engine
, test_cos
);
137 #else /* !PIPE_ARCH_SSE */
140 test_sincos(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
)
145 #endif /* !PIPE_ARCH_SSE */
149 test_all(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
)
151 boolean success
= TRUE
;
153 test_sincos(gallivm
, verbose
, fp
);
160 test_some(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
,
163 return test_all(gallivm
, verbose
, fp
);
167 test_single(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
)
169 printf("no test_single()");