summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2017-11-13 13:00:53 -0800
committerIan Romanick <[email protected]>2018-03-29 14:09:28 -0700
commit22fbb5c5949b1590ef04b6432dd7f3a93a37c2ed (patch)
treec43dcd5e0d83802f39221369da90d1eed745b808 /src/compiler/nir
parentd76c204d0564701b4b8b6a2bdda50e2939683e66 (diff)
util: Add and use util_is_power_of_two_nonzero
Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Eduardo Lima Mitev <[email protected]>
Diffstat (limited to 'src/compiler/nir')
-rw-r--r--src/compiler/nir/nir_search_helpers.h13
-rw-r--r--src/compiler/nir/nir_validate.c2
2 files changed, 5 insertions, 10 deletions
diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h
index 2d399bd5dcd..8bc6d723c34 100644
--- a/src/compiler/nir/nir_search_helpers.h
+++ b/src/compiler/nir/nir_search_helpers.h
@@ -28,12 +28,7 @@
#define _NIR_SEARCH_HELPERS_
#include "nir.h"
-
-static inline bool
-__is_power_of_two(unsigned int x)
-{
- return ((x != 0) && !(x & (x - 1)));
-}
+#include "util/bitscan.h"
static inline bool
is_pos_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
@@ -50,11 +45,11 @@ is_pos_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
case nir_type_int:
if (val->i32[swizzle[i]] < 0)
return false;
- if (!__is_power_of_two(val->i32[swizzle[i]]))
+ if (!util_is_power_of_two_nonzero(val->i32[swizzle[i]]))
return false;
break;
case nir_type_uint:
- if (!__is_power_of_two(val->u32[swizzle[i]]))
+ if (!util_is_power_of_two_nonzero(val->u32[swizzle[i]]))
return false;
break;
default:
@@ -80,7 +75,7 @@ is_neg_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
case nir_type_int:
if (val->i32[swizzle[i]] > 0)
return false;
- if (!__is_power_of_two(abs(val->i32[swizzle[i]])))
+ if (!util_is_power_of_two_nonzero(abs(val->i32[swizzle[i]])))
return false;
break;
default:
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 725ba43152c..565cb2ef163 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -982,7 +982,7 @@ validate_var_decl(nir_variable *var, bool is_global, validate_state *state)
validate_assert(state, is_global == nir_variable_is_global(var));
/* Must have exactly one mode set */
- validate_assert(state, util_bitcount(var->data.mode) == 1);
+ validate_assert(state, util_is_power_of_two_nonzero(var->data.mode));
if (var->data.compact) {
/* The "compact" flag is only valid on arrays of scalars. */