220 30871 <CAOG9n2H1a8bcWpnU1_EjwAA-h_Bs44zRLOWatZX=-mFLTLhjkA@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Joel Falcou <joel.falcou@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Detecting compile-time evaluation
Date: Sat, 11 Feb 2017 22:54:50 +0100
Lines: 258
Approved: news@gmane.org
Message-ID: <CAOG9n2H1a8bcWpnU1_EjwAA-h_Bs44zRLOWatZX=-mFLTLhjkA@mail.gmail.com>
References: <86a47916-27c3-4e29-862f-9b4e1f105c1c@isocpp.org>
 <34826fd2-84db-4ce9-b30b-66a95601918a@isocpp.org> <18849693.bqFcfaDNcV@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a114488307b319905484843fb
X-Trace: blaine.gmane.org 1486850100 11511 195.159.176.226 (11 Feb 2017 21:55:00 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 11 Feb 2017 21:55:00 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCPININ5TAFRBK4Q73CAKGQE3Q5QMNI@isocpp.org Sat Feb 11 22:54:53 2017
Return-path: <std-proposals+bncBCPININ5TAFRBK4Q73CAKGQE3Q5QMNI@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+bncBCPININ5TAFRBK4Q73CAKGQE3Q5QMNI@isocpp.org>)
	id 1ccfd3-0002IH-V8
	for gclcip-std-proposals@m.gmane.org; Sat, 11 Feb 2017 22:54:50 +0100
Original-Received: by mail-ua0-f199.google.com with SMTP id 96sf43989947uaq.7
        for <gclcip-std-proposals@m.gmane.org>; Sat, 11 Feb 2017 13:54:55 -0800 (PST)
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:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=lgUCAu9omcgeL7q/kqu4V5l2dXN5QlpN4Hd3L3RzL4Q=;
        b=peisMdyqNpLLHayZjIsX+dl40kplXb5gudO4vLAJnxzD0GO9WGXuB/6m+LIkQYqQnq
         SmkwHB8xW/HaJMFwPN923+/EJoEs1vKMhvR1GvNYijHvGKKQK06aWIOUzHkSlJOitl92
         zZEvrDYAdPm2fdsEVKJEuSUv2mOmYLrH31yPmeUdL2XvsPs407Tx4mPQ32D5CfZ1wdpt
         r9yHkNwnK54LpduJnVkjuuqF80MC5l4BCQE5xrfiH9OO9wKhqwh3nwWFpZaxpv8trXNW
         99xCbX3ac0aK96XKybkjeM6Ch0HenQkMhHdGjCe/f7bz3cQml+w0yOeJgEqykV6hZGvj
         Sa1A==
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=lgUCAu9omcgeL7q/kqu4V5l2dXN5QlpN4Hd3L3RzL4Q=;
        b=kuy07UrV83rHjjMeonwHhzlH9oe+Lbd3cZp7SxiH2AMicsxkumMGyVUsejWzqYvPIS
         p53/TaWypx6NtYBR8X2pVERMavx0oHP0thGWOd9TlZnwm4Dll6ZcH140JnvuiF8NXD57
         jZDgBsN85xnwtfYyOfspsTDGWvp9CKfG1XYQ/MAGBYw40zpn27xKDzkEbjBxLf01m+R2
         u9e3CfigN4+PHHanrLyTqgM7VgogzC3lU5AkX0TYZkJ3Q0Qghp712kRvgHo2L+zZt3K+
         dQhOJpHKyi8CUKe938UQa1+thpniraOkj6RDNN9WYDC0djsNjK/a07w0tIqoN51DalF0
         JjCg==
X-Gm-Message-State: AMke39nSBqGpdlmoLLu2cueAKMKkwZ2KQTS5Yyx8R9TpoQKDAxvm+3rxe9uompliZXsbhw==
X-Received: by 10.159.33.206 with SMTP id 72mr4414198uac.18.1486850095147;
        Sat, 11 Feb 2017 13:54:55 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.80.141 with SMTP id m135ls2107002itb.17.canary-gmail; Sat,
 11 Feb 2017 13:54:51 -0800 (PST)
X-Received: by 10.36.211.213 with SMTP id n204mr14944311itg.49.1486850091107;
        Sat, 11 Feb 2017 13:54:51 -0800 (PST)
Original-Received: from mail-it0-x22a.google.com (mail-it0-x22a.google.com. [2607:f8b0:4001:c0b::22a])
        by mx.google.com with ESMTPS id l6si6242932iof.240.2017.02.11.13.54.51
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 11 Feb 2017 13:54:51 -0800 (PST)
Received-SPF: pass (google.com: domain of joel.falcou@gmail.com designates 2607:f8b0:4001:c0b::22a as permitted sender) client-ip=2607:f8b0:4001:c0b::22a;
Original-Received: by mail-it0-x22a.google.com with SMTP id c7so159853331itd.1
        for <std-proposals@isocpp.org>; Sat, 11 Feb 2017 13:54:51 -0800 (PST)
X-Received: by 10.36.69.145 with SMTP id c17mr35252597itd.111.1486850090541;
 Sat, 11 Feb 2017 13:54:50 -0800 (PST)
Original-Received: by 10.107.32.196 with HTTP; Sat, 11 Feb 2017 13:54:50 -0800 (PST)
In-Reply-To: <18849693.bqFcfaDNcV@tjmaciei-mobl1>
X-Original-Sender: joel.falcou@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 joel.falcou@gmail.com designates 2607:f8b0:4001:c0b::22a as permitted sender)
 smtp.mailfrom=joel.falcou@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:30871
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30871>

--001a114488307b319905484843fb
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Eigen and other expression tempaltes library don't perform computation at
compile time, they build a lazy representation of computations at compile
time so the actual computations are delayed.
I wrote a couple of such library and the only places where constexpr made
sense was optimizing matrix size computation when all dimensions where
constants.

log2 happens a bit in constexpr context becasue finding the closest power
of 2 is a task some code may requires. I had myself solved a 2x2 linear
system but not much more at compile time.

2017-02-11 21:35 GMT+01:00 Thiago Macieira <thiago@macieira.org>:

> On s=C3=A1bado, 11 de fevereiro de 2017 10:43:53 PST Gonzalo BG wrote:
> > @Thiago:
> > > We used to have this problem with Clang: for example,
> > > qCountTrailingZeroBits  wasn't constexpr with Clang until 3.8, becaus=
e
> we
> > > couldn't use __builtin_ctz  in a constexpr context.
> >
> > Given that you have run into the issue, I cannot find the logic in the
> >
> > following statement:
> > > But in our experience, any algorithm that can be complex enough to
> > > warrant SIMD optimisation is too complex for a constexpr inline
> function.
> >
> > You seem to be arguing that using __builtin_ctz in a constexpr function
> is
> > reasonable, but using any other intrinsics while solving problems in an=
y
> > other domain is not. Care to elaborate on which experience makes you sa=
y
> so?
>
> It was a problem, but it's now fixed and we now can use the builtin that =
is
> constexpr.
>
> > 1) The post C++11 standard library. Before C++11 I rarely saw people
> > reimplementing pow, log, exp, sin, ... After C++11 almost every single
> > project had its own pow constexpr implementation because neither the ma=
th
> > functions from the standard library nor the builtins provided by the
> > compilers worked inside constant expressions for years after C++11. The
> > run-time performance of these functions was, and still is, horrible. Th=
e
> > fix for this was to make the math functions in the standard constexpr,
> but
> > this did not solve the underlying issue (which is being discussed here)=
..
>
> That's an interesting example, but it doesn't match my experience. I
> haven't
> seen a lot of people need exponentiation and logarithm in constexpr
> constexts.
> In regular code, you simply rely on the optimiser propagating constants,
> something compilers have done for a decade.
>
> > 2) Math/Linear algebra libraries like Eigen3, Blaze, ... which have use=
d
> > expression template hacks for compile-time computations for the last 20
> > years _cannot_ use constexpr anywhere in their API (and don't really us=
e
> it
> > almost anywhere) because somewhere down the pipeline they do use
> intrinsics
> > (and pragmas and what not) for run-time performance reasons.
>
> Same as above: I've never seen the need for those operations to appear in=
 a
> constexpr context in the first place. It is as I said: the majority of th=
e
> operations that benefit from non-constexpr'able code is too complex for
> constexpr anyway.
>
> > Do you consider using a log function (which is implemented using
> intrinsics
> > in most standard libraries) or multiplying two 4x4 matrices "too comple=
x"
> > for constexpr functions?
>
> Yes, in my experience.
>
> Or, put another way, what use-case warrants storing the result of such an
> operation in a constexpr variable? This is a real question, you probably
> know
> more cases than I do.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>    Software Architect - Intel Open Source Technology Center
>
> --
> 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/18849693.bqFcfaDNcV%40tjmaciei-mobl1.
>

--=20
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 e=
mail 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/CAOG9n2H1a8bcWpnU1_EjwAA-h_Bs44zRLOWatZX%3D-mFLT=
LhjkA%40mail.gmail.com.

--001a114488307b319905484843fb
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>Eigen and other expression tempaltes library don=
&#39;t perform computation at compile time, they build a lazy representatio=
n of computations at compile time so the actual computations are delayed.<b=
r></div>I wrote a couple of such library and the only places where constexp=
r made sense was optimizing matrix size computation when all dimensions whe=
re constants. <br><br></div>log2 happens a bit in constexpr context becasue=
 finding the closest power of 2 is a task some code may requires. I had mys=
elf solved a 2x2 linear system but not much more at compile time.<br></div>=
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">2017-02-11 21:35 =
GMT+01:00 Thiago Macieira <span dir=3D"ltr">&lt;<a href=3D"mailto:thiago@ma=
cieira.org" target=3D"_blank">thiago@macieira.org</a>&gt;</span>:<br><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
 solid;padding-left:1ex">On s=C3=A1bado, 11 de fevereiro de 2017 10:43:53 P=
ST Gonzalo BG wrote:<br>
&gt; @Thiago:<br>
&gt; &gt; We used to have this problem with Clang: for example,<br>
&gt; &gt; qCountTrailingZeroBits=C2=A0 wasn&#39;t constexpr with Clang unti=
l 3.8, because we<br>
&gt; &gt; couldn&#39;t use __builtin_ctz=C2=A0 in a constexpr context.<br>
&gt;<br>
&gt; Given that you have run into the issue, I cannot find the logic in the=
<br>
&gt;<br>
&gt; following statement:<br>
&gt; &gt; But in our experience, any algorithm that can be complex enough t=
o<br>
&gt; &gt; warrant SIMD optimisation is too complex for a constexpr inline f=
unction.<br>
&gt;<br>
&gt; You seem to be arguing that using __builtin_ctz in a constexpr functio=
n is<br>
&gt; reasonable, but using any other intrinsics while solving problems in a=
ny<br>
&gt; other domain is not. Care to elaborate on which experience makes you s=
ay so?<br>
<br>
It was a problem, but it&#39;s now fixed and we now can use the builtin tha=
t is<br>
constexpr.<br>
<br>
&gt; 1) The post C++11 standard library. Before C++11 I rarely saw people<b=
r>
&gt; reimplementing pow, log, exp, sin, ... After C++11 almost every single=
<br>
&gt; project had its own pow constexpr implementation because neither the m=
ath<br>
&gt; functions from the standard library nor the builtins provided by the<b=
r>
&gt; compilers worked inside constant expressions for years after C++11. Th=
e<br>
&gt; run-time performance of these functions was, and still is, horrible. T=
he<br>
&gt; fix for this was to make the math functions in the standard constexpr,=
 but<br>
&gt; this did not solve the underlying issue (which is being discussed here=
).<br>
<br>
That&#39;s an interesting example, but it doesn&#39;t match my experience. =
I haven&#39;t<br>
seen a lot of people need exponentiation and logarithm in constexpr constex=
ts.<br>
In regular code, you simply rely on the optimiser propagating constants,<br=
>
something compilers have done for a decade.<br>
<br>
&gt; 2) Math/Linear algebra libraries like Eigen3, Blaze, ... which have us=
ed<br>
&gt; expression template hacks for compile-time computations for the last 2=
0<br>
&gt; years _cannot_ use constexpr anywhere in their API (and don&#39;t real=
ly use it<br>
&gt; almost anywhere) because somewhere down the pipeline they do use intri=
nsics<br>
&gt; (and pragmas and what not) for run-time performance reasons.<br>
<br>
Same as above: I&#39;ve never seen the need for those operations to appear =
in a<br>
constexpr context in the first place. It is as I said: the majority of the<=
br>
operations that benefit from non-constexpr&#39;able code is too complex for=
<br>
constexpr anyway.<br>
<br>
&gt; Do you consider using a log function (which is implemented using intri=
nsics<br>
&gt; in most standard libraries) or multiplying two 4x4 matrices &quot;too =
complex&quot;<br>
&gt; for constexpr functions?<br>
<br>
Yes, in my experience.<br>
<br>
Or, put another way, what use-case warrants storing the result of such an<b=
r>
operation in a constexpr variable? This is a real question, you probably kn=
ow<br>
more cases than I do.<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
--<br>
Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" rel=3D"noref=
errer" target=3D"_blank">macieira.info</a> - thiago (AT) <a href=3D"http://=
kde.org" rel=3D"noreferrer" target=3D"_blank">kde.org</a><br>
=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center<br>
<br>
--<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%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@<wbr>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/18849693.bqFcfaDNcV%40tjmaciei-mobl1"=
 rel=3D"noreferrer" target=3D"_blank">https://groups.google.com/a/<wbr>isoc=
pp.org/d/msgid/std-<wbr>proposals/18849693.bqFcfaDNcV%<wbr>40tjmaciei-mobl1=
</a>.<br>
</font></span></blockquote></div><br></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/CAOG9n2H1a8bcWpnU1_EjwAA-h_Bs44zRLOWa=
tZX%3D-mFLTLhjkA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOG9n2H1a8bcWp=
nU1_EjwAA-h_Bs44zRLOWatZX%3D-mFLTLhjkA%40mail.gmail.com</a>.<br />

--001a114488307b319905484843fb--

.
