lkml.org 
[lkml]   [2023]   [Sep]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH v2 1/5] riscv: Checksum header
Date
...
> > > +/*
> > > + * Fold a partial checksum without adding pseudo headers
> > > + */
> > > +static inline __sum16 csum_fold(__wsum sum)
> > > +{
> > > + sum += (sum >> 16) | (sum << 16);
> > > + return (__force __sum16)(~(sum >> 16));
> > > +}

I'm intrigued, gcc normally compiler that quite well.
The very similar (from arch/arc):
return (~sum - rol32(sum, 16)) >> 16;
is slightly better on most architectures.
(Especially if the ~sum and rol() can be executed together.)

The only odd archs I saw were sparc32 (carry flag bug no rotate)
and arm (barrel shifter on all instructions).

It is better than the current asm for a lot of archs including x64.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

\
 
 \ /
  Last update: 2023-09-10 23:21    [W:0.066 / U:0.268 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site