pinctrl: pinctrl-single: Avoid divisions in context save/restore
Subsystems (3)
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
@@ -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
Tony Lindgren
maintainerPATCH 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_bytesinstead of 1.
While at it, remove the unneeded casts when assigning void pointers.This saves +100 bytes of kernel size on arm32/arm64.
Signed-off-by Geert Uytterhoeven <[email protected]>---
Compile-tested only.
Makes sense to me:
Keerthy can you please test?
Regards,
Tony
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_bytesinstead of 1.
While at it, remove the unneeded casts when assigning void pointers.This saves +100 bytes of kernel size on arm32/arm64.
Signed-off-by Geert Uytterhoeven <[email protected]>---
Compile-tested only.
Quoted 5 lines
Makes sense to me:
Acked-by Tony Lindgren <[email protected]>Keerthy can you please test?
Tested on AM437x-gp-evm for Deep Sleep0.
Thanks Geert!
Quoted 5 lines
Regards,
Tony
PATCH 1/1 pinctrl: pinctrl-single: Avoid divisions in context save/restore
In reply to Geert UytterhoevenQuoted 7 lines · Geert Uytterhoeven
The divisions (and multiplications) can be avoided by changing the loops to use increments of
mux_bytesinstead of 1.
While at it, remove the unneeded casts when assigning void pointers.This saves +100 bytes of kernel size on arm32/arm64.
Signed-off-by Geert Uytterhoeven <[email protected]>
Patch applied for v4.19.
Yours,
Linus Walleij