Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd/drm2/include/linux Try setting and clearing...
details: https://anonhg.NetBSD.org/src/rev/7489c51a0974
branches: trunk
changeset: 366325:7489c51a0974
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Aug 27 14:50:24 2018 +0000
description:
Try setting and clearing the bits we meant, not other bits.
Fix comments to match intent while we're fixing reality too.
diffstat:
sys/external/bsd/drm2/include/linux/bitmap.h | 37 +++++++++++++++------------
1 files changed, 20 insertions(+), 17 deletions(-)
diffs (73 lines):
diff -r 5bb33bf9b43a -r 7489c51a0974 sys/external/bsd/drm2/include/linux/bitmap.h
--- a/sys/external/bsd/drm2/include/linux/bitmap.h Mon Aug 27 14:50:04 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/bitmap.h Mon Aug 27 14:50:24 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bitmap.h,v 1.3 2018/08/27 07:13:45 riastradh Exp $ */
+/* $NetBSD: bitmap.h,v 1.4 2018/08/27 14:50:24 riastradh Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -96,44 +96,47 @@
/*
* bitmap_set(bitmap, startbit, nbits)
*
- * Set bits at startbit, startbit+1, ..., nbits-2, nbits-1 to 1.
+ * Set bits at startbit, startbit+1, ..., startbit+nbits-2,
+ * startbit+nbits-1 to 1.
*/
static inline void
bitmap_set(unsigned long *bitmap, size_t startbit, size_t nbits)
{
const size_t bpl = NBBY * sizeof(*bitmap);
- unsigned long *p;
+ unsigned long *p = bitmap + startbit/bpl;
unsigned long mask;
+ unsigned sz;
- for (p = bitmap + startbit/bpl, mask = ~(~0UL << (startbit%bpl));
- nbits >= bpl;
- p++, nbits -= bpl, mask = ~0UL)
- *p |= mask;
+ for (sz = bpl - (startbit%bpl), mask = ~0UL << (startbit%bpl);
+ nbits >= sz;
+ nbits -= sz, sz = bpl, mask = ~0UL)
+ *p++ |= mask;
if (nbits)
- *p |= mask & (~0UL << nbits);
+ *p |= mask & ~(~0UL << (nbits + bpl - sz));
}
/*
- * bitmap_set(bitmap, startbit, nbits)
+ * bitmap_clear(bitmap, startbit, nbits)
*
- * Clear bits at startbit, startbit+1, ..., nbits-2, nbits-1,
- * replacing them by 0.
+ * Clear bits at startbit, startbit+1, ..., startbit+nbits-2,
+ * startbit+nbits-1, replacing them by 0.
*/
static inline void
bitmap_clear(unsigned long *bitmap, size_t startbit, size_t nbits)
{
const size_t bpl = NBBY * sizeof(*bitmap);
- unsigned long *p;
+ unsigned long *p = bitmap + startbit/bpl;
unsigned long mask;
+ unsigned sz;
- for (p = bitmap + startbit/bpl, mask = ~0UL << (startbit%bpl);
- nbits >= bpl;
- p++, nbits -= bpl, mask = 0UL)
- *p &= mask;
+ for (sz = bpl - (startbit%bpl), mask = ~(~0UL << (startbit%bpl));
+ nbits >= sz;
+ nbits -= sz, sz = bpl, mask = 0UL)
+ *p++ &= mask;
if (nbits)
- *p &= mask | ~(~0UL << nbits);
+ *p &= mask | (~0UL << (nbits + bpl - sz));
}
/*
Home |
Main Index |
Thread Index |
Old Index