On Tue, Feb 17, 2015 at 12:04:22PM +0000, David Laight wrote:
> > +static inline u32 from64to32(u64 x)
> > +{
> > + /* add up 32-bit and 32-bit for 32+c bit */
> > + x = (x & 0xffffffff) + (x >> 32);
> > + /* add up carry.. */
> > + x = (x & 0xffffffff) + (x >> 32);
> > + return (u32)x;
> > +}
>
> As a matter of interest, does the compiler optimise away the
> second (x & 0xffffffff) ?
> The code could just be:
> x = (x & 0xffffffff) + (x >> 32);
> return x + (x >> 32);
>
On my side, from what I've seen so far, your version results in better
assembly, esp. with clang, but my first version
http://article.gmane.org/gmane.linux.kernel/1875407:
x += (x << 32) + (x >> 32);
return (__force __wsum)(x >> 32);
resulted in even better assembly, I just verified with gcc/clang,
x86_64/ARM and -O1,2,3.
Karl
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- [PATCH 3.12 068/122] ext4: prevent bugon on race between writ... Jiri Slaby
- [PATCH 3.12 086/122] net: don't OOPS on socket aio Jiri Slaby
- [PATCH 3.12 089/122] ipv4: tcp: get rid of ugly unicast_sock Jiri Slaby
- [PATCH 3.12 095/122] KVM: x86: Warn if guest virtual address ... Jiri Slaby
- [PATCH 3.12 094/122] Bluetooth: ath3k: workaround the compati... Jiri Slaby
- [PATCH 3.12 101/122] KVM: x86: Sysexit emulation does not mas... Jiri Slaby
- [PATCH 3.12 078/122] ipv6: stop sending PTB packets for MTU &... Jiri Slaby
- [PATCH 3.12 092/122] rbd: drop an unsafe assertion Jiri Slaby
- [PATCH 3.12 065/122] lib/checksum.c: fix carry in csum_tcpudp... Jiri Slaby
- RE: [PATCH 3.12 065/122] lib/checksum.c: fix carry in cs... David Laight
- Re: [PATCH 3.12 065/122] lib/checksum.c: fix carry i... Karl Beldan
- RE: [PATCH 3.12 065/122] lib/checksum.c: fix car... David Laight
- Re: [PATCH 3.12 065/122] lib/checksum.c: fix... Karl Beldan
- [PATCH 3.12 103/122] ACPI idle: permit sparse C-state sub-sta... Jiri Slaby
- [PATCH 3.12 069/122] lib/checksum.c: fix build for generic cs... Jiri Slaby
- [PATCH 3.12 088/122] tcp: ipv4: initialize unicast_sock sk_pa... Jiri Slaby
- [PATCH 3.12 083/122] ping: Fix race in free in receive path Jiri Slaby
- [PATCH 3.12 075/122] crypto: crc32c - add missing crypto modu... Jiri Slaby
- [PATCH 3.12 074/122] x86,kvm,vmx: Preserve CR4 across VM entr... Jiri Slaby
- [PATCH 3.12 035/122] powerpc/xmon: Fix another endiannes issu... Jiri Slaby
- [PATCH 3.12 013/122] target: Drop arbitrary maximum I/O size ... Jiri Slaby

