Skip to contentSkip to conversation

Use pair of shifts instead of and in ARM code

RFT Vladimir 'φ-coder/phcoder' Serbinenko 2 participants 3 messages Nov 13, 2013

lore
Share & tools
lore
#0 lore raw

1ff and 3fff can't be easily loaded on ARM. This patch replaces load+and with pair of shift to keep only wanted bits.

(quoted diff) +0 -0

b/grub-core/kern/arm/cache_armv7.S
index 0c16b10..454bad3 100644

grub-core/kern/arm/cache_armv7.S +10 -4
@@ -58,11 +64,17 @@ clean_invalidate_dcache:
        @ read current cache information
        mrc     p15, 1, r8, c0, c0, 0   @ Read CCSIDR
        lsr     r3, r8, #13             @ Number of sets -1
-       ldr     r9, =0x3fff
-       and     r3, r3, r9
+
+       @ Keep only 14 bits of r3
+       lsl     r3, r3, #18
+       lsr     r3, r3, #18
+
        lsr     r4, r8, #3              @ Number of ways -1
-       ldr     r9, =0x1ff
-       and     r4, r4, r9
+
+       @ Keep only 9  bits of r4
+       lsl     r4, r4, #23
+       lsr     r4, r4, #23
+
        and     r7, r8, #7              @ log2(line size in words) - 2
        add     r7, r7, #2              @  adjust
        mov     r8, #1
#1 lore raw
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko

1ff and 3fff can't be easily loaded on ARM. This patch replaces load+and with pair of shift to keep only wanted bits.

Actually, on ARMv7 we could just use MOVW instead:

grub-core/kern/arm/cache_armv7.S clean_invalidate_dcache: · line 61

Quoted 10 lines
grub-core/kern/arm/cache_armv7.S +0 -1
index 0c16b10..454bad3 100644
@@ -58,11 +64,17 @@ clean_invalidate_dcache:
        @ read current cache information
        mrc     p15, 1, r8, c0, c0, 0   @ Read CCSIDR
        lsr     r3, r8, #13             @ Number of sets -1
-       ldr     r9, =0x3fff
	movw	r9, #0x3fff

grub-core/kern/arm/cache_armv7.S clean_invalidate_dcache: · line 64

Quoted 8 lines
grub-core/kern/arm/cache_armv7.S +5 -2
-       and     r3, r3, r9
+
+       @ Keep only 14 bits of r3
+       lsl     r3, r3, #18
+       lsr     r3, r3, #18
+
        lsr     r4, r8, #3              @ Number of ways -1
-       ldr     r9, =0x1ff
	movw	r9, #0x1ff

grub-core/kern/arm/cache_armv7.S clean_invalidate_dcache: · line 80

Quoted 10 lines
grub-core/kern/arm/cache_armv7.S +5 -1
-       and     r4, r4, r9
+
+       @ Keep only 9  bits of r4
+       lsl     r4, r4, #23
+       lsr     r4, r4, #23
+
        and     r7, r8, #7              @ log2(line size in words) - 2
        add     r7, r7, #2              @  adjust
        mov     r8, #1

/
Leif

#2 lore raw
Quoted 6 lines · Leif Lindholm
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko

1ff and 3fff can't be easily loaded on ARM. This patch replaces load+and with pair of shift to keep only wanted bits.

Actually, on ARMv7 we could just use MOVW instead:

Another goal of this patch was to make this code compilable with clang (just a silly experiment) which lacks many useful ARM facilities including architecture switching in file (other than thumb<->arm). This was one of culprits. The other one was that I had to manually assemble barrier instructions.

Quoted 39 lines

grub-core/kern/arm/cache_armv7.S clean_invalidate_dcache: · line 61

Quoted 10 lines
grub-core/kern/arm/cache_armv7.S +0 -1
index 0c16b10..454bad3 100644
@@ -58,11 +64,17 @@ clean_invalidate_dcache:
        @ read current cache information
        mrc     p15, 1, r8, c0, c0, 0   @ Read CCSIDR
        lsr     r3, r8, #13             @ Number of sets -1
-       ldr     r9, =0x3fff
	movw	r9, #0x3fff

grub-core/kern/arm/cache_armv7.S clean_invalidate_dcache: · line 64

Quoted 8 lines
grub-core/kern/arm/cache_armv7.S +5 -2
-       and     r3, r3, r9
+
+       @ Keep only 14 bits of r3
+       lsl     r3, r3, #18
+       lsr     r3, r3, #18
+
        lsr     r4, r8, #3              @ Number of ways -1
-       ldr     r9, =0x1ff
	movw	r9, #0x1ff

grub-core/kern/arm/cache_armv7.S clean_invalidate_dcache: · line 80

Quoted 10 lines
grub-core/kern/arm/cache_armv7.S +5 -1
-       and     r4, r4, r9
+
+       @ Keep only 9  bits of r4
+       lsl     r4, r4, #23
+       lsr     r4, r4, #23
+
        and     r7, r8, #7              @ log2(line size in words) - 2
        add     r7, r7, #2              @  adjust
        mov     r8, #1

/
Leif

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel