1 /**************************************************************************
3 * Copyright 2009 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 **************************************************************************/
29 #include "pipe/p_defines.h"
30 #include "lp_bld_type.h"
31 #include "lp_bld_intr.h"
32 #include "lp_bld_logic.h"
36 lp_build_cmp(struct lp_build_context
*bld
,
41 const union lp_type type
= bld
->type
;
42 LLVMTypeRef vec_type
= lp_build_vec_type(type
);
43 LLVMTypeRef int_vec_type
= lp_build_int_vec_type(type
);
44 LLVMValueRef zeros
= LLVMConstNull(int_vec_type
);
45 LLVMValueRef ones
= LLVMConstAllOnes(int_vec_type
);
48 if(func
== PIPE_FUNC_NEVER
)
50 if(func
== PIPE_FUNC_ALWAYS
)
53 /* TODO: optimize the constant case */
55 /* XXX: It is not clear if we should use the ordered or unordered operators */
57 #if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
58 if(type
.width
* type
.length
== 128) {
70 case PIPE_FUNC_NOTEQUAL
:
76 case PIPE_FUNC_LEQUAL
:
79 case PIPE_FUNC_GREATER
:
83 case PIPE_FUNC_GEQUAL
:
101 args
[2] = LLVMConstInt(LLVMInt8Type(), cc
, 0);
102 res
= lp_build_intrinsic(bld
->builder
,
103 "llvm.x86.sse.cmp.ps",
106 res
= LLVMBuildBitCast(bld
->builder
, res
, int_vec_type
, "");
113 LLVMRealPredicate op
;
115 case PIPE_FUNC_NEVER
:
116 op
= LLVMRealPredicateFalse
;
118 case PIPE_FUNC_ALWAYS
:
119 op
= LLVMRealPredicateTrue
;
121 case PIPE_FUNC_EQUAL
:
124 case PIPE_FUNC_NOTEQUAL
:
130 case PIPE_FUNC_LEQUAL
:
133 case PIPE_FUNC_GREATER
:
136 case PIPE_FUNC_GEQUAL
:
143 cond
= LLVMBuildFCmp(bld
->builder
, op
, a
, b
, "");
148 case PIPE_FUNC_EQUAL
:
151 case PIPE_FUNC_NOTEQUAL
:
155 op
= type
.sign
? LLVMIntSLT
: LLVMIntULT
;
157 case PIPE_FUNC_LEQUAL
:
158 op
= type
.sign
? LLVMIntSLE
: LLVMIntULE
;
160 case PIPE_FUNC_GREATER
:
161 op
= type
.sign
? LLVMIntSGT
: LLVMIntUGT
;
163 case PIPE_FUNC_GEQUAL
:
164 op
= type
.sign
? LLVMIntSGE
: LLVMIntUGE
;
170 cond
= LLVMBuildICmp(bld
->builder
, op
, a
, b
, "");
173 return LLVMBuildSelect(bld
->builder
, cond
, ones
, zeros
, "");