220 37480 <2111ede0-62c6-4a41-8df3-f506d07f09f2@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Myriachan <myriachan@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allowing std::complex's magic permission for
 other types
Date: Mon, 26 Mar 2018 14:59:34 -0700 (PDT)
Lines: 110
Approved: news@gmane.org
Message-ID: <2111ede0-62c6-4a41-8df3-f506d07f09f2@isocpp.org>
References: <a3462649-a7bd-4215-b162-e8fe922df02d@isocpp.org>
 <6ec944b3-16c3-4f00-b0c9-a449a522d4ac@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_5272_970195018.1522101574846"
X-Trace: blaine.gmane.org 1522101454 19929 195.159.176.226 (26 Mar 2018 21:57:34 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 26 Mar 2018 21:57:34 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDKLT4PURQHRBR624XKQKGQE35SDMZQ@isocpp.org Mon Mar 26 23:57:30 2018
Return-path: <std-proposals+bncBDKLT4PURQHRBR624XKQKGQE35SDMZQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f199.google.com ([209.85.217.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDKLT4PURQHRBR624XKQKGQE35SDMZQ@isocpp.org>)
	id 1f0a7N-00054O-Jg
	for gclcip-std-proposals@m.gmane.org; Mon, 26 Mar 2018 23:57:29 +0200
Original-Received: by mail-ua0-f199.google.com with SMTP id r1sf14044287uae.6
        for <gclcip-std-proposals@m.gmane.org>; Mon, 26 Mar 2018 14:59:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=7c8dfuFeGewc33CHrlPHnLkoiOedNb6gsXHvP39DkZA=;
        b=O/wkubqZDZe/7ctaLEgTHEjhui9mx8MIwraD+tvnvJWs4Uv5qHTJxhbk9hqKUGwpHC
         k1uVx4kRu8RWIf/DkH2/QbKkoa4Nym/fNm9eoAPMXtmD686rfwYWqlmajbM1e3JG2oiJ
         Gfn5NPS2rQtGyslhoErOMQW4/elLmKtIy45dRsqkbDRIuCH0DfR5ikbj+lbYUQInC9qM
         T2BIDteDkKfCQuTvzeQTB6qQbZCTNRxQgcrNQ/QfKuz96UBeLT8+CHOXazEt2IZ8J7b9
         ATwnYBZZL47pFUXN2FQ0befy5ImeBG2A9kldpssM5nTbpB91V6vaFS0/V8iX6kDij1p9
         9/7A==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=7c8dfuFeGewc33CHrlPHnLkoiOedNb6gsXHvP39DkZA=;
        b=ZyEdgsSF5ZJPdDWmIvNKFd/k8CPlkUSYcu14rZD/0qjjZ5PfZv6qEkRzazzOKAjrXG
         kt9xXj5EmfdxOmBq/ZzL/U5WPwRjEMjAFxk05JK77lqCd6UbhCdAZTvWedDsQRvcH1rM
         NXx/PQdt52R79x006kFbIQuVO2+F+k98YQTC/yZK2v5FVzObLed7Nkiu5QwuSRjZSmiX
         yA4WKmjffSbTvuzj34WncWPXkyEWwuVLEiKtZne5vb93Hi+5YMr74Sq7idNUjUeK8FA0
         nqz5KD24kPRlbo6Jpb8Q0K1PaqVsttdebarno+slrohmgMLlMB/+MY4jpjSNjBt2OzkP
         2kfA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=7c8dfuFeGewc33CHrlPHnLkoiOedNb6gsXHvP39DkZA=;
        b=EqnHzJFanruD0dOZlDCI6/sE+Y+YKvHm/u5rEWErx4GpocLj3tuRJxAi7FrhhiY5+5
         DrpyKWxOxU7LiHFiZuYtBTTS1rGc7TyEf/uQrgSgxX1y/f2ioMyyQMGWDjPti2HX1Dmo
         XIWgHpd84mUPsn1AqO/NdM2K57qN19knmqsl0zM6ZATMNFE9X1prOg62nhmRkUQSKc5g
         8C9wdrKjbTfI7ANB2FuZQIexBqkZOLET9XusqeiSeZNb3t7LNOlj/fkJpT7MinRlxV8f
         xPNj3O8GWI3lpH+5iXF6POfjDw3Y/naZQ8tIbZg2lQsNXjaYbIl+b/qrf+mWVRX2laYd
         VkbA==
X-Gm-Message-State: AElRT7GsNI2hFRSMQ7y/EwonmAiypv45AXypquMbU+uEJpQM2FVTAK5s
	4m/uapBnTP7+Ml+C0vgcAhjIMA==
X-Google-Smtp-Source: AG47ELtKbyPHLE4lWCfWn85HWscYFLTBccujA9R8vsJNGcAtx3AXsK9SKQ2AxHq39MkgNA5K0RkkEA==
X-Received: by 10.31.177.1 with SMTP id a1mr13233734vkf.11.1522101576686;
        Mon, 26 Mar 2018 14:59:36 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.160.67 with SMTP id j64ls9443223vke.21.gmail; Mon, 26 Mar
 2018 14:59:35 -0700 (PDT)
X-Received: by 10.31.151.87 with SMTP id z84mr5023746vkd.5.1522101575322;
        Mon, 26 Mar 2018 14:59:35 -0700 (PDT)
In-Reply-To: <6ec944b3-16c3-4f00-b0c9-a449a522d4ac@isocpp.org>
X-Original-Sender: myriachan@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:37480
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37480>

------=_Part_5272_970195018.1522101574846
Content-Type: multipart/alternative; 
	boundary="----=_Part_5273_1924448923.1522101574846"

------=_Part_5273_1924448923.1522101574846
Content-Type: text/plain; charset="UTF-8"

On Monday, March 26, 2018 at 1:39:55 PM UTC-7, Nicol Bolas wrote:
>
>
>
> On Monday, March 26, 2018 at 4:26:58 PM UTC-4, Myriachan wrote:
>>
>> I would like to propose that C++ get a mechanism by which the magical 
>> ability of std::complex<T> * to be reinterpret_cast to T * could be allowed 
>> for other classes.
>>
>> A simple case of this is a vector4 type:
>>
>> struct vector3 { float x; float y; float z; float w; };
>>
>> The performance difference is strong enough that our project actually 
>> gets a much larger performance *increase* from using 
>> -fno-strict-aliasing versus -fstrict-aliasing with the changes required for 
>> compliance.
>>
>
> What does strict aliasing have to do with this? The strict aliasing rule 
> is not what prevents you from being able to do this cast. Indeed, nothing 
> prevents you from doing the cast. Since `vector4` is standard layout, the 
> standard *guarantees* that its first subobject shall have the same address 
> as the object itself. So the cast is OK.
>
> What isn't OK is the pointer arithmetic that follows, 
>

-fstrict-aliasing breaks our code, even though you're correct that it's not 
an aliasing problem.  -fstrict-aliasing seems to enable optimizations 
around pointer arithmetic undefined behavior, and there's no 
-fallow-evil-pointer-arithmetic option.

or the assumption that there is no padding between the elements.
>

The padding isn't a problem, because a simple static_assert can verify that 
your compiler isn't putting any padding.  Such code would be portable to 
any implementation that doesn't put padding.

Melissa

-- 
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/2111ede0-62c6-4a41-8df3-f506d07f09f2%40isocpp.org.

------=_Part_5273_1924448923.1522101574846
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Monday, March 26, 2018 at 1:39:55 PM UTC-7, Nicol Bolas=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><b=
r>On Monday, March 26, 2018 at 4:26:58 PM UTC-4, Myriachan wrote:<blockquot=
e class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px=
 #ccc solid;padding-left:1ex"><div dir=3D"ltr">I would like to propose that=
 C++ get a mechanism by which the magical ability of std::complex&lt;T&gt; =
* to be reinterpret_cast to T * could be allowed for other classes.<br><br>=
A simple case of this is a vector4 type:<br><br>struct vector3 { float x; f=
loat y; float z; float w; };<br><br>The performance difference is strong en=
ough that our project actually gets a much larger performance <i>increase</=
i> from using -fno-strict-aliasing versus -fstrict-aliasing with the change=
s required for compliance.<br></div></blockquote><div><br>What does strict =
aliasing have to do with this? The strict aliasing rule is not what prevent=
s you from being able to do this cast. Indeed, nothing prevents you from do=
ing the cast. Since `vector4` is standard layout, the standard *guarantees*=
 that its first subobject shall have the same address as the object itself.=
 So the cast is OK.<br><br>What isn&#39;t OK is the pointer arithmetic that=
 follows, </div></div></blockquote><div><br>-fstrict-aliasing breaks our co=
de, even though you&#39;re correct that it&#39;s not an aliasing problem.=
=C2=A0 -fstrict-aliasing seems to enable optimizations around pointer arith=
metic undefined behavior, and there&#39;s no -fallow-evil-pointer-arithmeti=
c option.<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><div>or the assumption that there is no padding between the eleme=
nts.<br></div></div></blockquote><div><br>The padding isn&#39;t a problem, =
because a simple static_assert can verify that your compiler isn&#39;t putt=
ing any padding.=C2=A0 Such code would be portable to any implementation th=
at doesn&#39;t put padding.<br><br>Melissa<br></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/2111ede0-62c6-4a41-8df3-f506d07f09f2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2111ede0-62c6-4a41-8df3-f506d07f09f2=
%40isocpp.org</a>.<br />

------=_Part_5273_1924448923.1522101574846--

------=_Part_5272_970195018.1522101574846--

.
