Skip to contentSkip to conversation

pinctrl: pinctrl-single: Avoid divisions in context save/restore

PATCH New Geert Uytterhoeven 4 participants 4 messages Jun 7, 2018 – Jun 14, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: pinctrl-single: Avoid divisions in context save/restore

The divisions (and multiplications) can be avoided by changing the loops to use increments of mux_bytes instead of 1.
While at it, remove the unneeded casts when assigning void pointers.

This saves +100 bytes of kernel size on arm32/arm64.

---
Compile-tested only.

As the loops are now identical, the code could be made even smaller by moving the switch() inside the loop, at the expense of readability.

---
 drivers/pinctrl/pinctrl-single.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/pinctrl/pinctrl-single.c +18 -18
index 9c3c00515aa0fe20..5de5dedb804928eb 100644
@@ -1593,19 +1593,19 @@ static int pcs_save_context(struct pcs_device *pcs)
 
 	switch (pcs->width) {
 	case 64:
-		regsl = (u64 *)pcs->saved_vals;
-		for (i = 0; i < pcs->size / mux_bytes; i++)
-			regsl[i] = pcs->read(pcs->base + i * mux_bytes);
+		regsl = pcs->saved_vals;
+		for (i = 0; i < pcs->size; i += mux_bytes)
+			*regsl++ = pcs->read(pcs->base + i);
 		break;
 	case 32:
-		regsw = (u32 *)pcs->saved_vals;
-		for (i = 0; i < pcs->size / mux_bytes; i++)
-			regsw[i] = pcs->read(pcs->base + i * mux_bytes);
+		regsw = pcs->saved_vals;
+		for (i = 0; i < pcs->size; i += mux_bytes)
+			*regsw++ = pcs->read(pcs->base + i);
 		break;
 	case 16:
-		regshw = (u16 *)pcs->saved_vals;
-		for (i = 0; i < pcs->size / mux_bytes; i++)
-			regshw[i] = pcs->read(pcs->base + i * mux_bytes);
+		regshw = pcs->saved_vals;
+		for (i = 0; i < pcs->size; i += mux_bytes)
+			*regshw++ = pcs->read(pcs->base + i);
 		break;
 	}
 
@@ -1623,19 +1623,19 @@ static void pcs_restore_context(struct pcs_device *pcs)
 
 	switch (pcs->width) {
 	case 64:
-		regsl = (u64 *)pcs->saved_vals;
-		for (i = 0; i < pcs->size / mux_bytes; i++)
-			pcs->write(regsl[i], pcs->base + i * mux_bytes);
+		regsl = pcs->saved_vals;
+		for (i = 0; i < pcs->size; i += mux_bytes)
+			pcs->write(*regsl++, pcs->base + i);
 		break;
 	case 32:
-		regsw = (u32 *)pcs->saved_vals;
-		for (i = 0; i < pcs->size / mux_bytes; i++)
-			pcs->write(regsw[i], pcs->base + i * mux_bytes);
+		regsw = pcs->saved_vals;
+		for (i = 0; i < pcs->size; i += mux_bytes)
+			pcs->write(*regsw++, pcs->base + i);
 		break;
 	case 16:
-		regshw = (u16 *)pcs->saved_vals;
-		for (i = 0; i < pcs->size / mux_bytes; i++)
-			pcs->write(regshw[i], pcs->base + i * mux_bytes);
+		regshw = pcs->saved_vals;
+		for (i = 0; i < pcs->size; i += mux_bytes)
+			pcs->write(*regshw++, pcs->base + i);
 		break;
 	}
 }
Signature · 1 line
2.7.4
maintainer
#1 lore raw

PATCH 1/1 pinctrl: pinctrl-single: Avoid divisions in context save/restore

Quoted 9 lines · Geert Uytterhoeven

The divisions (and multiplications) can be avoided by changing the loops to use increments of mux_bytes instead of 1.
While at it, remove the unneeded casts when assigning void pointers.

This saves +100 bytes of kernel size on arm32/arm64.

---
Compile-tested only.

Makes sense to me:

Keerthy can you please test?

Regards,

Tony

#2 lore raw

PATCH 1/1 pinctrl: pinctrl-single: Avoid divisions in context save/restore

Quoted 11 lines · Tony Lindgren
Quoted 9 lines · Geert Uytterhoeven

The divisions (and multiplications) can be avoided by changing the loops to use increments of mux_bytes instead of 1.
While at it, remove the unneeded casts when assigning void pointers.

This saves +100 bytes of kernel size on arm32/arm64.

---
Compile-tested only.

Quoted 5 lines

Makes sense to me:

Keerthy can you please test?

Tested on AM437x-gp-evm for Deep Sleep0.

Thanks Geert!

Quoted 5 lines

Regards,

Tony

#3 lore raw

PATCH 1/1 pinctrl: pinctrl-single: Avoid divisions in context save/restore

In reply to Geert Uytterhoeven
Quoted 7 lines · Geert Uytterhoeven

The divisions (and multiplications) can be avoided by changing the loops to use increments of mux_bytes instead of 1.
While at it, remove the unneeded casts when assigning void pointers.

This saves +100 bytes of kernel size on arm32/arm64.

Patch applied for v4.19.

Yours,
Linus Walleij