Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5935709pxb; Mon, 14 Feb 2022 11:06:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8ZTBe1b7n2iIdEobx1GIFEcJxAnb4ACDKLjx9iyNGfJiLBPMvZl2geTY9nmkGYcm16QfZ X-Received: by 2002:a63:4422:: with SMTP id r34mr368895pga.275.1644865605075; Mon, 14 Feb 2022 11:06:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644865605; cv=none; d=google.com; s=arc-20160816; b=AMqpOl8MNiboWFJuO1pPcwUTNWdsR5XRJt2qvv0tgcDpdNTdeGxVv7vB1dH6MuhoFg oAyYd523cMFjJICOqBtnJ0Afa1qMO5flGVHSUXRrbwfvuCnqDZc+/2AXkQ92mrs9LYR6 BMtQzWeFBSN4SPlG5JxADNT0vrsdenCOzL3TFXOnHe2nBPx6KWyL2lmx1rK8lXwtSvgh joA26zw4mXzO6aE6p0fsj0Jn3nH1kdy7WX9Yya8V918oJ7vlDp6pnPec+ORb+45Jmzl5 8wSd4ZqgYXobO2CMVHBGyZcgmDRzo9ZfwgZrYkI+py30HvrSLx4dUYygJ0qr6VgZRYLq 2qeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=pjtdbEbNwYfwRA6dnf8vsI+LSvlYpkxJ4rRGcagriFk=; b=uCfW67diTUa7I7zaDlXuInskaU9JPcXjWF7hwhOaI7KcgdfzHzNTeweizLxRlw/IT1 RmL2QvloH0OnQn7JdyCT8vgS5VJcC1+Y0TsHkmOX+pO7Kb81Yyx5aFPXCvSQ9AzPfhM9 XzSmodiy385jkDtjFDZKiJua34Jxwt0CDPtwMcMxwF/eXeVl7DGQKVIVCiFWiGIFfGWF CXbUPe0XtPWIdOVpaE08ew0OZ39k5oY9+ox4uDtKRJoghaktt1cn8EnAbNXVw/xj4+g+ HJtGfzG3ok4sQTGDsBugSl6m+duEj43XKEItYwI+DacTCDMayesD+9ucXGmfGLMeRSJN CnyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e8si449263pgn.715.2022.02.14.11.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 11:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CCD071D0C2; Mon, 14 Feb 2022 11:02:59 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbiBMRsF convert rfc822-to-8bit (ORCPT + 99 others); Sun, 13 Feb 2022 12:48:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbiBMRsE (ORCPT ); Sun, 13 Feb 2022 12:48:04 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A30F25A098 for ; Sun, 13 Feb 2022 09:47:57 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-186-LeVe8n1APwumlclMeJaqYQ-1; Sun, 13 Feb 2022 17:47:54 +0000 X-MC-Unique: LeVe8n1APwumlclMeJaqYQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Sun, 13 Feb 2022 17:47:52 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Sun, 13 Feb 2022 17:47:52 +0000 From: David Laight To: 'Segher Boessenkool' CC: 'Christophe Leroy' , "David S. Miller" , Jakub Kicinski , "netdev@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] net: Remove branch in csum_shift() Thread-Topic: [PATCH] net: Remove branch in csum_shift() Thread-Index: AQHYHyQqmTo4K/pb5UWdDmTfE7rfRayQxWFwgABxD4CAAIxicA== Date: Sun, 13 Feb 2022 17:47:52 +0000 Message-ID: <476aa649389345db92f86e9103a848be@AcuMS.aculab.com> References: <7f16910a8f63475dae012ef5135f41d1@AcuMS.aculab.com> <20220213091619.GY614@gate.crashing.org> In-Reply-To: <20220213091619.GY614@gate.crashing.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Segher Boessenkool > Sent: 13 February 2022 09:16 .... > > > What happens on x86-64? > > > > Trying to do the same in the x86 ipcsum code tended to make the code worse. > > (Although that test is for an odd length fragment and can just be removed.) > > In an ideal world the compiler could choose the optimal code sequences > everywhere. But that won't ever happen, the search space is way too > big. So compilers just use heuristics, not exhaustive search like > superopt does. There is a middle way of course, something with directed > searches, and maybe in a few decades systems will be fast enough. Until > then we will very often see code that is 10% slower and 30% bigger than > necessary. A single insn more than needed isn't so bad :-) But it can be a lot more than that. > Making things branch-free is very much worth it here though! I tried to find out where 'here' is. I can't get godbolt to generate anything like that object code for a call to csum_shift(). I can't actually get it to issue a rotate (x86 of ppc). I think it is only a single instruction because the compiler has saved 'offset & 1' much earlier instead of doing testing 'offset & 1' just prior to the conditional. It certainly has a nasty habit of doing that pessimisation. So while it helps a specific call site it may be much worse in general. I also suspect that the addc/addze pair could be removed by passing the old checksum into csum_partial. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)