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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 **************************************************************************/
29 #include "util/u_debug.h"
31 #include "lp_bld_type.h"
32 #include "lp_bld_debug.h"
33 #include "lp_bld_const.h"
34 #include "lp_bld_bitarit.h"
41 lp_build_or(struct lp_build_context
*bld
, LLVMValueRef a
, LLVMValueRef b
)
43 const struct lp_type type
= bld
->type
;
46 assert(lp_check_value(type
, a
));
47 assert(lp_check_value(type
, b
));
49 /* can't do bitwise ops on floating-point values */
51 a
= LLVMBuildBitCast(bld
->builder
, a
, bld
->int_vec_type
, "");
52 b
= LLVMBuildBitCast(bld
->builder
, b
, bld
->int_vec_type
, "");
55 res
= LLVMBuildOr(bld
->builder
, a
, b
, "");
58 res
= LLVMBuildBitCast(bld
->builder
, res
, bld
->vec_type
, "");
69 lp_build_and(struct lp_build_context
*bld
, LLVMValueRef a
, LLVMValueRef b
)
71 const struct lp_type type
= bld
->type
;
74 assert(lp_check_value(type
, a
));
75 assert(lp_check_value(type
, b
));
77 /* can't do bitwise ops on floating-point values */
79 a
= LLVMBuildBitCast(bld
->builder
, a
, bld
->int_vec_type
, "");
80 b
= LLVMBuildBitCast(bld
->builder
, b
, bld
->int_vec_type
, "");
83 res
= LLVMBuildAnd(bld
->builder
, a
, b
, "");
86 res
= LLVMBuildBitCast(bld
->builder
, res
, bld
->vec_type
, "");
97 lp_build_andnot(struct lp_build_context
*bld
, LLVMValueRef a
, LLVMValueRef b
)
99 const struct lp_type type
= bld
->type
;
102 assert(lp_check_value(type
, a
));
103 assert(lp_check_value(type
, b
));
105 /* can't do bitwise ops on floating-point values */
107 a
= LLVMBuildBitCast(bld
->builder
, a
, bld
->int_vec_type
, "");
108 b
= LLVMBuildBitCast(bld
->builder
, b
, bld
->int_vec_type
, "");
111 res
= LLVMBuildNot(bld
->builder
, b
, "");
112 res
= LLVMBuildAnd(bld
->builder
, a
, res
, "");
115 res
= LLVMBuildBitCast(bld
->builder
, res
, bld
->vec_type
, "");
126 lp_build_shl(struct lp_build_context
*bld
, LLVMValueRef a
, LLVMValueRef b
)
128 const struct lp_type type
= bld
->type
;
131 assert(!type
.floating
);
133 assert(lp_check_value(type
, a
));
134 assert(lp_check_value(type
, b
));
136 res
= LLVMBuildShl(bld
->builder
, a
, b
, "");
146 lp_build_shr(struct lp_build_context
*bld
, LLVMValueRef a
, LLVMValueRef b
)
148 const struct lp_type type
= bld
->type
;
151 assert(!type
.floating
);
153 assert(lp_check_value(type
, a
));
154 assert(lp_check_value(type
, b
));
157 res
= LLVMBuildAShr(bld
->builder
, a
, b
, "");
159 res
= LLVMBuildLShr(bld
->builder
, a
, b
, "");
167 * Shift left with immediate.
170 lp_build_shl_imm(struct lp_build_context
*bld
, LLVMValueRef a
, unsigned imm
)
172 LLVMValueRef b
= lp_build_const_int_vec(bld
->type
, imm
);
173 assert(imm
<= bld
->type
.width
);
174 return lp_build_shl(bld
, a
, b
);
179 * Shift right with immediate.
182 lp_build_shr_imm(struct lp_build_context
*bld
, LLVMValueRef a
, unsigned imm
)
184 LLVMValueRef b
= lp_build_const_int_vec(bld
->type
, imm
);
185 assert(imm
<= bld
->type
.width
);
186 return lp_build_shr(bld
, a
, b
);