diff mbox series

[4/4] parisc: checksum: Optimize from32to16

Message ID 20240221-parisc_use_generic_checksum-v1-4-ad34d895fd1b@rivosinc.com (mailing list archive)
State Accepted, archived
Headers show
Series parisc: checksum: Use generic implementations and optimize checksum | expand

Commit Message

Charlie Jenkins Feb. 22, 2024, 2:37 a.m. UTC
Replace the shifting and masking of x with a rotation. This generates
better assembly.

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
---
 arch/parisc/lib/checksum.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Guenter Roeck Feb. 22, 2024, 4:04 p.m. UTC | #1
On Wed, Feb 21, 2024 at 06:37:14PM -0800, Charlie Jenkins wrote:
> Replace the shifting and masking of x with a rotation. This generates
> better assembly.
> 
> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  arch/parisc/lib/checksum.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/parisc/lib/checksum.c b/arch/parisc/lib/checksum.c
> index eaa660491e24..1ae8cc730d13 100644
> --- a/arch/parisc/lib/checksum.c
> +++ b/arch/parisc/lib/checksum.c
> @@ -27,11 +27,8 @@
>  
>  static inline unsigned short from32to16(unsigned int x)
>  {
> -	/* 32 bits --> 16 bits + carry */
> -	x = (x & 0xffff) + (x >> 16);
> -	/* 16 bits + carry --> 16 bits including carry */
> -	x = (x & 0xffff) + (x >> 16);
> -	return (unsigned short)x;
> +	x += ror32(x, 16);
> +	return (unsigned short)(x >> 16);
>  }
>  
>  unsigned int do_csum(const unsigned char *buff, int len)
> 
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/arch/parisc/lib/checksum.c b/arch/parisc/lib/checksum.c
index eaa660491e24..1ae8cc730d13 100644
--- a/arch/parisc/lib/checksum.c
+++ b/arch/parisc/lib/checksum.c
@@ -27,11 +27,8 @@ 
 
 static inline unsigned short from32to16(unsigned int x)
 {
-	/* 32 bits --> 16 bits + carry */
-	x = (x & 0xffff) + (x >> 16);
-	/* 16 bits + carry --> 16 bits including carry */
-	x = (x & 0xffff) + (x >> 16);
-	return (unsigned short)x;
+	x += ror32(x, 16);
+	return (unsigned short)(x >> 16);
 }
 
 unsigned int do_csum(const unsigned char *buff, int len)