Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/riastradh-drm2]: src/sys/external/bsd/drm2/include/linux Fix up some bit...



details:   https://anonhg.NetBSD.org/src/rev/251598f21ca5
branches:  riastradh-drm2
changeset: 788369:251598f21ca5
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jul 24 03:28:09 2013 +0000

description:
Fix up some bit-hacking and pointer-futzing in <linux/kernel.h>.

- Avoid C arithmetic pitfalls and multiple evaluatoin in round_up.
- Add round_down.
- Explain why upper_32_bits and lower_32_bits exist.
- Explain what container_of does.

diffstat:

 sys/external/bsd/drm2/include/linux/kernel.h |  19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diffs (37 lines):

diff -r fb5d01d97757 -r 251598f21ca5 sys/external/bsd/drm2/include/linux/kernel.h
--- a/sys/external/bsd/drm2/include/linux/kernel.h      Wed Jul 24 03:27:52 2013 +0000
+++ b/sys/external/bsd/drm2/include/linux/kernel.h      Wed Jul 24 03:28:09 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kernel.h,v 1.1.2.17 2013/07/24 03:03:37 riastradh Exp $        */
+/*     $NetBSD: kernel.h,v 1.1.2.18 2013/07/24 03:28:09 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -46,11 +46,26 @@
 
 #define        uninitialized_var(x)    x
 
-#define        round_up(X, Y)  roundup2(X, Y)
+/*
+ * Rounding to powers of two -- carefully avoiding multiple evaluation
+ * of arguments and pitfalls with C integer arithmetic rules.
+ */
+#define        round_up(X, N)          ((((X) - 1) | ((N) - 1)) + 1)
+#define        round_down(X, N)        ((X) & ~(uintmax_t)((N) - 1))
 
+/*
+ * These select 32-bit halves of what may be 32- or 64-bit quantities,
+ * for which straight 32-bit shifts may be undefined behaviour (and do
+ * the wrong thing on most machines: return the input unshifted by
+ * ignoring the upper bits of the shift count).
+ */
 #define        upper_32_bits(X)        ((uint32_t) (((X) >> 16) >> 16))
 #define        lower_32_bits(X)        ((uint32_t) ((X) & 0xffffffffUL))
 
+/*
+ * Given x = &c->f, container_of(x, T, f) gives us back c, where T is
+ * the type of c.
+ */
 #define        container_of(PTR, TYPE, FIELD)                                  \
        ((void)sizeof((PTR) -                                           \
                &((TYPE *)(((char *)(PTR)) -                            \



Home | Main Index | Thread Index | Old Index