mesa: remove _mesa_ffs(), implement ffs() for non-GNU platforms
Call ffs() and ffsll() everywhere. Define our own ffs(), ffsll() functions when the platform doesn't have them. v2: remove #ifdef _WIN32, __IBMC__, __IBMCPP_ tests inside ffs() implementation. The #else clause was recursive. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Tested-by: Alexander von Gluck <kallisti5@unixzen.com>
This commit is contained in:
@@ -766,7 +766,7 @@ void emit_dp2(struct brw_compile *p,
|
||||
const struct brw_reg *arg0,
|
||||
const struct brw_reg *arg1)
|
||||
{
|
||||
int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
|
||||
if (!(mask & WRITEMASK_XYZW))
|
||||
return; /* Do not emit dead code */
|
||||
@@ -787,7 +787,7 @@ void emit_dp3(struct brw_compile *p,
|
||||
const struct brw_reg *arg0,
|
||||
const struct brw_reg *arg1)
|
||||
{
|
||||
int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
|
||||
if (!(mask & WRITEMASK_XYZW))
|
||||
return; /* Do not emit dead code */
|
||||
@@ -809,7 +809,7 @@ void emit_dp4(struct brw_compile *p,
|
||||
const struct brw_reg *arg0,
|
||||
const struct brw_reg *arg1)
|
||||
{
|
||||
int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
|
||||
if (!(mask & WRITEMASK_XYZW))
|
||||
return; /* Do not emit dead code */
|
||||
@@ -832,7 +832,7 @@ void emit_dph(struct brw_compile *p,
|
||||
const struct brw_reg *arg0,
|
||||
const struct brw_reg *arg1)
|
||||
{
|
||||
const int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
const int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
|
||||
if (!(mask & WRITEMASK_XYZW))
|
||||
return; /* Do not emit dead code */
|
||||
@@ -882,7 +882,7 @@ void emit_math1(struct brw_wm_compile *c,
|
||||
{
|
||||
struct brw_compile *p = &c->func;
|
||||
struct intel_context *intel = &p->brw->intel;
|
||||
int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
GLuint saturate = ((mask & SATURATE) ?
|
||||
BRW_MATH_SATURATE_SATURATE :
|
||||
BRW_MATH_SATURATE_NONE);
|
||||
@@ -945,7 +945,7 @@ void emit_math2(struct brw_wm_compile *c,
|
||||
{
|
||||
struct brw_compile *p = &c->func;
|
||||
struct intel_context *intel = &p->brw->intel;
|
||||
int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1;
|
||||
|
||||
if (!(mask & WRITEMASK_XYZW))
|
||||
return; /* Do not emit dead code */
|
||||
|
@@ -159,7 +159,7 @@ static struct prog_dst_register dst_undef( void )
|
||||
|
||||
static struct prog_dst_register get_temp( struct brw_wm_compile *c )
|
||||
{
|
||||
int bit = _mesa_ffs( ~c->fp_temp );
|
||||
int bit = ffs( ~c->fp_temp );
|
||||
|
||||
if (!bit) {
|
||||
printf("%s: out of temporaries\n", __FILE__);
|
||||
@@ -260,7 +260,7 @@ static struct prog_instruction *emit_scalar_insn(struct brw_wm_compile *c,
|
||||
if (inst0->DstReg.WriteMask == 0)
|
||||
return NULL;
|
||||
|
||||
dst_chan = _mesa_ffs(inst0->DstReg.WriteMask) - 1;
|
||||
dst_chan = ffs(inst0->DstReg.WriteMask) - 1;
|
||||
inst = get_fp_inst(c);
|
||||
*inst = *inst0;
|
||||
inst->DstReg.WriteMask = 1 << dst_chan;
|
||||
|
@@ -261,7 +261,7 @@ intelClearWithBlit(struct gl_context *ctx, GLbitfield mask)
|
||||
/* Loop over all renderbuffers */
|
||||
mask &= (1 << BUFFER_COUNT) - 1;
|
||||
while (mask) {
|
||||
GLuint buf = _mesa_ffs(mask) - 1;
|
||||
GLuint buf = ffs(mask) - 1;
|
||||
bool is_depth_stencil = buf == BUFFER_DEPTH || buf == BUFFER_STENCIL;
|
||||
struct intel_renderbuffer *irb;
|
||||
int x1, y1, x2, y2;
|
||||
|
@@ -171,7 +171,7 @@ intelClear(struct gl_context *ctx, GLbitfield mask)
|
||||
* buffer with it.
|
||||
*/
|
||||
if (mask & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) {
|
||||
int color_bit = _mesa_ffs(mask & BUFFER_BITS_COLOR);
|
||||
int color_bit = ffs(mask & BUFFER_BITS_COLOR);
|
||||
if (color_bit != 0) {
|
||||
tri_mask |= blit_mask & (1 << (color_bit - 1));
|
||||
blit_mask &= ~(1 << (color_bit - 1));
|
||||
|
@@ -303,7 +303,7 @@ _mesa_update_array_object_max_element(struct gl_context *ctx,
|
||||
GLuint min = ~0u;
|
||||
|
||||
while (enabled) {
|
||||
GLint attrib = _mesa_ffsll(enabled) - 1;
|
||||
GLint attrib = ffsll(enabled) - 1;
|
||||
enabled &= ~BITFIELD64_BIT(attrib);
|
||||
min = update_min(min, &arrayObj->VertexAttrib[attrib]);
|
||||
}
|
||||
|
@@ -88,7 +88,7 @@ __bitset_ffs(const BITSET_WORD *x, int n)
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (x[i])
|
||||
return _mesa_ffs(x[i]) + BITSET_WORDBITS * i;
|
||||
return ffs(x[i]) + BITSET_WORDBITS * i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -402,7 +402,7 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
|
||||
if (n == 1) {
|
||||
GLuint count = 0, destMask0 = destMask[0];
|
||||
while (destMask0) {
|
||||
GLint bufIndex = _mesa_ffs(destMask0) - 1;
|
||||
GLint bufIndex = ffs(destMask0) - 1;
|
||||
if (fb->_ColorDrawBufferIndexes[count] != bufIndex) {
|
||||
updated_drawbuffers(ctx);
|
||||
fb->_ColorDrawBufferIndexes[count] = bufIndex;
|
||||
@@ -417,7 +417,7 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
|
||||
GLuint count = 0;
|
||||
for (buf = 0; buf < n; buf++ ) {
|
||||
if (destMask[buf]) {
|
||||
GLint bufIndex = _mesa_ffs(destMask[buf]) - 1;
|
||||
GLint bufIndex = ffs(destMask[buf]) - 1;
|
||||
/* only one bit should be set in the destMask[buf] field */
|
||||
ASSERT(_mesa_bitcount(destMask[buf]) == 1);
|
||||
if (fb->_ColorDrawBufferIndexes[buf] != bufIndex) {
|
||||
|
@@ -295,7 +295,7 @@ need_saturate( GLuint mode )
|
||||
static GLuint translate_tex_src_bit( GLbitfield bit )
|
||||
{
|
||||
ASSERT(bit);
|
||||
return _mesa_ffs(bit) - 1;
|
||||
return ffs(bit) - 1;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -378,7 +378,7 @@ static struct ureg swizzle1( struct ureg reg, int x )
|
||||
|
||||
static struct ureg get_temp( struct tnl_program *p )
|
||||
{
|
||||
int bit = _mesa_ffs( ~p->temp_in_use );
|
||||
int bit = ffs( ~p->temp_in_use );
|
||||
if (!bit) {
|
||||
_mesa_problem(NULL, "%s: out of temporaries\n", __FILE__);
|
||||
exit(1);
|
||||
|
@@ -458,9 +458,8 @@ _mesa_inv_sqrtf(float n)
|
||||
* Find the first bit set in a word.
|
||||
*/
|
||||
int
|
||||
_mesa_ffs(int32_t i)
|
||||
ffs(int i)
|
||||
{
|
||||
#if (defined(_WIN32) ) || defined(__IBMC__) || defined(__IBMCPP__)
|
||||
register int bit = 0;
|
||||
if (i != 0) {
|
||||
if ((i & 0xffff) == 0) {
|
||||
@@ -482,9 +481,6 @@ _mesa_ffs(int32_t i)
|
||||
bit++;
|
||||
}
|
||||
return bit;
|
||||
#else
|
||||
return ffs(i);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -495,23 +491,24 @@ _mesa_ffs(int32_t i)
|
||||
* if no bits set.
|
||||
*/
|
||||
int
|
||||
_mesa_ffsll(int64_t val)
|
||||
ffsll(long long int val)
|
||||
{
|
||||
int bit;
|
||||
|
||||
assert(sizeof(val) == 8);
|
||||
|
||||
bit = _mesa_ffs((int32_t)val);
|
||||
bit = ffs((int) val);
|
||||
if (bit != 0)
|
||||
return bit;
|
||||
|
||||
bit = _mesa_ffs((int32_t)(val >> 32));
|
||||
bit = ffs((int) (val >> 32));
|
||||
if (bit != 0)
|
||||
return 32 + bit;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
#if !defined(__GNUC__) ||\
|
||||
((__GNUC__ * 100 + __GNUC_MINOR__) < 304) /* Not gcc 3.4 or later */
|
||||
|
@@ -573,10 +573,15 @@ _mesa_init_sqrt_table(void);
|
||||
#define ffsll __builtin_ffsll
|
||||
#endif
|
||||
|
||||
#define _mesa_ffs(i) ffs(i)
|
||||
#define _mesa_ffsll(i) ffsll(i)
|
||||
#else
|
||||
|
||||
#if ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) /* gcc 3.4 or later */
|
||||
extern int ffs(int i);
|
||||
extern int ffsll(long long int i);
|
||||
|
||||
#endif /*__ GNUC__ */
|
||||
|
||||
|
||||
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) /* gcc 3.4 or later */
|
||||
#define _mesa_bitcount(i) __builtin_popcount(i)
|
||||
#define _mesa_bitcount_64(i) __builtin_popcountll(i)
|
||||
#else
|
||||
@@ -586,16 +591,6 @@ extern unsigned int
|
||||
_mesa_bitcount_64(uint64_t n);
|
||||
#endif
|
||||
|
||||
#else
|
||||
extern int
|
||||
_mesa_ffs(int32_t i);
|
||||
|
||||
extern int
|
||||
_mesa_ffsll(int64_t i);
|
||||
|
||||
extern unsigned int
|
||||
_mesa_bitcount(unsigned int n);
|
||||
#endif
|
||||
|
||||
extern GLhalfARB
|
||||
_mesa_float_to_half(float f);
|
||||
|
@@ -928,6 +928,7 @@ _mesa_use_program(struct gl_context *ctx, struct gl_shader_program *shProg)
|
||||
ctx->Driver.UseProgram(ctx, shProg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do validation of the given shader program.
|
||||
* \param errMsg returns error message if validation fails.
|
||||
|
@@ -194,7 +194,7 @@ _mesa_print_vp_inputs(GLbitfield inputs)
|
||||
{
|
||||
printf("VP Inputs 0x%x: \n", inputs);
|
||||
while (inputs) {
|
||||
GLint attr = _mesa_ffs(inputs) - 1;
|
||||
GLint attr = ffs(inputs) - 1;
|
||||
const char *name = arb_input_attrib_string(attr,
|
||||
GL_VERTEX_PROGRAM_ARB);
|
||||
printf(" %d: %s\n", attr, name);
|
||||
@@ -212,7 +212,7 @@ _mesa_print_fp_inputs(GLbitfield inputs)
|
||||
{
|
||||
printf("FP Inputs 0x%x: \n", inputs);
|
||||
while (inputs) {
|
||||
GLint attr = _mesa_ffs(inputs) - 1;
|
||||
GLint attr = ffs(inputs) - 1;
|
||||
const char *name = arb_input_attrib_string(attr,
|
||||
GL_FRAGMENT_PROGRAM_ARB);
|
||||
printf(" %d: %s\n", attr, name);
|
||||
|
@@ -285,7 +285,7 @@ _swrast_map_textures(struct gl_context *ctx)
|
||||
|
||||
/* loop over enabled texture units */
|
||||
while (enabledUnits) {
|
||||
GLuint unit = _mesa_ffs(enabledUnits) - 1;
|
||||
GLuint unit = ffs(enabledUnits) - 1;
|
||||
struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
|
||||
|
||||
_swrast_map_texture(ctx, texObj);
|
||||
@@ -305,7 +305,7 @@ _swrast_unmap_textures(struct gl_context *ctx)
|
||||
|
||||
/* loop over enabled texture units */
|
||||
while (enabledUnits) {
|
||||
GLuint unit = _mesa_ffs(enabledUnits) - 1;
|
||||
GLuint unit = ffs(enabledUnits) - 1;
|
||||
struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
|
||||
|
||||
_swrast_unmap_texture(ctx, texObj);
|
||||
|
Reference in New Issue
Block a user