About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/util/bitset.h
AgeCommit message (Collapse)Author
2025-11-06util/bitset: Wrap __size in bracesNatalie Vock
Otherwise funny things can happen with the < operator because of precedence rules. Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37908>
2025-11-05util: add BITSET_RZALLOCAlyssa Rosenzweig
to complement BITSET_CALLOC for when you want a memctx in there. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Yonggang Luo <luoyonggang@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38245>
2025-11-05util: add BITSET_BYTES helperAlyssa Rosenzweig
this comes up a lot. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Yonggang Luo <luoyonggang@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38245>
2025-10-09util: add BITSET_CALLOC helperAlyssa Rosenzweig
comes up a bunch. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37779>
2025-08-23util: Fix `BITSET_EXTRACT` out-of-bounds readJosh Simmons
In some situations the implementation of `BITSET_EXTRACT` would read beyond the size of the bitset due to an unconditional + 1 in the address calculation. Reviewed-by: Georg Lehmann <dadschoorse@gmail.com> Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com> Fixes: 0cc9443e9b5 ("util: Add BITSET_EXTRACT") Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34605>
2025-07-29util: remove recursion from bitset helpersTimothy Arceri
Recursion can cause a stack overflow when the range is very large. Fixes: cb558b2b88c2 ("glsl: add mark_array_elements_referenced() fast path") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13617 Reviewed-by: Gert Wollny <gert.wollny@collabora.com> Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36430>
2025-04-17util: Add BITSET_EXTRACTKonstantin Seurer
Extracts a <=32 bit range from a bitset. Reviewed-by: Natalie Vock <natalie.vock@gmx.de> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34273>
2024-12-04util/bitset: add BITSET_GET_RANGE_INSIDE_WORDMarek Olšák
to be used later Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32424>
2024-11-21util: add BITSET_LAST_BIT_BEFOREGeorg Lehmann
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32145>
2024-05-14util: shift the mask in BITSET_TEST_RANGE_INSIDE_WORD to be relative to bMarek Olšák
so that users don't have to shift it at every use. It was supposed to be like this from the beginning. Fixes: fb994f44d91a4b947 - util: make BITSET_TEST_RANGE_INSIDE_WORD take a value to compare with Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29187>
2023-12-09util: make BITSET_TEST_RANGE_INSIDE_WORD take a value to compare withMarek Olšák
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26307>
2023-07-03util/bitset: Add some extra functionsConnor Abbott
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Faith Ekstrand <faith.ekstrand@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22301>
2023-05-23util/bitset: ensure the sets compared have the same size at compile timeEric Engestrom
Instead of checking this at run time. Signed-off-by: Eric Engestrom <eric@igalia.com> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: David Heidelberg <david.heidelberg@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23171>
2022-11-22util: Remove EXPLICIT_CONVERSION macro and use c++11 explicit directlyYonggang Luo
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: David Heidelberg <david.heidelberg@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19895>
2022-07-19util: Constify __bitset_test_rangeJason Ekstrand
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17328>
2022-07-14util/bitset: add BITSET_SIZE()Brian Paul
To get the size (in bits) of a bitset. And minor clean-up in __bitset_ffs(). Signed-off-by: Brian Paul <brianp@vmware.com> Reviewed-by: Roland Scheidegger <sroland@vmware.com> cc: mesa-stable Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17062>
2022-05-10util/bitset: Support larger ranges in BITSET_TEST/CLEAR_RANGEJason Ekstrand
Reviewed-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15988>
2022-03-10util/bitset: Fix off-by-one in __bitset_set_rangeConnor Abbott
Fixes: b3b03e33c9f ("util/bitset: add BITSET_SET_RANGE(..)") Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14107>
2021-09-21util/bitset: add BITSET_SET_RANGE(..)Christian Gmeiner
This version works across word boundary. Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11321>
2021-09-21util/bitset: s/BITSET_SET_RANGE/BITSET_SET_RANGE_INSIDE_WORDChristian Gmeiner
Prep work for the next commit. Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11321>
2021-09-21util/bitset: add left shiftChristian Gmeiner
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11321>
2021-09-21util/bitset: add right shiftChristian Gmeiner
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11321>
2021-09-21util/bitset: add bitwise AND, OR and NOTChristian Gmeiner
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11321>
2021-05-02util/bitset: Add BITSET_COUNT helperAlyssa Rosenzweig
Expressible as a prefix sum but that's a bit unnatural, so add a convenience helper. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Mike Blumenkrants <michael.blumenkrantz@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10581>
2021-04-13nir: add many passes that lower and optimize 16-bit input/outputs and samplersMarek Olšák
Added: * a pass that renumbers bases of IO intrinsics * a pass that converts mediump IO to 16 bits, optionally using the new packed varying slots * a pass that sets (forces) mediump in IO intrinsics (for testing) * a pass that remaps VARYING_SLOT_VAR[0..15]_16BIT to VARYING_SLOT_VAR[0..31] (if some shader stages don't want packed varyings) * a pass that folds type conversions around texture opcodes into those opcodes (e.g. tex(f2f32(coord), ..) is changed into tex accepting f16) * a pass that changes (legalizes) sampler src and dst types based on specified hw constraints (e.g. derivatives must be the same type as coordinates) Reviewed-by: Matt Turner <mattst88@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9050>
2021-04-07util/bitset: Avoid out-of-bounds readsConnor Abbott
I missed a corner case here: when the next range ends right at the end of the bitset, we need to return immediately to avoid trying to search after the bitset. And when finding the next end, we similarly need to bail if the range is size 1 at the very end of the range. In practice this probably would'nt have been noticed, because it would break out of the loop anyway, but I happened to be running something using this under Valgrind and it complained. Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10076>
2021-03-10util/bitset: add a new last bit apiDave Airlie
This is to be used where the bitset is a predefined array size. Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9456>
2021-03-10util/panfrost/glsl: rename BITSET_LAST_BIT to BITSET_LAST_BIT_SIZEDDave Airlie
The current users all pass in the number of dwords, but I'd like to provide an interface that doess ARRAY_SIZE implicitly. Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9456>
2021-01-25util/bitset: Avoid dereferencing the bitset for size == 0.Eric Anholt
If we don't have any bits in our set, don't go reading the pointer. Fixes invalid accesses caught by ASan in liveness and nir_to_tgsi when impl->ssa_alloc == 0. Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8530>
2020-11-03util/bitset: Add a range iterator helperConnor Abbott
I need this for emitting the SO program for turnip, where we want to skip over unused slots by manually advancing the counter. freedreno will also want to use it when it supports multistream streamout. Reviewed-by: Rob Clark <robdclark@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6962>
2020-06-03util: add BITSET_LAST_BIT() helperTimothy Arceri
This is the reverse of BITSET_FFS() Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4910>
2020-01-23util: Remove tmp argument from BITSET_FOREACH_SET macroMatt Turner
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3499> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3499>
2020-01-23util: Explain BITSET_FOREACH_SET paramsMatt Turner
__size, in particular, makes this macro rather confusing to understand how to use. Hopefully this comment saves future users the headache. Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3499>
2019-05-03util/bitset: fix bitset range mask calculations.Dave Airlie
The MASK macro is used in the RANGE macro, and it should return the pre-bitset word mask for the (b) value. i.e. BITSET_MASK(0) should be undefined since it's meaningless. BITSET_MASK(31) should give 0x7fffffff BITSET_MASK(32) should give 0xffffffff BITSET_MASK(33) should give 0x00000001 BITSET_MASK(64) should give 0xffffffff However then BITSET_RANGE ends up broken for cases where it's (b) value is the 0,32,64 value as in that case the lower mask would be 0 not 0xffffffff. This fixes the unit tests that I've added, and my code that uses bitsets. Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Fixes: bb38cadb1c5f2 "More GLSL code" Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
2019-05-02util/bitset: Return an actual bool from test macrosJason Ekstrand
I want to be able to do BITSET_TEST() != BITSET_TEST() and this isn't currently possible because BITSET_TEST() returns a random bit. Compare to zero to get an actual Boolean. Reviewed-by: Eric Engestrom <eric.engestrom@intel.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2018-10-23util: use *unsigned* ints for bit operationsEric Engestrom
Fixes errors thrown by GCC's Undefined Behaviour sanitizer (ubsan) every time this macro is used. Signed-off-by: Eric Engestrom <eric.engestrom@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
2018-06-15util/bitset: include util/macro.hChristian Gmeiner
BITSET_FFS(x) macro makes use of ARRAY_SIZE(x) macro which is defined in util/macro.h. Include it directy to make usage more straightforward. Fixes: 692bd4a1ab9 ("util: replace Elements() with ARRAY_SIZE()") Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
2018-03-29util: Include bitscan.h directlyIan Romanick
Previously bitset.h would include u_math.h to get bitscan.h. u_math.h lives in src/gallium/auxiliary/util while both bitset.h and bitscan.h live in src/util. Having the one file directly include another file that lives in the same directory makes much more sense. As a side-effect, several files need to directly include standard header files that were previously indirectly included. v2: Fix build break in src/amd/common/ac_nir_to_llvm.c. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Eduardo Lima Mitev <elima@igalia.com>
2018-02-27util/bitset: Make C++ wrapper trivially constructible.Francisco Jerez
In order to fix a build failure on compilers not implementing unrestricted unions, which is a C++11 feature. v2: Provide signed integer comparison and assignment operators instead of BITSET_WORD ones to avoid spurious ambiguity warnings on comparisons with a signed integer literal. Fixes: ba79a90fb52e1e81fb "glsl: Switch ast_type_qualifier to a 128-bit bitset." Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105238 Tested-by: Roland Scheidegger <sroland@vmware.com> Tested-By: George Kyriazis <george.kyriazis@intel.com> Reviewed-by: Roland Scheidegger <sroland@vmware.com>
2018-02-24util/bitset: Add C++ wrapper for static-size bitsets.Francisco Jerez
Reviewed-by: Plamena Manolova <plamena.manolova@intel.com>
2016-03-24util/bitset: Allow iterating over const bitsetsJason Ekstrand
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2015-08-18util/bitset: Add a BITSET_FOREACH_SET macroJason Ekstrand
Reviewed-by: Eric Anholt <eric@anholt.net>
2015-03-02util: replace Elements() with ARRAY_SIZE()Brian Paul
Reviewed-by: Matt Turner <mattst88@gmail.com>
2015-02-20util: Move Mesa's bitset.h to util/.Eric Anholt
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>