]> xenbits.xensource.com Git - people/dwmw2/xen.git/commitdiff
x86: comment opaque expression in __page_to_virt()
authorJan Beulich <jbeulich@suse.com>
Mon, 3 Sep 2012 06:17:50 +0000 (08:17 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 3 Sep 2012 06:17:50 +0000 (08:17 +0200)
mm.h's __page_to_virt() has a rather opaque expression. Comment it.

Reported-By: Ian Campbell <ian.campbell@citrix.com>
Suggested-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen/include/asm-x86/mm.h

index 4cba2765fbed6f1b93ce742f70f3f58f955ee607..2ed53d94166b0b2620c4d9185705f9c1782ce0b4 100644 (file)
@@ -323,6 +323,12 @@ static inline struct page_info *__virt_to_page(const void *v)
 static inline void *__page_to_virt(const struct page_info *pg)
 {
     ASSERT((unsigned long)pg - FRAMETABLE_VIRT_START < FRAMETABLE_VIRT_END);
+    /*
+     * (sizeof(*pg) & -sizeof(*pg)) selects the LS bit of sizeof(*pg). The
+     * division and re-multiplication avoids one shift when sizeof(*pg) is a
+     * power of two (otherwise there would be a right shift followed by a
+     * left shift, which the compiler can't know it can fold into one).
+     */
     return (void *)(DIRECTMAP_VIRT_START +
                     ((unsigned long)pg - FRAMETABLE_VIRT_START) /
                     (sizeof(*pg) / (sizeof(*pg) & -sizeof(*pg))) *