]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
arm64: mm: use bit ops rather than arithmetic in pa/va translations
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 22 Feb 2016 17:46:04 +0000 (18:46 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Tue, 23 Feb 2016 17:43:25 +0000 (17:43 +0000)
Since PAGE_OFFSET is chosen such that it cuts the kernel VA space right
in half, and since the size of the kernel VA space itself is always a
power of 2, we can treat PAGE_OFFSET as a bitmask and replace the
additions/subtractions with 'or' and 'and-not' operations.

For the comparison against PAGE_OFFSET, a mov/cmp/branch sequence ends
up getting replaced with a single tbz instruction. For the additions and
subtractions, we save a mov instruction since the mask is folded into the
instruction's immediate field.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/memory.h

index 460d09bf94424c45b40a5a486ac4b3b93ef0fdd5..eb798156cf56ad03e11b23e92b3a3bcaa1f7f99d 100644 (file)
  */
 #define __virt_to_phys(x) ({                                           \
        phys_addr_t __x = (phys_addr_t)(x);                             \
-       __x >= PAGE_OFFSET ? (__x - PAGE_OFFSET + PHYS_OFFSET) :        \
-                            (__x - kimage_voffset); })
+       __x & BIT(VA_BITS - 1) ? (__x & ~PAGE_OFFSET) + PHYS_OFFSET :   \
+                                (__x - kimage_voffset); })
 
-#define __phys_to_virt(x)      ((unsigned long)((x) - PHYS_OFFSET + PAGE_OFFSET))
+#define __phys_to_virt(x)      ((unsigned long)((x) - PHYS_OFFSET) | PAGE_OFFSET)
 #define __phys_to_kimg(x)      ((unsigned long)((x) + kimage_voffset))
 
 /*
 
 #ifndef __ASSEMBLY__
 
+#include <linux/bitops.h>
 #include <linux/mmdebug.h>
 
 extern phys_addr_t             memstart_addr;