summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2017-11-13 11:17:41 -0800
committerIan Romanick <ian.d.romanick@intel.com>2018-03-29 14:09:23 -0700
commitd76c204d0564701b4b8b6a2bdda50e2939683e66 (patch)
treeedcf51df711640ffd89326079f10b1dcf65f311b /src/gallium/auxiliary
parenta3a16d4aa7e5a22816226d8e7417138164b10525 (diff)
util: Move util_is_power_of_two to bitscan.h and rename to util_is_power_of_two_or_zero
The new name make the zero-input behavior more obvious. The next patch adds a new function with different zero-input behavior. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Suggested-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_arit.c2
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_debug.cpp2
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_aos.c4
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_gather.c8
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_pack.c2
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.c6
-rw-r--r--src/gallium/auxiliary/util/u_math.h10
-rw-r--r--src/gallium/auxiliary/util/u_ringbuffer.c2
8 files changed, 14 insertions, 22 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index 321c6e4edf..e922474ef6 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -1307,7 +1307,7 @@ lp_build_mul_imm(struct lp_build_context *bld,
if(b == 2 && bld->type.floating)
return lp_build_add(bld, a, a);
- if(util_is_power_of_two(b)) {
+ if(util_is_power_of_two_or_zero(b)) {
unsigned shift = ffs(b) - 1;
if(bld->type.floating) {
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
index f311fe7f69..23ada3d043 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
@@ -60,7 +60,7 @@
extern "C" boolean
lp_check_alignment(const void *ptr, unsigned alignment)
{
- assert(util_is_power_of_two(alignment));
+ assert(util_is_power_of_two_or_zero(alignment));
return ((uintptr_t)ptr & (alignment - 1)) == 0;
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
index 36dedba34f..b52acca1b3 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
@@ -496,7 +496,7 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
if (format_matches_type(format_desc, type) &&
format_desc->block.bits <= type.width * 4 &&
/* XXX this shouldn't be needed */
- util_is_power_of_two(format_desc->block.bits)) {
+ util_is_power_of_two_or_zero(format_desc->block.bits)) {
LLVMValueRef packed;
LLVMTypeRef dst_vec_type = lp_build_vec_type(gallivm, type);
struct lp_type fetch_type;
@@ -609,7 +609,7 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
format_desc->block.width == 1 &&
format_desc->block.height == 1 &&
/* XXX this shouldn't be needed */
- util_is_power_of_two(format_desc->block.bits) &&
+ util_is_power_of_two_or_zero(format_desc->block.bits) &&
format_desc->block.bits <= 32 &&
format_desc->is_bitmask &&
!format_desc->is_mixed &&
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.c b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
index 7d11dcd3b6..8cabe9ef01 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_gather.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
@@ -118,7 +118,7 @@ lp_build_gather_elem(struct gallivm_state *gallivm,
*/
if (!aligned) {
LLVMSetAlignment(res, 1);
- } else if (!util_is_power_of_two(src_width)) {
+ } else if (!util_is_power_of_two_or_zero(src_width)) {
/*
* Full alignment is impossible, assume the caller really meant
* the individual elements were aligned (e.g. 3x32bit format).
@@ -130,7 +130,7 @@ lp_build_gather_elem(struct gallivm_state *gallivm,
* this should cover all the 3-channel formats.
*/
if (((src_width / 24) * 24 == src_width) &&
- util_is_power_of_two(src_width / 24)) {
+ util_is_power_of_two_or_zero(src_width / 24)) {
LLVMSetAlignment(res, src_width / 24);
} else {
LLVMSetAlignment(res, 1);
@@ -199,7 +199,7 @@ lp_build_gather_elem_vec(struct gallivm_state *gallivm,
*/
if (!aligned) {
LLVMSetAlignment(res, 1);
- } else if (!util_is_power_of_two(src_width)) {
+ } else if (!util_is_power_of_two_or_zero(src_width)) {
/*
* Full alignment is impossible, assume the caller really meant
* the individual elements were aligned (e.g. 3x32bit format).
@@ -211,7 +211,7 @@ lp_build_gather_elem_vec(struct gallivm_state *gallivm,
* this should cover all the 3-channel formats.
*/
if (((src_width / 24) * 24 == src_width) &&
- util_is_power_of_two(src_width / 24)) {
+ util_is_power_of_two_or_zero(src_width / 24)) {
LLVMSetAlignment(res, src_width / 24);
} else {
LLVMSetAlignment(res, 1);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
index 7879826422..b8b53a7d6e 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_pack.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
@@ -219,7 +219,7 @@ lp_build_concat(struct gallivm_state *gallivm,
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
assert(src_type.length * num_vectors <= ARRAY_SIZE(shuffles));
- assert(util_is_power_of_two(num_vectors));
+ assert(util_is_power_of_two_or_zero(num_vectors));
new_length = src_type.length;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
index ab9d051c91..81cb506071 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
@@ -114,9 +114,9 @@ lp_sampler_static_texture_state(struct lp_static_texture_state *state,
state->swizzle_a = view->swizzle_a;
state->target = view->target;
- state->pot_width = util_is_power_of_two(texture->width0);
- state->pot_height = util_is_power_of_two(texture->height0);
- state->pot_depth = util_is_power_of_two(texture->depth0);
+ state->pot_width = util_is_power_of_two_or_zero(texture->width0);
+ state->pot_height = util_is_power_of_two_or_zero(texture->height0);
+ state->pot_depth = util_is_power_of_two_or_zero(texture->depth0);
state->level_zero_only = !view->u.tex.last_level;
/*
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index a441b5457b..46d02978fd 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -179,14 +179,6 @@ util_fast_pow(float x, float y)
return util_fast_exp2(util_fast_log2(x) * y);
}
-/* Note that this counts zero as a power of two.
- */
-static inline boolean
-util_is_power_of_two( unsigned v )
-{
- return (v & (v-1)) == 0;
-}
-
/**
* Floor(x), returned as int.
@@ -459,7 +451,7 @@ util_next_power_of_two(unsigned x)
if (x <= 1)
return 1;
- if (util_is_power_of_two(x))
+ if (util_is_power_of_two_or_zero(x))
return x;
val--;
diff --git a/src/gallium/auxiliary/util/u_ringbuffer.c b/src/gallium/auxiliary/util/u_ringbuffer.c
index 4d6166833e..f6bb910671 100644
--- a/src/gallium/auxiliary/util/u_ringbuffer.c
+++ b/src/gallium/auxiliary/util/u_ringbuffer.c
@@ -27,7 +27,7 @@ struct util_ringbuffer *util_ringbuffer_create( unsigned dwords )
if (!ring)
return NULL;
- assert(util_is_power_of_two(dwords));
+ assert(util_is_power_of_two_or_zero(dwords));
ring->buf = MALLOC( dwords * sizeof(unsigned) );
if (ring->buf == NULL)