Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp312126pxb; Wed, 27 Oct 2021 03:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxauhRdCMnJmFFszX7+aRmpQkrSKfXfGwbP0i3M1ZZNTymhOn0MG9cPJv7XCbbNek+V6QJl X-Received: by 2002:a62:445:0:b0:44c:3b5b:f680 with SMTP id 66-20020a620445000000b0044c3b5bf680mr32351230pfe.30.1635330681787; Wed, 27 Oct 2021 03:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635330681; cv=none; d=google.com; s=arc-20160816; b=PAYowKwQtiyRtOAPJ7uYGUDjABZ0T1P3i1qE3XgmHbXzGpflDmVXZ/eButEbTDYa4Y bIJXCYorNlKY8EZhkRLhTmj9qzgkCwoirZcyG7eF8gbJ+1tMCNjdvQhyhAqU9zsZCu8u rY+HRC6ohkErl4A2iQCcCPqokJM4utF/puQ14rhlkiS81xEbtFnGNAE8yZ1/E2phOPl7 MiAMV6SrGTGkqmpbLmeYJpEMZKS3V7J+yDlYX5Y9ppuXE6z04t03Py+uYC4kWwO6Hxf4 3lVlTF9QgOUDGWmuFNPBkUyxl0xd9j28bh+aSfFM0O2vM2eqo61i/bJu9h9TgAoP+Y72 0/+A== 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=CIiIJFd9JT6RJ463A7d/voc32nI7QyUcZFha6esrkKE=; b=eNCKg8IbWJ2JfHLPbcL/awV8VrLAUGO75zVKxCBkpSS18g1+GNGwejQHWA4MjKBFL3 3zzECAqDQs2uL8A7Yi96CpSnxvCd4TF73uVosLnVXM6jdh9jf9ayTpzyreb6A6thVh2z lMm4l7k+D1IJ7D3IrlXeflGEvkc/LZJ36cSu2xSwNlZ0WZz8G1wZVRKkrsumij6a1YzQ PflafFuvnHOXnPenAVbNWncqT2ncfmS11sUtFAsf2AC0U+iWmbylbcVHwf1N1FfWWi3g vFj5C8cpZylGdsGAYpfdv8y+vitIk5YyaSNHDzk+Q3xlfbiQc7fE5wW1FqeqJLdovHN2 2I8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l16si12112129pfu.252.2021.10.27.03.31.04; Wed, 27 Oct 2021 03:31:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237009AbhJZVHY convert rfc822-to-8bit (ORCPT + 99 others); Tue, 26 Oct 2021 17:07:24 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:38329 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235594AbhJZVHX (ORCPT ); Tue, 26 Oct 2021 17:07:23 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-59-nuyPE1CKP524lUkKQActcw-1; Tue, 26 Oct 2021 22:04:56 +0100 X-MC-Unique: nuyPE1CKP524lUkKQActcw-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.24; Tue, 26 Oct 2021 22:04:55 +0100 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.024; Tue, 26 Oct 2021 22:04:55 +0100 From: David Laight To: 'Nathan Chancellor' CC: 'Nick Terrell' , Nick Desaulniers , "linux-kernel@vger.kernel.org" , "llvm@lists.linux.dev" Subject: RE: [PATCH] lib: zstd: Add cast to silence clang's -Wbitwise-instead-of-logical Thread-Topic: [PATCH] lib: zstd: Add cast to silence clang's -Wbitwise-instead-of-logical Thread-Index: AQHXxrmhV8EJKX2UAE+nrwZQNmVvMavkgQmAgACZsECAACtYgIAAgqUg Date: Tue, 26 Oct 2021 21:04:55 +0000 Message-ID: <2c664a6701b44050a0525b541292ce21@AcuMS.aculab.com> References: <20211021202353.2356400-1-nathan@kernel.org> <4245BD7A-4B12-4172-B4EE-76A99C717C7D@fb.com> In-Reply-To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nathan Chancellor > Sent: 26 October 2021 15:03 ... > > Isn't enabling that warning completely stupid? > > The casts required to silence it could easily cause more problems > > - by hiding more important bugs. And seriously affect code readability. > > Which warning? > > -Wbitwise-instead-of-logical is included in clang's -Wall and I do not > think it should be disabled; this is the first instance of the warning > that has been silenced with a cast. I'm not sure about that one. I have a feeling it will generate false positives for carefully optimised code more often that it finds anything where 'short circuiting' will be a real gain. Especially for values with are known to be either 0 or 1. > -Wshorten-64-to-32 will never be enabled for Linux but zstd is a > separate project that can be built for a variety of operating systems so > that has to be considered when developing changes for the kernel because > the kernel changes need to go upstream eventually if they touch core > zstd code, otherwise they will just get blown away on the next import. > Specifically, this warning was enabled on iOS: > https://github.com/facebook/zstd/pull/2062 That one... If you are going to enable it, then you need a static inline function to convert u64 to u32, not a C cast. I'm sure that it won't be long before the compiler writes start an 'open season' on casts. They really are more dangerous than the warnings they are trying to remove. > > ...c > > > > index 05570ed5f8be..5105e59ac04a 100644 > > > > --- a/lib/zstd/decompress/huf_decompress.c > > > > +++ b/lib/zstd/decompress/huf_decompress.c > > > > @@ -886,7 +886,7 @@ HUF_decompress4X2_usingDTable_internal_body( > > > > HUF_DECODE_SYMBOLX2_0(op2, &bitD2); > > > > HUF_DECODE_SYMBOLX2_0(op3, &bitD3); > > > > HUF_DECODE_SYMBOLX2_0(op4, &bitD4); > > > > - endSignal = (U32)LIKELY( > > > > + endSignal = (U32)LIKELY((U32) > > > > (BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished) > > > > & (BIT_reloadDStreamFast(&bitD2) == BIT_DStream_unfinished) > > > > & (BIT_reloadDStreamFast(&bitD3) == BIT_DStream_unfinished) > > > > Isn't that the same as: > > ((BIT_reload() & BIT_reload() & BIT_reload()) == BIT_DStream_unfinished) > > which will generate much better code. > > Especially on cpu without 'seteq' instructions. > > I don't think so. Feel free to double check my math. > > BIT_reloadDStreamFast() can return either BIT_DStream_unfinished (0) or > BIT_DStream_overflow (3).... Ah, I'd assumed that BIT_DStream_unfinished was non-zero. So you actually want: endSignal = !(BIT() | BIT() | BIT()); Just kill the CaMeLs and unnecessary constants. Then the code becomes succint, easier to read/check etc. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)