220 35596 <CAHSYqdYu3qrNMfKXGAosv8p1rq3wxxYSNQ4bpdiyWP4SxFVZKA@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Hyman Rosen <hyman.rosen@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Rotational shift operator
Date: Wed, 29 Nov 2017 12:17:35 -0500
Lines: 123
Approved: news@gmane.org
Message-ID: <CAHSYqdYu3qrNMfKXGAosv8p1rq3wxxYSNQ4bpdiyWP4SxFVZKA@mail.gmail.com>
References: <69593098-e2cc-487e-bd14-9001b27aa7c1@isocpp.org>
 <CAHSYqda2VTVT4Qid7GC9vzPxEKSDdmHxC9QR7EEoBtxzU6OZSQ@mail.gmail.com>
 <6888287.JoKhHhR3xM@tjmaciei-mobl1> <3058817.kvbDme98ge@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="001a114b3de205e780055f225175"
X-Trace: blaine.gmane.org 1511975880 29839 195.159.176.226 (29 Nov 2017 17:18:00 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 29 Nov 2017 17:18:00 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDKJJPVBQMKRBROX7PIAKGQEQJGUL6Y@isocpp.org Wed Nov 29 18:17:52 2017
Return-path: <std-proposals+bncBDKJJPVBQMKRBROX7PIAKGQEQJGUL6Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f199.google.com ([209.85.128.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDKJJPVBQMKRBROX7PIAKGQEQJGUL6Y@isocpp.org>)
	id 1eK5zb-0007GU-82
	for gclcip-std-proposals@m.gmane.org; Wed, 29 Nov 2017 18:17:51 +0100
Original-Received: by mail-wr0-f199.google.com with SMTP id m6sf928147wrf.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 29 Nov 2017 09:17:58 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1511975878; cv=pass;
        d=google.com; s=arc-20160816;
        b=r1vl+4G8SlS8ER9iAozWGcYv+DUtWPt4HJVWELQ6nbxPMo7SgVg/O9ML+MsTNTkgq6
         zlaR6+pkrihLlepgDdZKjNssv3gBBolANWJ+tboYNODmBMb8eljQ48qSOgyir2/l/Qp+
         j3yUkeOZsT6wwn2Vdn3oThPPNPW+5j5ojAgthRnpKwFC0tofp5c7yVCgabTvpSof3cSZ
         vw7ATbmSfFnuPqhzO/w33iUoNegu+XmYsxESx0hH4A3LfQArIKv57NX5adMOXVLV8aQf
         wepdvaD7kYHWQPKBFEaov0aC1s+RE0PvaInGFHG9Ns0eayekxLu8S2tB+MxfLWr/UqjJ
         bcNg==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date
         :from:references:in-reply-to:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=kacG3WAQJCpJch4uBtghVQtzDILS6BjUAjP1cSHxpuw=;
        b=DY47cv6opfnukNrIY78+DRqxv/FtdKT91DjUz9j6/8emLL8dp16dRUS91PyGO6Y6Gl
         uzkbmHyG+YzI4lCnFuBA+ZLfN7vVnvCoVnMpurq/EKvAhmZ1chfQcYunI7Qxcns7Rc7i
         8seVFfdofOkya4v+W6LHqEm+Y0LY12THVvLUfIG6/nfEEAyXAZD3QzaMQbCLjl8/Z8f8
         CyvAsvysqw+S+aojex35J7HAKxjTJZtzwiYt8kHMmxcbwuDRDgP3C+nLaBcgjVC1NSeL
         +l99oXsAPXf106C3U1EZKt8s9/kCyKNjk7n6PmhtWuWzNPYtxnpQjMTUibVRAqXvPlF7
         7eZg==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=AzOkfopY;
       spf=pass (google.com: domain of hyman.rosen@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=hyman.rosen@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=kacG3WAQJCpJch4uBtghVQtzDILS6BjUAjP1cSHxpuw=;
        b=fFKHL7ioTmveRPKDSe2pOCBOpDAEtYQwsRKvxwZJG7ts4Oc6MdSPYUp1ovFPxk15Bc
         kpIjDhmwKwsMc6CBm0RMPSyOqqqlkA++aQlTF+RyoxWx2pGrTm5+taWnY5ci2XyLrKbf
         Kw6efRwjZSAgCCQ9+t6++WZXwcSUHB6OOwXZh8HwKI7KVWNRdRxr3MqlDPN6U3XlRUwj
         cZ1Kga34YsThLyMl2s3TGicSl7/GQRcyK/rr5jUDVP3KTZRkoRPte1oyPgFvzifmQ014
         KbJw9m0kcxMxyLnodMnh2AzY0kzulyIJtNoP4b1TyIV5Af5HhcdnNaGtnX1H7RxZXcU+
         hSwA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=kacG3WAQJCpJch4uBtghVQtzDILS6BjUAjP1cSHxpuw=;
        b=UHiMYxfQFnvGTN3EI+EysCg36BqZC0ulIPjTpif0qpkCNKF6gRyXwEs4d0Nxs07b7P
         iyW1zOBeuOW2gmbie1TpCQTw/exbS7iQx+UBGNUxBH1fbnBWeFXx3fQ+B/gEzX5yAnEt
         yP+u9E4jgMe2b3v0U9Qok90GLcpYyjybc3peas1oI8va3wTN5ip/QUZydp3zW5g6oTWi
         xB9ND2rRMCtvOjg3Vryq0Tk37TpzSQKIf2f6jhCEnOdZBq2K5cqqKqoXiKk0pCUI4vfT
         NEm8NfFQJ6boRqO2qmFwc1S9KpcbBR4HLb7NBIw5aYqNMKY1HZ1ztQGimBjZy0rUgIcb
         ybrg==
X-Gm-Message-State: AJaThX4AfNYp6IRwdYvlDqht8dH/l+zEpDXX5JMAcam0qJME6Rj3Wz7H
	HdYp8hAuaMJHCWOlG7+7V/ux5w==
X-Google-Smtp-Source: AGs4zMaSirkmjP3zJbVf5IEbPaW+h8PipHZzyMuLrgB2+5tFBbMr2FBRDfrQ/uugVuQAgbIYHIMvlw==
X-Received: by 10.28.207.1 with SMTP id f1mr614583wmg.11.1511975878629;
        Wed, 29 Nov 2017 09:17:58 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.209.78 with SMTP id i75ls299141wmg.0.gmail; Wed, 29 Nov
 2017 09:17:57 -0800 (PST)
X-Received: by 10.28.191.132 with SMTP id o4mr3359497wmi.157.1511975877031;
        Wed, 29 Nov 2017 09:17:57 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1511975877; cv=none;
        d=google.com; s=arc-20160816;
        b=r4Vd0qkwBrOdoNc/aIK/Gd4wf52RCJ6ystRo4cYrSY2/8upv6XVDIS/Kss4Ktyh8kn
         LCM1KxlolNe8E/ucA8yeeU6N8vRKj/3REuQPAbnc72jXRI3RUtJ62x7XSxPf6eAFJFxn
         j11zJt2ZgFUYvF2nt6OC3YjU/azIkDGkgF3/ngFln+TKBzaxsRMBGkedmI2JL9x0czC6
         IRvoM1vWYA2AoHRlzgVaexDDZg9HIQuqjvsElDiwKQVlLsXBXaLvemiDNvIzdLOeSPAr
         GY+tRozx1Fz3e6w+JmQcm7vkhRKOi9MFCDpvh+mioYZBhFzf1SmeNUHlel5J9nuh2QXZ
         X+Fg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:references:in-reply-to:mime-version
         :dkim-signature:arc-authentication-results;
        bh=JmRVVDWQ4YIsACkGZXC7ZjZOl0vqeOcBP2XUUexlWcc=;
        b=U1NrJghoqtw7s+I4E5isJMWPEwih94lOy1thnfTb2OGAIkEeUkFupqR+XLH9lujlFC
         GGI9Z5orc1pMNU3xfbOSCB1oLfVsaEnPC0eF16HdKDN7jH61MtSWYJj+3dAWnOzDKbM5
         QPBdk+3UkOqEBpRhc7/KdIt78isw1Hf0O9zRGMwi/uFBX9HWqWZ667A3PHB4urpTJN1g
         pRGFPN03fOw/eBxnrsPgylTxzPfIB217PDlBvLwIhWG6ePbmpnjkOb4QuHVVqZQXJo5K
         XUzuJQgUfI9y86AZ8W1PeKzCaN1nFGPPtwt3Tm7pDUigxUXsDHzVbdEw3GL6tiJwWU8J
         ZQpQ==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=AzOkfopY;
       spf=pass (google.com: domain of hyman.rosen@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=hyman.rosen@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id 31sor970558wri.44.2017.11.29.09.17.57
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Wed, 29 Nov 2017 09:17:57 -0800 (PST)
Received-SPF: pass (google.com: domain of hyman.rosen@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 10.223.130.17 with SMTP id 17mr3263709wrb.131.1511975876420;
 Wed, 29 Nov 2017 09:17:56 -0800 (PST)
Original-Received: by 10.28.57.214 with HTTP; Wed, 29 Nov 2017 09:17:35 -0800 (PST)
In-Reply-To: <3058817.kvbDme98ge@tjmaciei-mobl1>
X-Original-Sender: hyman.rosen@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=AzOkfopY;       spf=pass
 (google.com: domain of hyman.rosen@gmail.com designates 209.85.220.41 as
 permitted sender) smtp.mailfrom=hyman.rosen@gmail.com;       dmarc=pass
 (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:35596
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35596>

--001a114b3de205e780055f225175
Content-Type: text/plain; charset="UTF-8"

On Tue, Nov 28, 2017 at 8:33 PM, Thiago Macieira <thiago@macieira.org>
wrote:
>
> > What should, according to you, the following produce:
> >
> >         1U << functionThatReturns33();
> >
> > Please answer bearing in mind that the SHL operation in assembly is only
> > specified to work with values less than 32. Any higher value may shift
> > everything, nothing, or shift by the modulo 32.
>
> Please answer in two cases:
>
>  1) regular context, the compiler could not inline functionThatReturns33()
>
>  2) constant expression context, the compiler can inline and did constant
> propagation


First of all, there is no reason for the behavior to be undefined rather
than
unspecified, unless there are platforms where doing such shifts causes traps
in a way that would be unnatural to prevent.

The value should be whatever the naive assembly language shift instruction
generates with such a count.  On Intel platforms beyond the 8086, for
example,
it is specified that the processor masks the shift count with 5 or 6 bits
depending
on whether the shift is of a 32-bit or 64-bit value, so the shift is done
modulo the
bit size - shifting a 32-bit value by 32 leaves the value unchanged.
<
https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf
>

If the compiler can detect that the shift size is such a too-large value,
it should
issue a warning, because it is unlikely that the programmer intended the
behavior,
but the code that it generates should be as-if the naive shift were
executed.

In all cases, the result of const expressions, constexpr expressions, and
preprocessor expressions should match the results that would obtain if the
expressions were to be evaluated at runtime.

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdYu3qrNMfKXGAosv8p1rq3wxxYSNQ4bpdiyWP4SxFVZKA%40mail.gmail.com.

--001a114b3de205e780055f225175
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Nov 28, 2017 at 8:33 PM, Thiago Macieira <span dir=3D"ltr">&lt;<a href=
=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@macieira.org</a>&g=
t;</span> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0=
px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span cla=
ss=3D"gmail-">
&gt; What should, according to you, the following produce:<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A01U &lt;&lt; functionThatReturns33();<=
br>
&gt;<br>
&gt; Please answer bearing in mind that the SHL operation in assembly is on=
ly<br>
&gt; specified to work with values less than 32. Any higher value may shift=
<br>
&gt; everything, nothing, or shift by the modulo 32.<br>
<br>
</span>Please answer in two cases:<br>
<br>
=C2=A01) regular context, the compiler could not inline functionThatReturns=
33()<br>
<br>
=C2=A02) constant expression context, the compiler can inline and did const=
ant<br>
propagation</blockquote><div><br>First of all, there is no reason for the b=
ehavior to be undefined rather than<br>unspecified, unless there are platfo=
rms where doing such shifts causes traps<br>in a way that would be unnatura=
l to prevent.<br><br>The value should be whatever the naive assembly langua=
ge shift instruction<br>generates with such a count.=C2=A0 On Intel platfor=
ms beyond the 8086, for example,<br>it is specified that the processor mask=
s the shift count with 5 or 6 bits depending<br>on whether the shift is of =
a 32-bit or 64-bit value, so the shift is done modulo the<br>bit size - shi=
fting a 32-bit value by 32 leaves the value unchanged.<br>&lt;<a href=3D"ht=
tps://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32=
-architectures-software-developer-instruction-set-reference-manual-325383.p=
df">https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64=
-ia-32-architectures-software-developer-instruction-set-reference-manual-32=
5383.pdf</a>&gt;<br><br>If the compiler can detect that the shift size is s=
uch a too-large value, it should<br>issue a warning, because it is unlikely=
 that the programmer intended the behavior,<br>but the code that it generat=
es should be as-if the naive shift were executed.<br><br>In all cases, the =
result of const expressions, constexpr expressions, and<br>preprocessor exp=
ressions=C2=A0should match the results that would obtain if the<br>expressi=
ons were to be evaluated at runtime.</div></div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAHSYqdYu3qrNMfKXGAosv8p1rq3wxxYSNQ4b=
pdiyWP4SxFVZKA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdYu3qrNMfKX=
GAosv8p1rq3wxxYSNQ4bpdiyWP4SxFVZKA%40mail.gmail.com</a>.<br />

--001a114b3de205e780055f225175--

.
