Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4543097rdb; Fri, 15 Sep 2023 05:40:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFrTluN9l39wAMvoDioKyN/qX62j5vKjMEbmuhfeAkpILFSIKHdAaESEK7Yt0yxEyPUEu1y X-Received: by 2002:a05:6870:391f:b0:1d5:5d44:7404 with SMTP id b31-20020a056870391f00b001d55d447404mr1638348oap.43.1694781642541; Fri, 15 Sep 2023 05:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694781642; cv=none; d=google.com; s=arc-20160816; b=qOsMYPpXpouoPuweL/5WgTbes/i9xoDFa4I8asSJD1frTCqBKBhaAus2ancCjSKtXW QCNnv9RM+ljIBH/JG6cv9cCpZOyKY1+G85GMdyvCDwt4MUuwkaqL3dJNAIVFli/vQ0Tb dWSdXWvzCGe/QCotDNM5dh+TAOc0czDUc1WNMoCDHFzrizL+PxaTZdlttnwj2Ar7sT2Z hnzugyWNpcSaQpWJ/v7owAb0IOgUPigX/rwhkqq/gyMTbZZsJKs66NRUk9t/K4SLSeC+ 6O3QQflVDKVULRTbU3iAWBkCWpoRKoLgfOezpqRVDBXvJUPxouKTwORbOi65pFpj89Im BpTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:mime-version :references:in-reply-to:from:dkim-signature; bh=CePvDk/TxgBw6w90UlCCAlVR7GMFDlWsOITzDbSZkZE=; fh=gOzr2J2/AaC/1DdOEiJ/vMVIpQG7VS7WGUZu6JUmCr4=; b=XVz2Soo1zD9IA4p9lW+gZmYP5CrEknhBYF9f6KZ2Jtr94B6uZWc0LKXXRnmmqhBseF L6pGkhTE69GHOcsu5tLQn8nmFA3QNyR1Ovx0i31oe9QDG8MtDS31SwJV5Z2DtO4wYUA7 f/VG7fvq13hrDWtwhXFELctsNSbS7HZeieni74Fx1sxOHuBTrelNkTRgyi3ixpr4VHuf 76sDatTulRI9V47irzl29EwWSRevJ26bkEA1daA4s4R11mNGotdEjAqvMXPx6Yylc4mn NHibo7hOjcY+mery/bAsoXgSwq9EUIQe6Jxm0U01Y7EecJwIszbhq2mMOtoST4x9w3xQ 3fkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=KSqcbl2G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id l62-20020a639141000000b00565bcc15ee2si3224004pge.815.2023.09.15.05.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:40:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=KSqcbl2G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id CEC2983D7C91; Fri, 15 Sep 2023 03:10:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234131AbjIOKKC (ORCPT + 99 others); Fri, 15 Sep 2023 06:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234160AbjIOKKA (ORCPT ); Fri, 15 Sep 2023 06:10:00 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40F6A3591 for ; Fri, 15 Sep 2023 03:07:45 -0700 (PDT) Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id D04503F67C for ; Fri, 15 Sep 2023 10:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1694772463; bh=CePvDk/TxgBw6w90UlCCAlVR7GMFDlWsOITzDbSZkZE=; h=From:In-Reply-To:References:Mime-Version:Date:Message-ID:Subject: To:Cc:Content-Type; b=KSqcbl2GquNamS8ZyHjLk+kK0OmTqqRvi0VeHrfPBosU8wrYYdR3rEhaAy/sI1tST q49Drx9jb1aZo04a+FvlCj5/+ZWcBLFwVQ7sgk0QxE+RzJqPol3IUCMJY56swmuEHz lnBMCTTjYuwqCnusdQAGJMsWmHmiKg18A9VIUxtTKaeGwnHmQqFz8eO0cDSJ9l0EB/ a39NJJBX8N5W5leKm4thzEIjiYZLwUoHYuaqm4jtdz8io+dlcY1wfoa7A0mEMrvkks x7a0gmWcAz0I0NccjnSZaX+g7HeyYCY3i6fKicHk48p+qFqdcSJ7p9seUB4NExRHeK hjF66zkT/eOZA== Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-412136f4706so20117881cf.0 for ; Fri, 15 Sep 2023 03:07:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694772460; x=1695377260; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CePvDk/TxgBw6w90UlCCAlVR7GMFDlWsOITzDbSZkZE=; b=qNt+U9aWvC0PYKpoXJZ6tCdVTNrsuIZz27lXbwPNWtWU6tKnHwKZrQz3gSqL4R0CB4 szwiqjB/M+ZrN1w4OMUNWAX0XY2G4sOwnqzW8RtXTTK6A6lHaB0JCQtHV+RHGtG1xJLo UrRhDUUEvx/7Deb1VZD6uK3JcDCQ+CCG3lsfjNhI5cqaPP9eTjClBCf5DaS3ddPJa3oM YSJkdgd2hPdFqp6glXLha6c4gB7lZPjdgHT3NFMMQwYJ/IWfhpOhWKAUcLr4StcVjWdX Sd3PGUzqbasVqjssgIdkrafes2OsaUbcF9PsLOCVJIQMv1hchU8uZ4qjFEC8zU/5FxcF k+JQ== X-Gm-Message-State: AOJu0YzuBD+i+MIqoNsN6OZxQGGQtxAV9Dz3YLT0QXqZkg7j74dV8IqZ MRnuV+l8MRi7m6Afqev2/EQpAHYJscNdqbjfILbFedzdIFdimSig/WJgeL0k0G9R6y2ka+TpGTV SIN5pB//57j4+nAt4DZdMmIgmSOQvvdwcgZiAF/kgT4L1+NiPzHNe7j89Pw== X-Received: by 2002:ac8:59ca:0:b0:412:1ba6:32af with SMTP id f10-20020ac859ca000000b004121ba632afmr1121511qtf.19.1694772460112; Fri, 15 Sep 2023 03:07:40 -0700 (PDT) X-Received: by 2002:ac8:59ca:0:b0:412:1ba6:32af with SMTP id f10-20020ac859ca000000b004121ba632afmr1121495qtf.19.1694772459877; Fri, 15 Sep 2023 03:07:39 -0700 (PDT) Received: from 348282803490 named unknown by gmailapi.google.com with HTTPREST; Fri, 15 Sep 2023 03:07:39 -0700 From: Emil Renner Berthing In-Reply-To: <20230914-optimize_checksum-v5-2-c95b82a2757e@rivosinc.com> References: <20230914-optimize_checksum-v5-0-c95b82a2757e@rivosinc.com> <20230914-optimize_checksum-v5-2-c95b82a2757e@rivosinc.com> Mime-Version: 1.0 Date: Fri, 15 Sep 2023 03:07:39 -0700 Message-ID: Subject: Re: [PATCH v5 2/4] riscv: Checksum header To: Charlie Jenkins , Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Paul Walmsley , Albert Ou Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 15 Sep 2023 03:10:03 -0700 (PDT) Charlie Jenkins wrote: > Provide checksum algorithms that have been designed to leverage riscv > instructions such as rotate. In 64-bit, can take advantage of the larger > register to avoid some overflow checking. > > Signed-off-by: Charlie Jenkins > --- > arch/riscv/include/asm/checksum.h | 79 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 79 insertions(+) > > diff --git a/arch/riscv/include/asm/checksum.h b/arch/riscv/include/asm/checksum.h > new file mode 100644 > index 000000000000..2f0f224682bd > --- /dev/null > +++ b/arch/riscv/include/asm/checksum.h > @@ -0,0 +1,79 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * IP checksum routines > + * > + * Copyright (C) 2023 Rivos Inc. > + */ > +#ifndef __ASM_RISCV_CHECKSUM_H > +#define __ASM_RISCV_CHECKSUM_H > + > +#include > +#include > + > +#define ip_fast_csum ip_fast_csum > + > +#include > + > +/* > + * Quickly compute an IP checksum with the assumption that IPv4 headers will > + * always be in multiples of 32-bits, and have an ihl of at least 5. > + * @ihl is the number of 32 bit segments and must be greater than or equal to 5. > + * @iph is assumed to be word aligned. > + */ > +static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) > +{ > + unsigned long csum = 0; > + int pos = 0; > + > + do { > + csum += ((const unsigned int *)iph)[pos]; > + if (IS_ENABLED(CONFIG_32BIT)) > + csum += csum < ((const unsigned int *)iph)[pos]; > + } while (++pos < ihl); > + > + /* > + * ZBB only saves three instructions on 32-bit and five on 64-bit so not > + * worth checking if supported without Alternatives. > + */ > + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && > + IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { > + unsigned long fold_temp; > + > + asm_volatile_goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, > + RISCV_ISA_EXT_ZBB, 1) > + : > + : > + : > + : no_zbb); > + > + if (IS_ENABLED(CONFIG_32BIT)) { > + asm(".option push \n\ > + .option arch,+zbb \n\ > + not %[fold_temp], %[csum] \n\ > + rori %[csum], %[csum], 16 \n\ > + sub %[csum], %[fold_temp], %[csum] \n\ > + .option pop" > + : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp)); > + } else { > + asm(".option push \n\ > + .option arch,+zbb \n\ > + rori %[fold_temp], %[csum], 32 \n\ > + add %[csum], %[fold_temp], %[csum] \n\ > + srli %[csum], %[csum], 32 \n\ > + not %[fold_temp], %[csum] \n\ > + roriw %[csum], %[csum], 16 \n\ > + subw %[csum], %[fold_temp], %[csum] \n\ > + .option pop" > + : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp)); > + } > + return csum >> 16; > + } > +no_zbb: > +#ifndef CONFIG_32BIT > + csum += (csum >> 32) | (csum << 32); > + csum >>= 32; This indentation is still weird. > +#endif > + return csum_fold((__force __wsum)csum); > +} > + > +#endif // __ASM_RISCV_CHECKSUM_H > > -- > 2.42.0 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv