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 LLVMBuilderRef builder = bld->gallivm->builder;
44 const struct lp_type type = bld->type;
47 assert(lp_check_value(type, a));
48 assert(lp_check_value(type, b));
50 /* can't do bitwise ops on floating-point values */
52 a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
53 b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
56 res = LLVMBuildOr(builder, a, b, "");
59 res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
70 lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
72 LLVMBuilderRef builder = bld->gallivm->builder;
73 const struct lp_type type = bld->type;
76 assert(lp_check_value(type, a));
77 assert(lp_check_value(type, b));
79 /* can't do bitwise ops on floating-point values */
81 a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
82 b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
85 res = LLVMBuildAnd(builder, a, b, "");
88 res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
99 lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
101 LLVMBuilderRef builder = bld->gallivm->builder;
102 const struct lp_type type = bld->type;
105 assert(lp_check_value(type, a));
106 assert(lp_check_value(type, b));
108 /* can't do bitwise ops on floating-point values */
110 a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
111 b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
114 res = LLVMBuildNot(builder, b, "");
115 res = LLVMBuildAnd(builder, a, res, "");
118 res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
129 lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
131 LLVMBuilderRef builder = bld->gallivm->builder;
132 const struct lp_type type = bld->type;
135 assert(!type.floating);
137 assert(lp_check_value(type, a));
138 assert(lp_check_value(type, b));
140 res = LLVMBuildShl(builder, a, b, "");
150 lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
152 LLVMBuilderRef builder = bld->gallivm->builder;
153 const struct lp_type type = bld->type;
156 assert(!type.floating);
158 assert(lp_check_value(type, a));
159 assert(lp_check_value(type, b));
162 res = LLVMBuildAShr(builder, a, b, "");
164 res = LLVMBuildLShr(builder, a, b, "");
172 * Shift left with immediate.
175 lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
177 LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
178 assert(imm <= bld->type.width);
179 return lp_build_shl(bld, a, b);
184 * Shift right with immediate.
187 lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
189 LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
190 assert(imm <= bld->type.width);
191 return lp_build_shr(bld, a, b);