Skip to contentSkip to conversation

arm64: fpsimd: avoid restoring fpcr if the contents haven't changed

PATCH New Will Deacon 2 participants 3 messages Jun 26, 2014 – Jun 27, 2014 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: fpsimd: avoid restoring fpcr if the contents haven't changed

Writing to the FPCR is commonly implemented as a self-synchronising operation in the CPU, so avoid writing to the register when the saved value matches that in the hardware already.

---
 arch/arm64/include/asm/fpsimdmacros.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/include/asm/fpsimdmacros.h +9 -0
index 768414d55e64..137c0f45b0a8 100644
@@ -40,6 +40,7 @@
 	str	w\tmpnr, [\state, #16 * 2 + 4]
 .endm
 
+/* Clobbers \state */
 .macro fpsimd_restore state, tmpnr
 	ldp	q0, q1, [\state, #16 * 0]
 	ldp	q2, q3, [\state, #16 * 2]
@@ -60,7 +61,15 @@
 	ldr	w\tmpnr, [\state, #16 * 2]
 	msr	fpsr, x\tmpnr
 	ldr	w\tmpnr, [\state, #16 * 2 + 4]
+	/*
+	 * Writes to fpcr may be self-synchronising, so avoid restoring
+	 * the register if it hasn't changed.
+	 */
+	mrs	\state, fpcr
+	cmp	x\tmpnr, \state
+	b.eq	9999f
 	msr	fpcr, x\tmpnr
+9999:
 .endm
 
 .altmacro
Signature · 1 line
2.0.0
#1 lore raw

PATCH 1/1 arm64: fpsimd: avoid restoring fpcr if the contents haven't changed

Hey Will,

Quoted 27 lines · Will Deacon

Writing to the FPCR is commonly implemented as a self-synchronising operation in the CPU, so avoid writing to the register when the saved value matches that in the hardware already.

---
 arch/arm64/include/asm/fpsimdmacros.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/include/asm/fpsimdmacros.h +2 -0
index 768414d55e64..137c0f45b0a8 100644
@@ -40,6 +40,7 @@
        str     w\tmpnr, [\state, #16 * 2 + 4]
 .endm
 
+/* Clobbers \state */
 .macro fpsimd_restore state, tmpnr
        ldp     q0, q1, [\state, #16 * 0]
        ldp     q2, q3, [\state, #16 * 2]
@@ -60,7 +61,15 @@
        ldr     w\tmpnr, [\state, #16 * 2]
        msr     fpsr, x\tmpnr
        ldr     w\tmpnr, [\state, #16 * 2 + 4]
+       /*

arch/arm64/include/asm/fpsimdmacros.h line 74

Quoted 10 lines
arch/arm64/include/asm/fpsimdmacros.h +7 -0
+        * Writes to fpcr may be self-synchronising, so avoid restoring
+        * the register if it hasn't changed.
+        */
+       mrs     \state, fpcr
+       cmp     x\tmpnr, \state
+       b.eq    9999f
        msr     fpcr, x\tmpnr
+9999:
 .endm
 

I would assume the same would apply to the partial restore that was merged during the last window?

Signature · 1 line
Ard.
#2 lore raw

PATCH 1/1 arm64: fpsimd: avoid restoring fpcr if the contents haven't changed

Quoted 1 line · Ard Biesheuvel

Hey Will,

Hi Ard,

Quoted 33 lines · Will Deacon
Quoted 32 lines

Writing to the FPCR is commonly implemented as a self-synchronising operation in the CPU, so avoid writing to the register when the saved value matches that in the hardware already.

---
 arch/arm64/include/asm/fpsimdmacros.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/include/asm/fpsimdmacros.h +7 -0
index 768414d55e64..137c0f45b0a8 100644
@@ -40,6 +40,7 @@
        str     w\tmpnr, [\state, #16 * 2 + 4]
 .endm
 
+/* Clobbers \state */
 .macro fpsimd_restore state, tmpnr
        ldp     q0, q1, [\state, #16 * 0]
        ldp     q2, q3, [\state, #16 * 2]
@@ -60,7 +61,15 @@
        ldr     w\tmpnr, [\state, #16 * 2]
        msr     fpsr, x\tmpnr
        ldr     w\tmpnr, [\state, #16 * 2 + 4]
+       /*
+        * Writes to fpcr may be self-synchronising, so avoid restoring
+        * the register if it hasn't changed.
+        */
+       mrs     \state, fpcr
+       cmp     x\tmpnr, \state
Quoted 8 lines

arch/arm64/include/asm/fpsimdmacros.h line 74

Quoted 5 lines
arch/arm64/include/asm/fpsimdmacros.h +2 -0
+       b.eq    9999f
        msr     fpcr, x\tmpnr
+9999:
 .endm
 

I would assume the same would apply to the partial restore that was merged during the last window?

Good point; I'll take a look.

Cheers,

Will