From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, URIBL_BLOCKED,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86EBBC04E53 for ; Wed, 15 May 2019 09:47:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4BD2520843 for ; Wed, 15 May 2019 09:47:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bXNwR+ES" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BD2520843 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=G7YJmhD3bRqWxefAaSQEuDgGyINqb1f53zXrKad61Cc=; b=bXNwR+ES9HP37Y dKWVPIaKzkeaAWV8iLL0FxqUpPtbnn+t/1u5AXXwqxM9t85ZwOwSWdksFx+/P6bJ9x3V8X/VIH2se gOU7C57sVP75qvKscJWFQkL6egdj4ZTFN7HdI79IloNgABlNu2iSqzmlGHgy8Ge0ImijA4ZfWA1lh XDRcNS+2x1BUovgSikII9kfNyiAJW9iy5eIrLnT4AY8lqqBET9WJ3ccFsVqaHuCIKm0FML7F50plj pVc88VsIH6gH4dvaii+1WHel71wnBaGNZTi24fMcuSpfEtFsCX1xc2KGVU9OAguUcFOkgAvIyT6DY 5IDWRmut79Rmh4vhCEdA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQqVG-0002ru-As; Wed, 15 May 2019 09:47:14 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQqVA-0002mX-Lg for linux-arm-kernel@lists.infradead.org; Wed, 15 May 2019 09:47:10 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3839380D; Wed, 15 May 2019 02:47:08 -0700 (PDT) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B1F153F703; Wed, 15 May 2019 02:47:06 -0700 (PDT) Date: Wed, 15 May 2019 10:47:04 +0100 From: Will Deacon To: Robin Murphy Subject: Re: [PATCH] arm64: do_csum: implement accelerated scalar version Message-ID: <20190515094704.GC24357@fuggles.cambridge.arm.com> References: <20190218230842.11448-1-ard.biesheuvel@linaro.org> <20190412095243.GA27193@fuggles.cambridge.arm.com> <41b30c72-c1c5-14b2-b2e1-3507d552830d@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <41b30c72-c1c5-14b2-b2e1-3507d552830d@arm.com> User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190515_024708_769230_4B795771 X-CRM114-Status: GOOD ( 19.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , netdev@vger.kernel.org, ilias.apalodimas@linaro.org, Zhangshaokun , "huanglingyan \(A\)" , linux-arm-kernel@lists.infradead.org, steve.capper@arm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 15, 2019 at 07:18:22PM +0100, Robin Murphy wrote: > On 12/04/2019 10:52, Will Deacon wrote: > > I'm waiting for Robin to come back with numbers for a C implementation. > > > > Robin -- did you get anywhere with that? > > Still not what I would call finished, but where I've got so far (besides an > increasingly elaborate test rig) is as below - it still wants some unrolling > in the middle to really fly (and actual testing on BE), but the worst-case > performance already equals or just beats this asm version on Cortex-A53 with > GCC 7 (by virtue of being alignment-insensitive and branchless except for > the loop). Unfortunately, the advantage of C code being instrumentable does > also come around to bite me... Is there any interest from anybody in spinning a proper patch out of this? Shaokun? Will > /* Looks dumb, but generates nice-ish code */ > static u64 accumulate(u64 sum, u64 data) > { > __uint128_t tmp = (__uint128_t)sum + data; > return tmp + (tmp >> 64); > } > > unsigned int do_csum_c(const unsigned char *buff, int len) > { > unsigned int offset, shift, sum, count; > u64 data, *ptr; > u64 sum64 = 0; > > offset = (unsigned long)buff & 0x7; > /* > * This is to all intents and purposes safe, since rounding down cannot > * result in a different page or cache line being accessed, and @buff > * should absolutely not be pointing to anything read-sensitive. > * It does, however, piss off KASAN... > */ > ptr = (u64 *)(buff - offset); > shift = offset * 8; > > /* > * Head: zero out any excess leading bytes. Shifting back by the same > * amount should be at least as fast as any other way of handling the > * odd/even alignment, and means we can ignore it until the very end. > */ > data = *ptr++; > #ifdef __LITTLE_ENDIAN > data = (data >> shift) << shift; > #else > data = (data << shift) >> shift; > #endif > count = 8 - offset; > > /* Body: straightforward aligned loads from here on... */ > //TODO: fancy stuff with larger strides and uint128s? > while(len > count) { > sum64 = accumulate(sum64, data); > data = *ptr++; > count += 8; > } > /* > * Tail: zero any over-read bytes similarly to the head, again > * preserving odd/even alignment. > */ > shift = (count - len) * 8; > #ifdef __LITTLE_ENDIAN > data = (data << shift) >> shift; > #else > data = (data >> shift) << shift; > #endif > sum64 = accumulate(sum64, data); > > /* Finally, folding */ > sum64 += (sum64 >> 32) | (sum64 << 32); > sum = sum64 >> 32; > sum += (sum >> 16) | (sum << 16); > if (offset & 1) > return (u16)swab32(sum); > > return sum >> 16; > } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel