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 Split bitmap_set/clear i...
details: https://anonhg.NetBSD.org/src/rev/a431d4154936
branches: trunk
changeset: 366331:a431d4154936
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Aug 27 14:52:16 2018 +0000
description:
Split bitmap_set/clear into begin/middle/end sections.
For clarity and speed. Largely from uwe@ with tweaks from me.
diffstat:
sys/external/bsd/drm2/include/linux/bitmap.h | 54 ++++++++++++++++++++-------
1 files changed, 39 insertions(+), 15 deletions(-)
diffs (81 lines):
diff -r dd7a66a9276b -r a431d4154936 sys/external/bsd/drm2/include/linux/bitmap.h
--- a/sys/external/bsd/drm2/include/linux/bitmap.h Mon Aug 27 14:51:55 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/bitmap.h Mon Aug 27 14:52:16 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bitmap.h,v 1.7 2018/08/27 14:51:05 riastradh Exp $ */
+/* $NetBSD: bitmap.h,v 1.8 2018/08/27 14:52:16 riastradh Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -105,16 +105,28 @@
{
const size_t bpl = NBBY * sizeof(*bitmap);
unsigned long *p = bitmap + startbit/bpl;
- unsigned long mask;
- unsigned sz;
+ unsigned initial = startbit%bpl;
- for (sz = bpl - (startbit%bpl), mask = ~0UL << (startbit%bpl);
- nbits >= sz;
- nbits -= sz, sz = bpl, mask = ~0UL)
- *p++ |= mask;
+ /* Handle an initial odd word if any. */
+ if (initial) {
+ /* Does the whole thing fit in a single word? */
+ if (nbits <= bpl - initial) {
+ /* Yes: just set nbits starting at initial. */
+ *p |= ~(~0ULL << nbits) << initial;
+ return;
+ }
+ /* Nope: set all bits above initial, and advance. */
+ *p++ |= ~0ULL << initial;
+ nbits -= bpl - initial;
+ }
+ /* Set the middle part to all bits 1. */
+ for (; nbits >= bpl; nbits -= bpl)
+ *p++ = ~0UL;
+
+ /* Handle a final odd word if any by setting its low nbits. */
if (nbits)
- *p |= mask & ~(~0UL << (nbits + bpl - sz));
+ *p |= ~(~0ULL << nbits);
}
/*
@@ -128,16 +140,28 @@
{
const size_t bpl = NBBY * sizeof(*bitmap);
unsigned long *p = bitmap + startbit/bpl;
- unsigned long mask;
- unsigned sz;
+ unsigned initial = startbit%bpl;
- for (sz = bpl - (startbit%bpl), mask = ~(~0UL << (startbit%bpl));
- nbits >= sz;
- nbits -= sz, sz = bpl, mask = 0UL)
- *p++ &= mask;
+ /* Handle an initial odd word if any. */
+ if (initial) {
+ /* Does the whole thing fit in a single word? */
+ if (nbits <= bpl - initial) {
+ /* Yes: just clear nbits starting at initial. */
+ *p &= ~(~(~0ULL << nbits) << initial);
+ return;
+ }
+ /* Nope: clear all bits above initial, and advance. */
+ *p++ &= ~(~0ULL << initial);
+ nbits -= bpl - initial;
+ }
+ /* Zero the middle part. */
+ for (; nbits >= bpl; nbits -= bpl)
+ *p++ = 0UL;
+
+ /* Handle a final odd word if any by clearing its low nbits. */
if (nbits)
- *p &= mask | (~0UL << (nbits + bpl - sz));
+ *p &= ~0ULL << nbits;
}
/*
Home |
Main Index |
Thread Index |
Old Index