util: Move _mesa_fsl/util_last_bit into util/bitscan.h
As requested with the initial creation of util/bitscan.h now move other bitscan related functions into util. v2: Split into two patches. Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de> Tested-by: Brian Paul <brianp@vmware.com> Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:

committed by
Mathias Fröhlich

parent
e4cb3af524
commit
027cbf00f2
@@ -146,7 +146,7 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
|
|||||||
shader->info.name = ralloc_asprintf(shader, "GLSL%d", shader_prog->Name);
|
shader->info.name = ralloc_asprintf(shader, "GLSL%d", shader_prog->Name);
|
||||||
if (shader_prog->Label)
|
if (shader_prog->Label)
|
||||||
shader->info.label = ralloc_strdup(shader, shader_prog->Label);
|
shader->info.label = ralloc_strdup(shader, shader_prog->Label);
|
||||||
shader->info.num_textures = _mesa_fls(sh->Program->SamplersUsed);
|
shader->info.num_textures = util_last_bit(sh->Program->SamplersUsed);
|
||||||
shader->info.num_ubos = sh->NumUniformBlocks;
|
shader->info.num_ubos = sh->NumUniformBlocks;
|
||||||
shader->info.num_abos = shader_prog->NumAtomicBuffers;
|
shader->info.num_abos = shader_prog->NumAtomicBuffers;
|
||||||
shader->info.num_ssbos = sh->NumShaderStorageBlocks;
|
shader->info.num_ssbos = sh->NumShaderStorageBlocks;
|
||||||
|
@@ -346,70 +346,6 @@ util_half_inf_sign(int16_t x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find last bit set in a word. The least significant bit is 1.
|
|
||||||
* Return 0 if no bits are set.
|
|
||||||
*/
|
|
||||||
static inline unsigned
|
|
||||||
util_last_bit(unsigned u)
|
|
||||||
{
|
|
||||||
#if defined(HAVE___BUILTIN_CLZ)
|
|
||||||
return u == 0 ? 0 : 32 - __builtin_clz(u);
|
|
||||||
#else
|
|
||||||
unsigned r = 0;
|
|
||||||
while (u) {
|
|
||||||
r++;
|
|
||||||
u >>= 1;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find last bit set in a word. The least significant bit is 1.
|
|
||||||
* Return 0 if no bits are set.
|
|
||||||
*/
|
|
||||||
static inline unsigned
|
|
||||||
util_last_bit64(uint64_t u)
|
|
||||||
{
|
|
||||||
#if defined(HAVE___BUILTIN_CLZLL)
|
|
||||||
return u == 0 ? 0 : 64 - __builtin_clzll(u);
|
|
||||||
#else
|
|
||||||
unsigned r = 0;
|
|
||||||
while (u) {
|
|
||||||
r++;
|
|
||||||
u >>= 1;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find last bit in a word that does not match the sign bit. The least
|
|
||||||
* significant bit is 1.
|
|
||||||
* Return 0 if no bits are set.
|
|
||||||
*/
|
|
||||||
static inline unsigned
|
|
||||||
util_last_bit_signed(int i)
|
|
||||||
{
|
|
||||||
if (i >= 0)
|
|
||||||
return util_last_bit(i);
|
|
||||||
else
|
|
||||||
return util_last_bit(~(unsigned)i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns a bitfield in which the first count bits starting at start are
|
|
||||||
* set.
|
|
||||||
*/
|
|
||||||
static inline unsigned
|
|
||||||
u_bit_consecutive(unsigned start, unsigned count)
|
|
||||||
{
|
|
||||||
assert(start + count <= 32);
|
|
||||||
if (count == 32)
|
|
||||||
return ~0;
|
|
||||||
return ((1u << count) - 1) << start;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return float bits.
|
* Return float bits.
|
||||||
*/
|
*/
|
||||||
|
@@ -220,7 +220,7 @@ brw_upload_cs_prog(struct brw_context *brw)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
brw->cs.base.sampler_count =
|
brw->cs.base.sampler_count =
|
||||||
_mesa_fls(ctx->ComputeProgram._Current->Base.SamplersUsed);
|
util_last_bit(ctx->ComputeProgram._Current->Base.SamplersUsed);
|
||||||
|
|
||||||
brw_cs_populate_key(brw, &key);
|
brw_cs_populate_key(brw, &key);
|
||||||
|
|
||||||
|
@@ -452,15 +452,15 @@ brw_try_draw_prims(struct gl_context *ctx,
|
|||||||
* index.
|
* index.
|
||||||
*/
|
*/
|
||||||
brw->wm.base.sampler_count =
|
brw->wm.base.sampler_count =
|
||||||
_mesa_fls(ctx->FragmentProgram._Current->Base.SamplersUsed);
|
util_last_bit(ctx->FragmentProgram._Current->Base.SamplersUsed);
|
||||||
brw->gs.base.sampler_count = ctx->GeometryProgram._Current ?
|
brw->gs.base.sampler_count = ctx->GeometryProgram._Current ?
|
||||||
_mesa_fls(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;
|
util_last_bit(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;
|
||||||
brw->tes.base.sampler_count = ctx->TessEvalProgram._Current ?
|
brw->tes.base.sampler_count = ctx->TessEvalProgram._Current ?
|
||||||
_mesa_fls(ctx->TessEvalProgram._Current->Base.SamplersUsed) : 0;
|
util_last_bit(ctx->TessEvalProgram._Current->Base.SamplersUsed) : 0;
|
||||||
brw->tcs.base.sampler_count = ctx->TessCtrlProgram._Current ?
|
brw->tcs.base.sampler_count = ctx->TessCtrlProgram._Current ?
|
||||||
_mesa_fls(ctx->TessCtrlProgram._Current->Base.SamplersUsed) : 0;
|
util_last_bit(ctx->TessCtrlProgram._Current->Base.SamplersUsed) : 0;
|
||||||
brw->vs.base.sampler_count =
|
brw->vs.base.sampler_count =
|
||||||
_mesa_fls(ctx->VertexProgram._Current->Base.SamplersUsed);
|
util_last_bit(ctx->VertexProgram._Current->Base.SamplersUsed);
|
||||||
|
|
||||||
intel_prepare_render(brw);
|
intel_prepare_render(brw);
|
||||||
brw_predraw_set_aux_buffers(brw);
|
brw_predraw_set_aux_buffers(brw);
|
||||||
|
@@ -1845,7 +1845,7 @@ fs_visitor::emit_gs_control_data_bits(const fs_reg &vertex_count)
|
|||||||
fs_reg prev_count = bld.vgrf(BRW_REGISTER_TYPE_UD, 1);
|
fs_reg prev_count = bld.vgrf(BRW_REGISTER_TYPE_UD, 1);
|
||||||
abld.ADD(prev_count, vertex_count, brw_imm_ud(0xffffffffu));
|
abld.ADD(prev_count, vertex_count, brw_imm_ud(0xffffffffu));
|
||||||
unsigned log2_bits_per_vertex =
|
unsigned log2_bits_per_vertex =
|
||||||
_mesa_fls(gs_compile->control_data_bits_per_vertex);
|
util_last_bit(gs_compile->control_data_bits_per_vertex);
|
||||||
abld.SHR(dword_index, prev_count, brw_imm_ud(6u - log2_bits_per_vertex));
|
abld.SHR(dword_index, prev_count, brw_imm_ud(6u - log2_bits_per_vertex));
|
||||||
|
|
||||||
if (per_slot_offset.file != BAD_FILE) {
|
if (per_slot_offset.file != BAD_FILE) {
|
||||||
@@ -2789,7 +2789,7 @@ fs_visitor::nir_emit_tcs_intrinsic(const fs_builder &bld,
|
|||||||
if (mask == 0)
|
if (mask == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
unsigned num_components = _mesa_fls(mask);
|
unsigned num_components = util_last_bit(mask);
|
||||||
enum opcode opcode;
|
enum opcode opcode;
|
||||||
|
|
||||||
/* We can only pack two 64-bit components in a single message, so send
|
/* We can only pack two 64-bit components in a single message, so send
|
||||||
@@ -4523,7 +4523,7 @@ fs_visitor::nir_emit_texture(const fs_builder &bld, nir_tex_instr *instr)
|
|||||||
nir_ssa_def_components_read(&instr->dest.ssa):
|
nir_ssa_def_components_read(&instr->dest.ssa):
|
||||||
(1 << dest_size) - 1;
|
(1 << dest_size) - 1;
|
||||||
assert(write_mask != 0); /* dead code should have been eliminated */
|
assert(write_mask != 0); /* dead code should have been eliminated */
|
||||||
inst->regs_written = _mesa_fls(write_mask) * dispatch_width / 8;
|
inst->regs_written = util_last_bit(write_mask) * dispatch_width / 8;
|
||||||
} else {
|
} else {
|
||||||
inst->regs_written = 4 * dispatch_width / 8;
|
inst->regs_written = 4 * dispatch_width / 8;
|
||||||
}
|
}
|
||||||
|
@@ -674,7 +674,7 @@ brw_setup_tex_for_precompile(struct brw_context *brw,
|
|||||||
struct gl_program *prog)
|
struct gl_program *prog)
|
||||||
{
|
{
|
||||||
const bool has_shader_channel_select = brw->is_haswell || brw->gen >= 8;
|
const bool has_shader_channel_select = brw->is_haswell || brw->gen >= 8;
|
||||||
unsigned sampler_count = _mesa_fls(prog->SamplersUsed);
|
unsigned sampler_count = util_last_bit(prog->SamplersUsed);
|
||||||
for (unsigned i = 0; i < sampler_count; i++) {
|
for (unsigned i = 0; i < sampler_count; i++) {
|
||||||
if (!has_shader_channel_select && (prog->ShadowSamplers & (1 << i))) {
|
if (!has_shader_channel_select && (prog->ShadowSamplers & (1 << i))) {
|
||||||
/* Assume DEPTH_TEXTURE_MODE is the default: X, X, X, 1 */
|
/* Assume DEPTH_TEXTURE_MODE is the default: X, X, X, 1 */
|
||||||
|
@@ -1157,7 +1157,7 @@ brw_assign_common_binding_table_offsets(gl_shader_stage stage,
|
|||||||
uint32_t next_binding_table_offset)
|
uint32_t next_binding_table_offset)
|
||||||
{
|
{
|
||||||
const struct gl_linked_shader *shader = NULL;
|
const struct gl_linked_shader *shader = NULL;
|
||||||
int num_textures = _mesa_fls(prog->SamplersUsed);
|
int num_textures = util_last_bit(prog->SamplersUsed);
|
||||||
|
|
||||||
if (shader_prog)
|
if (shader_prog)
|
||||||
shader = shader_prog->_LinkedShaders[stage];
|
shader = shader_prog->_LinkedShaders[stage];
|
||||||
|
@@ -334,7 +334,7 @@ vec4_gs_visitor::emit_control_data_bits()
|
|||||||
emit(ADD(dst_reg(prev_count), this->vertex_count,
|
emit(ADD(dst_reg(prev_count), this->vertex_count,
|
||||||
brw_imm_ud(0xffffffffu)));
|
brw_imm_ud(0xffffffffu)));
|
||||||
unsigned log2_bits_per_vertex =
|
unsigned log2_bits_per_vertex =
|
||||||
_mesa_fls(c->control_data_bits_per_vertex);
|
util_last_bit(c->control_data_bits_per_vertex);
|
||||||
emit(SHR(dst_reg(dword_index), prev_count,
|
emit(SHR(dst_reg(dword_index), prev_count,
|
||||||
brw_imm_ud(6 - log2_bits_per_vertex)));
|
brw_imm_ud(6 - log2_bits_per_vertex)));
|
||||||
}
|
}
|
||||||
|
@@ -998,7 +998,7 @@ update_stage_texture_surfaces(struct brw_context *brw,
|
|||||||
else
|
else
|
||||||
surf_offset += stage_state->prog_data->binding_table.plane_start[plane];
|
surf_offset += stage_state->prog_data->binding_table.plane_start[plane];
|
||||||
|
|
||||||
unsigned num_samplers = _mesa_fls(prog->SamplersUsed);
|
unsigned num_samplers = util_last_bit(prog->SamplersUsed);
|
||||||
for (unsigned s = 0; s < num_samplers; s++) {
|
for (unsigned s = 0; s < num_samplers; s++) {
|
||||||
surf_offset[s] = 0;
|
surf_offset[s] = 0;
|
||||||
|
|
||||||
|
@@ -339,51 +339,6 @@ extern unsigned int
|
|||||||
_mesa_bitcount_64(uint64_t n);
|
_mesa_bitcount_64(uint64_t n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the last (most significant) bit set in a word.
|
|
||||||
*
|
|
||||||
* Essentially ffs() in the reverse direction.
|
|
||||||
*/
|
|
||||||
static inline unsigned int
|
|
||||||
_mesa_fls(unsigned int n)
|
|
||||||
{
|
|
||||||
#ifdef HAVE___BUILTIN_CLZ
|
|
||||||
return n == 0 ? 0 : 32 - __builtin_clz(n);
|
|
||||||
#else
|
|
||||||
unsigned int v = 1;
|
|
||||||
|
|
||||||
if (n == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
while (n >>= 1)
|
|
||||||
v++;
|
|
||||||
|
|
||||||
return v;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the last (most significant) bit set in a uint64_t value.
|
|
||||||
*
|
|
||||||
* Essentially ffsll() in the reverse direction.
|
|
||||||
*/
|
|
||||||
static inline unsigned int
|
|
||||||
_mesa_flsll(uint64_t n)
|
|
||||||
{
|
|
||||||
#ifdef HAVE___BUILTIN_CLZLL
|
|
||||||
return n == 0 ? 0 : 64 - __builtin_clzll(n);
|
|
||||||
#else
|
|
||||||
unsigned int v = 1;
|
|
||||||
|
|
||||||
if (n == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
while (n >>= 1)
|
|
||||||
v++;
|
|
||||||
|
|
||||||
return v;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
_mesa_half_is_negative(GLhalfARB h)
|
_mesa_half_is_negative(GLhalfARB h)
|
||||||
|
@@ -887,7 +887,7 @@ setup_registers_and_variables(struct ptn_compile *c)
|
|||||||
struct nir_shader *shader = b->shader;
|
struct nir_shader *shader = b->shader;
|
||||||
|
|
||||||
/* Create input variables. */
|
/* Create input variables. */
|
||||||
const int num_inputs = _mesa_flsll(c->prog->InputsRead);
|
const int num_inputs = util_last_bit64(c->prog->InputsRead);
|
||||||
for (int i = 0; i < num_inputs; i++) {
|
for (int i = 0; i < num_inputs; i++) {
|
||||||
if (!(c->prog->InputsRead & BITFIELD64_BIT(i)))
|
if (!(c->prog->InputsRead & BITFIELD64_BIT(i)))
|
||||||
continue;
|
continue;
|
||||||
@@ -948,7 +948,7 @@ setup_registers_and_variables(struct ptn_compile *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create output registers and variables. */
|
/* Create output registers and variables. */
|
||||||
int max_outputs = _mesa_fls(c->prog->OutputsWritten);
|
int max_outputs = util_last_bit(c->prog->OutputsWritten);
|
||||||
c->output_regs = rzalloc_array(c, nir_register *, max_outputs);
|
c->output_regs = rzalloc_array(c, nir_register *, max_outputs);
|
||||||
|
|
||||||
for (int i = 0; i < max_outputs; i++) {
|
for (int i = 0; i < max_outputs; i++) {
|
||||||
@@ -1043,7 +1043,7 @@ prog_to_nir(const struct gl_program *prog,
|
|||||||
ptn_add_output_stores(c);
|
ptn_add_output_stores(c);
|
||||||
|
|
||||||
s->info.name = ralloc_asprintf(s, "ARB%d", prog->Id);
|
s->info.name = ralloc_asprintf(s, "ARB%d", prog->Id);
|
||||||
s->info.num_textures = _mesa_fls(prog->SamplersUsed);
|
s->info.num_textures = util_last_bit(prog->SamplersUsed);
|
||||||
s->info.num_ubos = 0;
|
s->info.num_ubos = 0;
|
||||||
s->info.num_abos = 0;
|
s->info.num_abos = 0;
|
||||||
s->info.num_ssbos = 0;
|
s->info.num_ssbos = 0;
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#ifndef BITSCAN_H
|
#ifndef BITSCAN_H
|
||||||
#define BITSCAN_H
|
#define BITSCAN_H
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
@@ -146,6 +147,73 @@ u_bit_scan_consecutive_range64(uint64_t *mask, int *start, int *count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find last bit set in a word. The least significant bit is 1.
|
||||||
|
* Return 0 if no bits are set.
|
||||||
|
* Essentially ffs() in the reverse direction.
|
||||||
|
*/
|
||||||
|
static inline unsigned
|
||||||
|
util_last_bit(unsigned u)
|
||||||
|
{
|
||||||
|
#if defined(HAVE___BUILTIN_CLZ)
|
||||||
|
return u == 0 ? 0 : 32 - __builtin_clz(u);
|
||||||
|
#else
|
||||||
|
unsigned r = 0;
|
||||||
|
while (u) {
|
||||||
|
r++;
|
||||||
|
u >>= 1;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find last bit set in a word. The least significant bit is 1.
|
||||||
|
* Return 0 if no bits are set.
|
||||||
|
* Essentially ffsll() in the reverse direction.
|
||||||
|
*/
|
||||||
|
static inline unsigned
|
||||||
|
util_last_bit64(uint64_t u)
|
||||||
|
{
|
||||||
|
#if defined(HAVE___BUILTIN_CLZLL)
|
||||||
|
return u == 0 ? 0 : 64 - __builtin_clzll(u);
|
||||||
|
#else
|
||||||
|
unsigned r = 0;
|
||||||
|
while (u) {
|
||||||
|
r++;
|
||||||
|
u >>= 1;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find last bit in a word that does not match the sign bit. The least
|
||||||
|
* significant bit is 1.
|
||||||
|
* Return 0 if no bits are set.
|
||||||
|
*/
|
||||||
|
static inline unsigned
|
||||||
|
util_last_bit_signed(int i)
|
||||||
|
{
|
||||||
|
if (i >= 0)
|
||||||
|
return util_last_bit(i);
|
||||||
|
else
|
||||||
|
return util_last_bit(~(unsigned)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns a bitfield in which the first count bits starting at start are
|
||||||
|
* set.
|
||||||
|
*/
|
||||||
|
static inline unsigned
|
||||||
|
u_bit_consecutive(unsigned start, unsigned count)
|
||||||
|
{
|
||||||
|
assert(start + count <= 32);
|
||||||
|
if (count == 32)
|
||||||
|
return ~0;
|
||||||
|
return ((1u << count) - 1) << start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user