From: Bart Van Assche <bvanassche@acm.org>
To: dgilbert@interlog.com, Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Christoph Hellwig <hch@lst.de>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Subject: Re: [PATCH 4/9] drivers/iio: Sign extend without triggering implementation-defined behavior
Date: Thu, 31 Oct 2019 10:55:09 -0700 [thread overview]
Message-ID: <a5863854-037d-55d5-69c8-ae15aa4a861a@acm.org> (raw)
In-Reply-To: <bc4941a9-25f0-c931-61f1-b4f96c4bdff9@interlog.com>
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.
next prev parent reply other threads:[~2019-10-31 17:55 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-28 20:06 [PATCH 0/9] Consolidate {get,put}_unaligned_[bl]e24() definitions Bart Van Assche
2019-10-28 20:06 ` [PATCH 1/9] linux/unaligned/byteshift.h: Remove superfluous casts Bart Van Assche
2019-10-28 20:06 ` [PATCH 2/9] c6x: Include <linux/unaligned/generic.h> instead of duplicating it Bart Van Assche
2019-11-07 3:09 ` Bart Van Assche
2019-11-07 13:54 ` Mark Salter
2019-10-28 20:06 ` [PATCH 3/9] treewide: Consolidate {get,put}_unaligned_[bl]e24() definitions Bart Van Assche
2019-10-28 20:06 ` [PATCH 4/9] drivers/iio: Sign extend without triggering implementation-defined behavior Bart Van Assche
2019-10-30 19:43 ` Jonathan Cameron
2019-10-30 20:02 ` Peter Zijlstra
2019-10-30 22:13 ` Douglas Gilbert
2019-10-31 17:55 ` Bart Van Assche [this message]
2019-10-28 20:06 ` [PATCH 5/9] scsi/st: Use get_unaligned_signed_be24() Bart Van Assche
2019-10-28 20:06 ` [PATCH 6/9] scsi/trace: Use get_unaligned_be*() Bart Van Assche
2019-10-28 20:06 ` [PATCH 7/9] arm/ecard: Use get_unaligned_le{16,24}() Bart Van Assche
2019-10-28 20:06 ` [PATCH 8/9] IB/qib: Sign extend without triggering implementation-defined behavior Bart Van Assche
2019-10-28 20:07 ` [PATCH 9/9] ASoC/fsl_spdif: Use put_unaligned_be24() instead of open-coding it Bart Van Assche
2019-10-28 20:24 ` Mark Brown
2019-10-28 20:49 ` Bart Van Assche
2019-10-28 21:52 ` [PATCH 0/9] Consolidate {get,put}_unaligned_[bl]e24() definitions Peter Zijlstra
2019-10-28 22:02 ` Bart Van Assche
2019-10-29 1:10 ` Douglas Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a5863854-037d-55d5-69c8-ae15aa4a861a@acm.org \
--to=bvanassche@acm.org \
--cc=dgilbert@interlog.com \
--cc=hch@lst.de \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=pmeerw@pmeerw.net \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).