220 21870 <e5f0ed3a-22ad-489b-8881-90b6d2d0050a@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Evgeny Panasyuk <evgeny.panasyuk@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: is await an extension of the do-notation? (was Re:
 Re: Resumable expressions p0114r0 vs async/await P0057R0)
Date: Sun, 18 Oct 2015 01:52:32 -0700 (PDT)
Lines: 188
Approved: news@gmane.org
Message-ID: <e5f0ed3a-22ad-489b-8881-90b6d2d0050a@isocpp.org>
References: <639f0012-8cb4-4db3-82a6-8d042a3497f9@isocpp.org>
 <fcbcc1c4-535c-4fa2-a17d-4acffe84a4b5@isocpp.org>
 <1d15dbc4-e0c1-4df1-86db-014e11f14d26@isocpp.org>
 <56114953.4030701@wanadoo.fr>
 <561B403D.4030403@gmail.com>
 <CAOfiQqkKvZfVatJ1Bz4qSvGc-g6iep0xeP1B1=J1-gCu43NXxg@mail.gmail.com>
 <561C07D1.3080304@gmail.com>
 <CAOfiQqnR4GYCttwu8G-44_UEN4WekW19uorEvf-5VC3vOpej-g@mail.gmail.com>
 <561C213F.1060009@gmail.com>
 <fb82d876-8a54-4c28-8e53-297018470cf6@isocpp.org>
 <561C3875.2050701@gmail.com>
 <86924069-44d0-447f-bf8a-a42e46579832@isocpp.org>
 <561D79A7.8080007@gmail.com>
 <894616d6-9609-4038-b2bc-d2c62df21e0f@isocpp.org>
 <99bdb3ae-9214-4440-8572-4c47a61eda46@isocpp.org>
 <58628096-14ae-42b2-89d3-c0bd2183bbc0@isocpp.org>
 <561DC957.8080603@gmail.com>
 <510ce172-976a-4e3a-ae68-31fdb40af4d7@isocpp.org>
 <9dd3f28c-4ffb-4e08-9955-242c46e14527@isocpp.org>
 <31d5f64f-8db9-4ba3-aca7-872114b9776d@isocpp.org>
 <561DE488.3040103@gmail.com>
 <5587a3fd-499c-42b3-bf05-fd5cdc2d9118@isocpp.org>
 <561EF19E.6010405@gmail.com>
 <a4eb8eb5-0ace-457c-b410-219d8c4470db@isocpp.org>
 <f679fc91-5ab5-4894-89f1-cec17361e8f1@isocpp.org>
 <7560dfa8-c77f-41ec-9c0d-c88fe65e20b5@isocpp.org>
 <a78b3900-eee5-4bc9-ab38-52e169700205@isocpp.org>
 <bb43af4f-f1a3-41c2-b14d-edda75a44458@isocpp.org>
 <d921fcc9-36a4-4f6e-9cf3-c934fc991ccc@isocpp.org>
 <CANCwVhcjBjX+9v9D9OEuDeZCf5p77SbrxN0DMif3CyMkoe8DSA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_898_198255041.1445158353080"
X-Trace: ger.gmane.org 1445158362 1728 80.91.229.3 (18 Oct 2015 08:52:42 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 18 Oct 2015 08:52:42 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC54TLGKR4LBBUV3RWYQKGQEMX6GCFI@isocpp.org Sun Oct 18 10:52:42 2015
Return-path: <std-proposals+bncBC54TLGKR4LBBUV3RWYQKGQEMX6GCFI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC54TLGKR4LBBUV3RWYQKGQEMX6GCFI@isocpp.org>)
	id 1Znjhp-0003Cy-5f
	for gclcip-std-proposals@m.gmane.org; Sun, 18 Oct 2015 10:52:41 +0200
Original-Received: by iow1 with SMTP id 1sf172236265iow.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 18 Oct 2015 01:52:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :content-type: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=VUaHfqMUoxeb6EkHNYO+0RWoFTQG2rzN9Q7XnFMxIdY=;
        b=EHKu5bke2/L/ZSWrMXg2h2YikKN2J1YLgnKXbeF7ccnGB4f8flKm71gxlvhLkJsCu3
         FHFifiwc8sV0/+fO9DentcvT0LSV7hltrmiCg5SqbtwhAd+uLMLQPOfcYEmNdTVyXwsC
         9gZ8xfItWCrfl9zHYcXnMdqyqyE/zvpOwqBckrZL0GDXZnfLfM/YkuNJNw9Zk7Xk2D8q
         oFZA1CcUMWCAtk4/xg09ar7paR1/leFtA1zmILovfT1VTkhXMeq2DIGgTQWri0M6Q+ZJ
         3mou7kXkQ1+vAhstjbG6t+nSg8BSzOpff4i78gQY256JYD9u2OmD0GMywAJRE/pBHLqc
         LnJw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type: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=VUaHfqMUoxeb6EkHNYO+0RWoFTQG2rzN9Q7XnFMxIdY=;
        b=NsWMzX0KmVH0ZOG4hkzSJtdTkoCm8KZssjGe10U9vt0RXhY2qZ8MVWc08OtEHonQYM
         7c+KIY4MPZELtfQIbOFmyIkyRnYDKnby4BTk0M1lPLQOhWVUK9T98fsJtCV33n/ughB3
         XuVjvBnFcq4MNIt4jA6va1+4AB+E0FgJMaQzD6FIkW3kOLGeRME5RIGl6MXV4lNVusjC
         RaBGpQl79WPKt/ZGoU2qCWHcH9FUhIna89XbqWPLdiKbs+goWe8HVnGlWBWJHLox9uUq
         PaTzknbK2GbH2juCv6YI2c6lrlH9tvsmRuqnWxUWn1HVv3GZl8UZH0gamNc3BtMGUk2W
         I8Lw==
X-Gm-Message-State: ALoCoQn7qOUqF/eSeuPmeB5zFrkM1YwPaPv6Th5R9D61CcGYQOsZIi5u/1R/EYvWuCPuHvxQebWg
X-Received: by 10.107.162.142 with SMTP id l136mr20891531ioe.32.1445158355076;
        Sun, 18 Oct 2015 01:52:35 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.169.66 with SMTP id s63ls755318ioe.68.gmail; Sun, 18 Oct
 2015 01:52:34 -0700 (PDT)
X-Received: by 10.50.225.70 with SMTP id ri6mr267106igc.9.1445158354371;
        Sun, 18 Oct 2015 01:52:34 -0700 (PDT)
In-Reply-To: <CANCwVhcjBjX+9v9D9OEuDeZCf5p77SbrxN0DMif3CyMkoe8DSA@mail.gmail.com>
X-Original-Sender: Evgeny.Panasyuk@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:21870
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21870>

------=_Part_898_198255041.1445158353080
Content-Type: multipart/alternative; 
	boundary="----=_Part_899_96203393.1445158353081"

------=_Part_899_96203393.1445158353081
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

18 October 2015 =D0=B3., 11:07:55 UTC+3 TONGARI J:
>
>
> Out of curiosity, what does the corresponding macro version look like?
>

It is very similar in structure:
COROUTINE(int, yield_demo, (int, N),
    (int, i))
{
    for (i =3D 0; i !=3D N; ++i)
        YIELD i;
    return;
}
COROUTINE_END
Due limitation of macro-implementation major difference here is that you=20
have to put all locals (loop variable i) at the top, like in old C or=20
Pascal.
=20

> do you provide the similar iterator API and use it for comparison?
>

Yes, I used very similar input iterator to one defined int=20
std::experimental::generator, and used range-based-for (and actually *main*=
=20
is exactly same).

But if use coroutine directly, without iterators and range-based-for (which=
=20
are not well suited for input ranges), then GCC generates following code=20
within loop:

..L5:

	addl	$1, %ebx

	cmpl	$1073741824, %ebx

	jne	.L6

                 ... branch with ret ...

..L6:

	.cfi_restore_state

	movl	%ebx, %edi

	call	_Z5printi

	jmp	.L5


It is almost zero overhead. Small issue here is that looks like it does not=
=20
understand which branch is more likely, that's why there is "split" of code=
=20
and unconditional jump to .L5.

Anyway, I do realize that I should provide full code, more results data,=20
etc, make other tests, add await, etc. That's why I said that detailed=20
report is required.

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_899_96203393.1445158353081
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">18 October 2015 =D0=B3., 11:07:55 UTC+3 TONGARI J:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gm=
ail_quote"><div><br></div><div>Out of curiosity, what does the correspondin=
g macro version look like?</div></div></div></div></blockquote><div><br>It =
is very similar in structure:<br><div class=3D"prettyprint" style=3D"backgr=
ound-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-st=
yle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D=
"styled-by-prettify">COROUTINE</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> yiel=
d_demo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> N</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">),</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> i</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">))</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">for</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">i </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">=
0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> i </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">!=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> N</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">++</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">i</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 YIELD i</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
COROUTINE_END</span></div></code></div>Due limitation of macro-implementati=
on major difference here is that you have to put all locals (loop variable =
i) at the top, like in old C or Pascal.<br>=C2=A0</div><blockquote class=3D=
"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc s=
olid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><=
div>do you provide the similar iterator API and use it for comparison?</div=
></div></div></div></blockquote><div><br>Yes, I used very similar input ite=
rator to one defined int std::experimental::generator, and used range-based=
-for (and actually <b>main</b> is exactly same).<br><br>But if use coroutin=
e directly, without iterators and range-based-for (which are not well suite=
d for input ranges), then GCC generates following code within loop:<br><div=
><pre class=3D"f0" style=3D"display: inline-block; padding: 0; margin: 0;">=
..L5:</pre></div><div><pre class=3D"f0" style=3D"display: inline-block; padd=
ing: 0; margin: 0;">	addl	$1, %ebx</pre></div><div><pre class=3D"f0" style=
=3D"display: inline-block; padding: 0; margin: 0;">	cmpl	$1073741824, %ebx<=
/pre></div><div><pre class=3D"f0" style=3D"display: inline-block; padding: =
0; margin: 0;">	jne	.L6</pre></div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ... branch with r=
et ...<br><div><pre class=3D"f0" style=3D"display: inline-block; padding: 0=
; margin: 0;">.L6:</pre></div><div><pre class=3D"f0" style=3D"display: inli=
ne-block; padding: 0; margin: 0;">	.cfi_restore_state</pre></div><div><pre =
class=3D"f0" style=3D"display: inline-block; padding: 0; margin: 0;">	movl	=
%ebx, %edi</pre></div><div><pre class=3D"f0" style=3D"display: inline-block=
; padding: 0; margin: 0;">	call	_Z5printi</pre></div><div><pre class=3D"f0"=
 style=3D"display: inline-block; padding: 0; margin: 0;">	jmp	.L5</pre></di=
v><br>It is almost zero overhead. Small issue here is that looks like it do=
es not understand which branch is more likely, that&#39;s why there is &quo=
t;split&quot; of code and unconditional jump to .L5.<br><br>Anyway, I do re=
alize that I should provide full code, more results data, etc, make other t=
ests, add await, etc. That&#39;s why I said that detailed report is require=
d.<br></div></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_899_96203393.1445158353081--
------=_Part_898_198255041.1445158353080--

.
