Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1465690ybx; Thu, 31 Oct 2019 10:59:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwatB5OtTsYNSwa5BIbgVTqccLq6sMdrEJ+0iWdhHmkKIPQepgQjl4ujrrK1RwTYU85Wym9 X-Received: by 2002:aa7:d714:: with SMTP id t20mr7886262edq.129.1572544765801; Thu, 31 Oct 2019 10:59:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572544765; cv=none; d=google.com; s=arc-20160816; b=u8B0sT4KWOXe4fAR0U1Lv7rPm8AE8blfbQOLkQkLLHvIjO6EpQYes6dMUFYbDnrfFt Vhanl6UfOJkFTMYg+lWOlyv5bg/Zol5zf3fJyfD0W++iUT0eow1vKSimNFcLr8aH9pkb mZm24DVnSvGcm+jVHyxtaU21Vf6QBlvSEIbMJ6rnwFil4nasVjivekkhgEGNpHR3alKE glp7ZdqF+DOL6admYeHU6+O3HGmiISM/kTlJ7W+AxLKFIlO8cqmcZmW1T3EcabNzU2zz cQszmcNmpXsCubUhUl3X8+3xUjdK1GYxEMny8uyHJWmKBFtALsUhcZYdeyVWNHvAJd8K lFdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=rfu7xisG1VzK9l1fM8rUWCXjY+Vu9qgC5rX7Api65YQ=; b=yhxbaclATICZbXqUr+gqCivoi3ecVohySbvVjCT1BlhR36+8VFJFbgAEj9H9xnfR4u tRB0gewgJmFSDpiLsH6WW1lpgto5sy/WLBT25Six6R2AuJQ/a+8v7Mps82d/nx6jwicA MTNORs2g9o8BpLyjAVQHiNP6zAkr1n5N/O7tZgqVRdye4QPuxGCsS7cmCGVmhdCPUh0P ZzkRdck7DHuJkYyASA2UB4c48cf3YKDQ1/0Gr9PtxnACrOJcfSOzQAGDkjrtFoWkj/PM F37Z5OlB3ypg36o5rh4K/TNdDOjNxffNbUlYieBFYby6mnxs4/AIwSSTNIW3UW8clTB0 AoNA== 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 w16si1735822eja.101.2019.10.31.10.59.02; Thu, 31 Oct 2019 10:59:25 -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 S1729181AbfJaRzM (ORCPT + 99 others); Thu, 31 Oct 2019 13:55:12 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33587 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726602AbfJaRzM (ORCPT ); Thu, 31 Oct 2019 13:55:12 -0400 Received: by mail-pl1-f196.google.com with SMTP id y8so3033636plk.0; Thu, 31 Oct 2019 10:55:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=rfu7xisG1VzK9l1fM8rUWCXjY+Vu9qgC5rX7Api65YQ=; b=sVLCWYoob04UbUMLPirKTHrvWcBOotdRwKhsfJWBQOvCSVnm6iEgVJdycxjh2EKLNH 4DunIVF1bBAbyrz+xtnpDu8O0/CR2BrimsKIaNsileWcLvDrsCNI3P6nR/uBmAzhjkqu bCDiYESXsHIS0eHtIj88B2eS4yjCRf26YEp9JrAVi4eAjAPIE+Vq9wwjgWiMhLWktpcS a9i1UXkEdoGbbia4FpkPjewNtmQoGx4aP7ikTrTJdxMl73/OHxKF/qR9+a4+xHxODcHb LJMOrXcN+ZdpSVkwOtXECVbzfCoEffRT/YQ6217RnJAe04azadxxGhSns1LrbvXKrdCl hNMQ== X-Gm-Message-State: APjAAAW/f6DRTLEnx+D4OeCVT3vxqCaIjUFzA0TtosPueKlLnmTOVUQS /s60eYkMwm3IzuNI39mXKX0= X-Received: by 2002:a17:902:b687:: with SMTP id c7mr7654265pls.52.1572544511272; Thu, 31 Oct 2019 10:55:11 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id 22sm3859912pfo.131.2019.10.31.10.55.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Oct 2019 10:55:10 -0700 (PDT) Subject: Re: [PATCH 4/9] drivers/iio: Sign extend without triggering implementation-defined behavior To: dgilbert@interlog.com, Peter Zijlstra Cc: Ingo Molnar , Thomas Gleixner , Christoph Hellwig , "Martin K . Petersen" , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler References: <20191028200700.213753-1-bvanassche@acm.org> <20191028200700.213753-5-bvanassche@acm.org> <20191030200232.GC3079@worktop.programming.kicks-ass.net> From: Bart Van Assche Message-ID: Date: Thu, 31 Oct 2019 10:55:09 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/30/19 3:13 PM, Douglas Gilbert wrote: > On 2019-10-30 4:02 p.m., Peter Zijlstra wrote: >> On Mon, Oct 28, 2019 at 01:06:55PM -0700, Bart Van Assche wrote: >>>  From the C standard: "The result of E1 >> E2 is E1 right-shifted E2 bit >>> positions. If E1 has an unsigned type or if E1 has a signed type and a >>> nonnegative value, the value of the result is the integral part of the >>> quotient of E1 / 2E2 . If E1 has a signed type and a negative value, the >>> resulting value is implementation-defined." >> >> FWIW, we actually hard rely on this implementation defined behaviour all >> over the kernel. See for example the generic sign_extend{32,64}() >> functions. >> >> AFAIR the only reason the C standard says this is implementation defined >> is because it wants to support daft things like 1s complement and >> saturating integers. > > See: >    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2218.htm > > That is in C++20 and on the agenda for C2x: >    https://gustedt.wordpress.com/2018/11/12/c2x/ Thanks Peter and Doug. This is very useful feedback. I will drop the sign_extend_24_to_32() function and use sign_extend32() instead. Bart.