[PATCH v8 2/5] include: sbi/sbi_hartmask: add equality helper

Pawandeep Oza pawandeep.oza at oss.qualcomm.com
Tue Nov 17 09:27:44 PST 2026


On Mon, Nov 16, 2026 at 7:07 PM Rahul Pathak
<rahul.pathak at oss.qualcomm.com> wrote:
>
> On Tue, Nov 17, 2026 at 4:06 AM Pawandeep Oza
> <pawandeep.oza at oss.qualcomm.com> wrote:
> >
> > From: Oza Pawandeep <pawandeep.oza at oss.qualcomm.com>
> >
> > Add sbi_hartmask_equal() to check whether two hartmasks contain the
> > same hart indexes.
> >
> > Signed-off-by: Oza Pawandeep <pawandeep.oza at oss.qualcomm.com>
> > ---
> >  include/sbi/sbi_hartmask.h | 26 ++++++++++++++++++++++++++
> >  1 file changed, 26 insertions(+)
> >
> > diff --git a/include/sbi/sbi_hartmask.h b/include/sbi/sbi_hartmask.h
> > index da6821ee..253a5dcd 100644
> > --- a/include/sbi/sbi_hartmask.h
> > +++ b/include/sbi/sbi_hartmask.h
> > @@ -206,4 +206,30 @@ static inline int sbi_hartmask_weight(const struct sbi_hartmask *srcp)
> >                 (__i) < SBI_HARTMASK_MAX_BITS; \
> >                 (__i) = find_next_bit((__m)->bits, SBI_HARTMASK_MAX_BITS, (__i) + 1))
> >
> > +
> > +/**
> > + * Check whether two hartmasks are equal
> > + * @param a the first hartmask to compare
> > + * @param b the second hartmask to compare
> > + *
> > + * Return: true if both hartmasks contain the same harts, false otherwise
> > + */
>
> For this simple comparison why not perform the words comparison
> instead of going bit by bit. BITS_TO_LONGS will give the fixed words
> making the sbi_hartmask.
oza: sounds good, sure let me change this way.
>
> > +static inline bool sbi_hartmask_equal(const struct sbi_hartmask *a,
> > +                                     const struct sbi_hartmask *b)
> > +{
> > +       u32 hartindex;
> > +
> > +       sbi_hartmask_for_each_hartindex(hartindex, a) {
> > +               if (!sbi_hartmask_test_hartindex(hartindex, b))
> > +                       return false;
> > +       }
> > +
> > +       sbi_hartmask_for_each_hartindex(hartindex, b) {
> > +               if (!sbi_hartmask_test_hartindex(hartindex, a))
> > +                       return false;
> > +       }
> > +
> > +       return true;
> > +}
> > +
> >  #endif
> > --
> > 2.43.0
> >
> >
> > --
> > opensbi mailing list
> > opensbi at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list