#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,
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:
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:
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. */
static void
emit_blt_inplace(struct etna_cmd_stream *stream, const struct blt_inplace_op *op)
{
- assert(op->bpp > 0 && util_is_power_of_two_or_zero(op->bpp));
+ assert(op->bpp > 0 && util_is_power_of_two_nonzero(op->bpp));
etna_cmd_stream_reserve(stream, 64*2); /* Never allow BLT sequences to be broken up */
etna_set_state(stream, VIVS_BLT_ENABLE, 0x00000001);
etna_set_state(stream, VIVS_BLT_CONFIG,
static void
cplx_align_assert_sane(struct cplx_align a)
{
- assert(a.mul > 0 && util_is_power_of_two_or_zero(a.mul));
+ assert(a.mul > 0 && util_is_power_of_two_nonzero(a.mul));
assert(a.offset < a.mul);
}
mark_uniform_slots_read(struct uniform_slot_info *slots,
unsigned num_slots, unsigned alignment)
{
- assert(alignment > 0 && util_is_power_of_two_or_zero(alignment));
+ assert(alignment > 0 && util_is_power_of_two_nonzero(alignment));
assert(alignment <= CPLX_ALIGN_MAX_MUL);
/* We can't align a slot to anything less than the slot size */
return (v & (v - 1)) == 0;
}
+/* Determine if an unsigned value is a power of two.
+ *
+ * \note
+ * Zero is \b not treated as a power of two.
+ */
+static inline bool
+util_is_power_of_two_nonzero(unsigned v)
+{
+ return v != 0 && (v & (v - 1)) == 0;
+}
+
/* For looping over a bitmask when you want to loop over consecutive bits
* manually, for example:
*