From aec11e4daa36fb31774971ce34f04e3ebeeeeed7 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 17 Feb 2012 19:02:21 +0000 Subject: [PATCH] gallivm: add bitarit xor and not ops. Signed-off-by: Dave Airlie --- src/gallium/auxiliary/gallivm/lp_bld_bitarit.c | 44 ++++++++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_bitarit.h | 5 +++ 2 files changed, 49 insertions(+) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c index a9c57d6..97ae162 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c @@ -62,6 +62,31 @@ lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) return res; } +/* bitwise XOR (a ^ b) */ +LLVMValueRef +lp_build_xor(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + /* can't do bitwise ops on floating-point values */ + if (type.floating) { + a = LLVMBuildBitCast(builder, a, bld->int_vec_type, ""); + b = LLVMBuildBitCast(builder, b, bld->int_vec_type, ""); + } + + res = LLVMBuildXor(builder, a, b, ""); + + if (type.floating) { + res = LLVMBuildBitCast(builder, res, bld->vec_type, ""); + } + + return res; +} /** * Return (a & b) @@ -121,6 +146,25 @@ lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) return res; } +/* bitwise NOT */ +LLVMValueRef +lp_build_not(struct lp_build_context *bld, LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + + if (type.floating) { + a = LLVMBuildBitCast(builder, a, bld->int_vec_type, ""); + } + res = LLVMBuildNot(builder, a, ""); + if (type.floating) { + res = LLVMBuildBitCast(builder, res, bld->vec_type, ""); + } + return res; +} /** * Shift left. diff --git a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.h b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.h index 5c5b981..29f5def 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.h @@ -48,6 +48,9 @@ LLVMValueRef lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); LLVMValueRef +lp_build_xor(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); + +LLVMValueRef lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); LLVMValueRef @@ -65,5 +68,7 @@ lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm); LLVMValueRef lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm); +LLVMValueRef +lp_build_not(struct lp_build_context *bld, LLVMValueRef a); #endif /* !LP_BLD_ARIT_H */ -- 2.7.4