Received: by 10.213.65.68 with SMTP id h4csp3522710imn; Mon, 9 Apr 2018 23:42:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/V0kbzav3MsEtHNvybRuw4AlSuMxvlt5Bw69nqocgFnnSDT/wXEq0WEpWSn6d3IRdTgkNU X-Received: by 2002:a17:902:7441:: with SMTP id e1-v6mr9791249plt.169.1523342569666; Mon, 09 Apr 2018 23:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523342569; cv=none; d=google.com; s=arc-20160816; b=gXeoIilXSFFg79C9CrCHHq47WeGs4aJO5Tq9eD775NrBGxPBbWusolW3PmrBifjBYW b7fWZKMm4OSkCAdgNQc/4DfeNI1I/lkWpfEULZC2BZmpIZRjHmv2JaxsEUqRqi2jOGf9 9Wqb61ySJFeBjf0Vwobr3WjfNz/X3YYZLT1oVPgHivi2elhFQYfn2t6M1gk+wZOCd1eJ NnS1DENYII39lRjsYbpQMq1QMecOvre/Z1H7scFU0nPm8xYKsYTlUCrVWl/aor0rZQpA ymVrUAi/7XoY5dom1tiEPBiv9yg1I6kooqJBS9XU38fSkWcb6MB3/0B0XtW/XcqIoQRW C+eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:cc:to:subject:from :arc-authentication-results; bh=NQ4tMVReOr2PKGuX3eY+FLbChSLXGdYPZOtT0WV/OTY=; b=l4yoOIsDoMoAu2hl2d3AewuN/wTR6dlzrq4CHb1lcK8fbMnnDh/vsMUAmaGg3makpN YGiCECGX9ttDOG4JZTeMxX3k2DLxKOcBXm1T7x24qBhxqxZ+gcecb84IjbsALTh4WPqp zfSorgRbinjniHDM6OwqQUED+ikSFZIDse+o+zlmDNjG9oDDaChWzcQdI9qGr+tsW5FI P/lsZ3p+mk71E7s2XPWsq/wYYXFRPXTrAHj7GPeyYNuZXG9yG9JFkF1OVjUEUsgafvY+ qHOsMc4jTsKXu3ZuNI1IYe7Unwz27RFFYd3TT3V0tCnerlvNUWMiio9aK46e/7NWeC+a VI9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1-v6si1969054pld.108.2018.04.09.23.42.12; Mon, 09 Apr 2018 23:42:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752435AbeDJGeh (ORCPT + 99 others); Tue, 10 Apr 2018 02:34:37 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:62550 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752064AbeDJGeg (ORCPT ); Tue, 10 Apr 2018 02:34:36 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 40Ky7t4Y51z9ttfv; Tue, 10 Apr 2018 08:34:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id EuhCsruoRGFN; Tue, 10 Apr 2018 08:34:34 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 40Ky7t4345z9ttfs; Tue, 10 Apr 2018 08:34:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 987258B791; Tue, 10 Apr 2018 08:34:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id j4IE3zHSTqMY; Tue, 10 Apr 2018 08:34:35 +0200 (CEST) Received: from po15720vm.idsi0.si.c-s.fr (unknown [192.168.232.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 669E78B750; Tue, 10 Apr 2018 08:34:35 +0200 (CEST) Received: by po15720vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 272F8653BC; Tue, 10 Apr 2018 08:34:35 +0200 (CEST) From: Christophe Leroy Subject: [PATCH] powerpc/64: optimises from64to32() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Scott Wood Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Message-Id: <20180410063435.272F8653BC@po15720vm.idsi0.si.c-s.fr> Date: Tue, 10 Apr 2018 08:34:35 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation of from64to32() gives a poor result: 0000000000000270 <.from64to32>: 270: 38 00 ff ff li r0,-1 274: 78 69 00 22 rldicl r9,r3,32,32 278: 78 00 00 20 clrldi r0,r0,32 27c: 7c 60 00 38 and r0,r3,r0 280: 7c 09 02 14 add r0,r9,r0 284: 78 09 00 22 rldicl r9,r0,32,32 288: 7c 00 4a 14 add r0,r0,r9 28c: 78 03 00 20 clrldi r3,r0,32 290: 4e 80 00 20 blr This patch modifies from64to32() to operate in the same spirit as csum_fold() It swaps the two 32-bit halves of sum then it adds it with the unswapped sum. If there is a carry from adding the two 32-bit halves, it will carry from the lower half into the upper half, giving us the correct sum in the upper half. The resulting code is: 0000000000000260 <.from64to32>: 260: 78 60 00 02 rotldi r0,r3,32 264: 7c 60 1a 14 add r3,r0,r3 268: 78 63 00 22 rldicl r3,r3,32,32 26c: 4e 80 00 20 blr Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/checksum.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/checksum.h b/arch/powerpc/include/asm/checksum.h index 4e63787dc3be..54065caa40b3 100644 --- a/arch/powerpc/include/asm/checksum.h +++ b/arch/powerpc/include/asm/checksum.h @@ -12,6 +12,7 @@ #ifdef CONFIG_GENERIC_CSUM #include #else +#include /* * Computes the checksum of a memory block at src, length len, * and adds in "sum" (32-bit), while copying the block to dst. @@ -55,11 +56,7 @@ static inline __sum16 csum_fold(__wsum sum) 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; + return (x + ror64(x, 32)) >> 32; } static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, -- 2.13.3