summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorDylan Baker <[email protected]>2018-08-21 09:46:46 -0700
committerDylan Baker <[email protected]>2018-09-07 10:21:26 -0700
commit8396043f304bb2a752130230055605c5c966e89f (patch)
treeee2e8a5494b88bff3b5e67ece8ffdba70d12c087 /src/mesa
parent80825abb5d1a7491035880253ffd531c55acae6b (diff)
Replace uses of _mesa_bitcount with util_bitcount
and _mesa_bitcount_64 with util_bitcount_64. This fixes a build problem in nir for platforms that don't have popcount or popcountll, such as 32bit msvc. v2: - Fix additional uses of _mesa_bitcount added after this was originally written Acked-by: Eric Engestrom <[email protected]> (v1) Acked-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/common/meta.c5
-rw-r--r--src/mesa/drivers/dri/i965/brw_curbe.c3
-rw-r--r--src/mesa/drivers/dri/i965/brw_performance_query.c5
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm.c7
-rw-r--r--src/mesa/drivers/x11/Makefile.am1
-rw-r--r--src/mesa/drivers/x11/fakeglx.c7
-rw-r--r--src/mesa/drivers/x11/meson.build2
-rw-r--r--src/mesa/drivers/x11/xm_api.c17
-rw-r--r--src/mesa/main/arrayobj.c5
-rw-r--r--src/mesa/main/buffers.c7
-rw-r--r--src/mesa/main/imports.c38
-rw-r--r--src/mesa/main/imports.h15
-rw-r--r--src/mesa/program/program_parse.y4
-rw-r--r--src/mesa/state_tracker/st_glsl_to_nir.cpp5
14 files changed, 39 insertions, 82 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 04752e0e875..056a181c17b 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -88,6 +88,7 @@
#include "util/bitscan.h"
#include "util/ralloc.h"
#include "compiler/nir/nir.h"
+#include "util/u_math.h"
/** Return offset in bytes of the field within a vertex struct */
#define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
@@ -1611,7 +1612,7 @@ _mesa_meta_drawbuffers_from_bitfield(GLbitfield bits)
assert((bits & ~BUFFER_BITS_COLOR) == 0);
/* Make sure we don't overflow any arrays. */
- assert(_mesa_bitcount(bits) <= MAX_DRAW_BUFFERS);
+ assert(util_bitcount(bits) <= MAX_DRAW_BUFFERS);
enums[0] = GL_NONE;
@@ -1651,7 +1652,7 @@ _mesa_meta_drawbuffers_and_colormask(struct gl_context *ctx, GLbitfield mask)
assert((mask & ~BUFFER_BITS_COLOR) == 0);
/* Make sure we don't overflow any arrays. */
- assert(_mesa_bitcount(mask) <= MAX_DRAW_BUFFERS);
+ assert(util_bitcount(mask) <= MAX_DRAW_BUFFERS);
enums[0] = GL_NONE;
diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c
index e4a2bd9c891..eb824739c67 100644
--- a/src/mesa/drivers/dri/i965/brw_curbe.c
+++ b/src/mesa/drivers/dri/i965/brw_curbe.c
@@ -64,6 +64,7 @@
#include "brw_defines.h"
#include "brw_state.h"
#include "brw_util.h"
+#include "util/u_math.h"
/**
@@ -86,7 +87,7 @@ static void calculate_curbe_offsets( struct brw_context *brw )
/* _NEW_TRANSFORM */
if (ctx->Transform.ClipPlanesEnabled) {
- GLuint nr_planes = 6 + _mesa_bitcount(ctx->Transform.ClipPlanesEnabled);
+ GLuint nr_planes = 6 + util_bitcount(ctx->Transform.ClipPlanesEnabled);
nr_clip_regs = (nr_planes * 4 + 15) / 16;
}
diff --git a/src/mesa/drivers/dri/i965/brw_performance_query.c b/src/mesa/drivers/dri/i965/brw_performance_query.c
index d45529fc0c7..ff9272999d1 100644
--- a/src/mesa/drivers/dri/i965/brw_performance_query.c
+++ b/src/mesa/drivers/dri/i965/brw_performance_query.c
@@ -67,6 +67,7 @@
#include "util/ralloc.h"
#include "util/hash_table.h"
#include "util/list.h"
+#include "util/u_math.h"
#include "brw_context.h"
#include "brw_defines.h"
@@ -1985,11 +1986,11 @@ compute_topology_builtins(struct brw_context *brw)
for (int i = 0; i < sizeof(devinfo->subslice_masks[i]); i++) {
brw->perfquery.sys_vars.n_eu_sub_slices +=
- _mesa_bitcount(devinfo->subslice_masks[i]);
+ util_bitcount(devinfo->subslice_masks[i]);
}
for (int i = 0; i < sizeof(devinfo->eu_masks); i++)
- brw->perfquery.sys_vars.n_eus += _mesa_bitcount(devinfo->eu_masks[i]);
+ brw->perfquery.sys_vars.n_eus += util_bitcount(devinfo->eu_masks[i]);
brw->perfquery.sys_vars.eu_threads_count =
brw->perfquery.sys_vars.n_eus * devinfo->num_thread_per_eu;
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index db632ed15e1..139ca910f9f 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -40,6 +40,7 @@
#include "brw_program.h"
#include "util/ralloc.h"
+#include "util/u_math.h"
static void
assign_fs_binding_table_offsets(const struct gen_device_info *devinfo,
@@ -559,7 +560,7 @@ brw_wm_populate_key(struct brw_context *brw, struct brw_wm_prog_key *key)
}
/* BRW_NEW_VUE_MAP_GEOM_OUT */
- if (devinfo->gen < 6 || _mesa_bitcount_64(prog->info.inputs_read &
+ if (devinfo->gen < 6 || util_bitcount64(prog->info.inputs_read &
BRW_FS_VARYING_INPUT_MASK) > 16) {
key->input_slots_valid = brw->vue_map_geom_out.slots_valid;
}
@@ -632,14 +633,14 @@ brw_wm_populate_default_key(const struct gen_device_info *devinfo,
key->iz_lookup |= BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT;
}
- if (devinfo->gen < 6 || _mesa_bitcount_64(prog->info.inputs_read &
+ if (devinfo->gen < 6 || util_bitcount64(prog->info.inputs_read &
BRW_FS_VARYING_INPUT_MASK) > 16) {
key->input_slots_valid = prog->info.inputs_read | VARYING_BIT_POS;
}
brw_setup_tex_for_precompile(devinfo, &key->tex, prog);
- key->nr_color_regions = _mesa_bitcount_64(outputs_written &
+ key->nr_color_regions = util_bitcount64(outputs_written &
~(BITFIELD64_BIT(FRAG_RESULT_DEPTH) |
BITFIELD64_BIT(FRAG_RESULT_STENCIL) |
BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));
diff --git a/src/mesa/drivers/x11/Makefile.am b/src/mesa/drivers/x11/Makefile.am
index c256ce0d34f..3024c549e61 100644
--- a/src/mesa/drivers/x11/Makefile.am
+++ b/src/mesa/drivers/x11/Makefile.am
@@ -68,6 +68,7 @@ GL_PATCH = 0
lib@GL_LIB@_la_LIBADD = \
$(top_builddir)/src/mesa/libmesa.la \
$(top_builddir)/src/mapi/glapi/libglapi.la \
+ $(top_builddir)/src/util/libmesautil.la \
$(SHARED_GLAPI_LIB) \
$(GL_LIB_DEPS)
diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c
index b946521b951..e6d488c4dc3 100644
--- a/src/mesa/drivers/x11/fakeglx.c
+++ b/src/mesa/drivers/x11/fakeglx.c
@@ -52,6 +52,7 @@
#include "main/version.h"
#include "xfonts.h"
#include "xmesaP.h"
+#include "util/u_math.h"
/* This indicates the client-side GLX API and GLX encoder version. */
#define CLIENT_MAJOR_VERSION 1
@@ -510,9 +511,9 @@ get_visual( Display *dpy, int scr, unsigned int depth, int xclass )
* 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
*/
if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
- if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
- _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
- _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
+ if (util_bitcount((GLuint) vis->red_mask ) <= 8 &&
+ util_bitcount((GLuint) vis->green_mask) <= 8 &&
+ util_bitcount((GLuint) vis->blue_mask ) <= 8) {
return vis;
}
else {
diff --git a/src/mesa/drivers/x11/meson.build b/src/mesa/drivers/x11/meson.build
index bb4fda14cb8..cb092d25d6c 100644
--- a/src/mesa/drivers/x11/meson.build
+++ b/src/mesa/drivers/x11/meson.build
@@ -32,7 +32,7 @@ libgl = shared_library(
include_directories : [
inc_include, inc_src, inc_mesa, inc_mapi, inc_gallium, inc_gallium_aux
],
- link_with : [libmesa_classic, libglapi_static, gl_link_with],
+ link_with : [libmesa_classic, libglapi_static, libmesa_util, gl_link_with],
dependencies : [dep_x11, dep_xext, dep_xcb, dep_thread],
version : '1.6.0',
install : true,
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index 3d54193580e..cb8b58b8d96 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -84,6 +84,7 @@
#include "tnl/t_pipeline.h"
#include "drivers/common/driverfuncs.h"
#include "drivers/common/meta.h"
+#include "util/u_math.h"
/**
* Global X driver lock
@@ -463,9 +464,9 @@ setup_truecolor(XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap)
3*16, 11*16, 1*16, 9*16,
15*16, 7*16, 13*16, 5*16,
};
- GLint rBits = _mesa_bitcount(rmask);
- GLint gBits = _mesa_bitcount(gmask);
- GLint bBits = _mesa_bitcount(bmask);
+ GLint rBits = util_bitcount(rmask);
+ GLint gBits = util_bitcount(gmask);
+ GLint bBits = util_bitcount(bmask);
GLint maxBits;
GLuint i;
@@ -828,9 +829,9 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display,
{
const int xclass = v->visualType;
if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {
- red_bits = _mesa_bitcount(GET_REDMASK(v));
- green_bits = _mesa_bitcount(GET_GREENMASK(v));
- blue_bits = _mesa_bitcount(GET_BLUEMASK(v));
+ red_bits = util_bitcount(GET_REDMASK(v));
+ green_bits = util_bitcount(GET_GREENMASK(v));
+ blue_bits = util_bitcount(GET_BLUEMASK(v));
}
else {
/* this is an approximation */
@@ -1095,8 +1096,8 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p,
if (ctx->Extensions.ARB_texture_non_power_of_two) {
target = GLX_TEXTURE_2D_EXT;
}
- else if ( _mesa_bitcount(width) == 1
- && _mesa_bitcount(height) == 1) {
+ else if ( util_bitcount(width) == 1
+ && util_bitcount(height) == 1) {
/* power of two size */
if (height == 1) {
target = GLX_TEXTURE_1D_EXT;
diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 6e0665c0e5d..ad34282afc8 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -53,6 +53,7 @@
#include "varray.h"
#include "util/bitscan.h"
#include "util/u_atomic.h"
+#include "util/u_math.h"
const GLubyte
@@ -755,7 +756,7 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
* grouping information in a seperate array beside
* gl_array_attributes/gl_vertex_buffer_binding.
*/
- assert(_mesa_bitcount(binding->_BoundArrays & vao->_Enabled) == 1
+ assert(util_bitcount(binding->_BoundArrays & vao->_Enabled) == 1
|| (vao->_Enabled & ~binding->_BoundArrays) == 0);
/* Start this current effective binding with the array */
@@ -775,7 +776,7 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
&vao->BufferBinding[attrib2->BufferBindingIndex];
/* See the comment at the same assert above. */
- assert(_mesa_bitcount(binding2->_BoundArrays & vao->_Enabled) == 1
+ assert(util_bitcount(binding2->_BoundArrays & vao->_Enabled) == 1
|| (vao->_Enabled & ~binding->_BoundArrays) == 0);
/* Check if we have an identical binding */
diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index bb856882da2..d98c015bb24 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -37,6 +37,7 @@
#include "fbobject.h"
#include "mtypes.h"
#include "util/bitscan.h"
+#include "util/u_math.h"
#define BAD_MASK ~0u
@@ -468,7 +469,7 @@ draw_buffers(struct gl_context *ctx, struct gl_framebuffer *fb, GLsizei n,
* For OpenGL 4.x we check that behaviour. For any previous version we
* keep considering it wrong (as INVALID_ENUM).
*/
- if (_mesa_bitcount(destMask[output]) > 1) {
+ if (util_bitcount(destMask[output]) > 1) {
if (_mesa_is_winsys_fbo(fb) && ctx->Version >= 40 &&
buffers[output] == GL_BACK) {
if (n != 1) {
@@ -722,7 +723,7 @@ _mesa_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
* (ex: glDrawBuffer(GL_FRONT_AND_BACK)).
* Otherwise, destMask[x] can only have one bit set.
*/
- if (n > 0 && _mesa_bitcount(destMask[0]) > 1) {
+ if (n > 0 && util_bitcount(destMask[0]) > 1) {
GLuint count = 0, destMask0 = destMask[0];
while (destMask0) {
const gl_buffer_index bufIndex = u_bit_scan(&destMask0);
@@ -741,7 +742,7 @@ _mesa_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
if (destMask[buf]) {
gl_buffer_index bufIndex = ffs(destMask[buf]) - 1;
/* only one bit should be set in the destMask[buf] field */
- assert(_mesa_bitcount(destMask[buf]) == 1);
+ assert(util_bitcount(destMask[buf]) == 1);
if (fb->_ColorDrawBufferIndexes[buf] != bufIndex) {
updated_drawbuffers(ctx, fb);
fb->_ColorDrawBufferIndexes[buf] = bufIndex;
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index b4685b6dc35..566aac1d385 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -213,44 +213,6 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
/*@}*/
-/**********************************************************************/
-/** \name Math */
-/*@{*/
-
-
-#ifndef HAVE___BUILTIN_POPCOUNT
-/**
- * Return number of bits set in given GLuint.
- */
-unsigned int
-_mesa_bitcount(unsigned int n)
-{
- unsigned int bits;
- for (bits = 0; n > 0; n = n >> 1) {
- bits += (n & 1);
- }
- return bits;
-}
-#endif
-
-#ifndef HAVE___BUILTIN_POPCOUNTLL
-/**
- * Return number of bits set in given 64-bit uint.
- */
-unsigned int
-_mesa_bitcount_64(uint64_t n)
-{
- unsigned int bits;
- for (bits = 0; n > 0; n = n >> 1) {
- bits += (n & 1);
- }
- return bits;
-}
-#endif
-
-/*@}*/
-
-
/** Needed due to #ifdef's, above. */
int
_mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args)
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index a761f01851a..f461b1c052e 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -317,21 +317,6 @@ extern void *
_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
unsigned long alignment);
-#ifdef HAVE___BUILTIN_POPCOUNT
-#define _mesa_bitcount(i) __builtin_popcount(i)
-#else
-extern unsigned int
-_mesa_bitcount(unsigned int n);
-#endif
-
-#ifdef HAVE___BUILTIN_POPCOUNTLL
-#define _mesa_bitcount_64(i) __builtin_popcountll(i)
-#else
-extern unsigned int
-_mesa_bitcount_64(uint64_t n);
-#endif
-
-
extern int
_mesa_snprintf( char *str, size_t size, const char *fmt, ... ) PRINTFLIKE(3, 4);
diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y
index 415ff2a28ec..7398f5f507a 100644
--- a/src/mesa/program/program_parse.y
+++ b/src/mesa/program/program_parse.y
@@ -39,6 +39,8 @@
#include "program/symbol_table.h"
#include "program/program_parser.h"
+#include "util/u_math.h"
+
extern void *yy_scan_string(char *);
extern void yy_delete_buffer(void *);
@@ -2607,7 +2609,7 @@ _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *st
state->prog->arb.NumParameters = state->prog->Parameters->NumParameters;
state->prog->arb.NumAttributes =
- _mesa_bitcount_64(state->prog->info.inputs_read);
+ util_bitcount64(state->prog->info.inputs_read);
/*
* Initialize native counts to logical counts. The device driver may
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index d0ec410ec69..24776f7f9c4 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -32,7 +32,6 @@
#include "program/prog_parameter.h"
#include "program/ir_to_mesa.h"
#include "main/mtypes.h"
-#include "main/imports.h"
#include "main/errors.h"
#include "main/shaderapi.h"
#include "main/uniforms.h"
@@ -91,10 +90,10 @@ st_nir_assign_vs_in_locations(struct gl_program *prog, nir_shader *nir)
*/
if (var->data.location == VERT_ATTRIB_EDGEFLAG) {
/* bit of a hack, mirroring st_translate_vertex_program */
- var->data.driver_location = _mesa_bitcount_64(nir->info.inputs_read);
+ var->data.driver_location = util_bitcount64(nir->info.inputs_read);
} else if (nir->info.inputs_read & BITFIELD64_BIT(var->data.location)) {
var->data.driver_location =
- _mesa_bitcount_64(nir->info.inputs_read &
+ util_bitcount64(nir->info.inputs_read &
BITFIELD64_MASK(var->data.location));
nir->num_inputs++;
} else {