Topic: Allowing constexpr char[]'s in asm directives
Author: Jens Maurer <Jens.Maurer@gmx.net>
Date: Sat, 10 Nov 2012 08:15:30 +0100
Raw View
On 11/10/2012 02:15 AM, stackmachine@hotmail.com wrote:
> Simple feature: Allow the use of compiletime constant strings in asm directives. That would allow generating asm through template-meta programs. Wouldn't that be damn awesome?
Could you provide an example program that makes use of such a
feature in a non-trivial way, including the generation of
the compile-time constant strings? In which way would the
portability of that program be improved if the standard
would prescribe the feature you're proposing?
This needs a lot more elaboration before I'm willing
to invest committee time in it.
The current standard doesn't say a lot about "asm" (see section 7.4),
except that its argument must be a string-literal. And even then,
the entire asm is conditionally-supported, meaning an implementation
can simply refuse an "asm" with an error message (and not implement it).
Jens
--
.
Author: stackmachine@hotmail.com
Date: Sun, 11 Nov 2012 07:02:04 -0800 (PST)
Raw View
------=_Part_324_26262145.1352646124819
Content-Type: text/plain; charset=ISO-8859-1
Am Samstag, 10. November 2012 08:16:19 UTC+1 schrieb Jens Maurer:
>
> On 11/10/2012 02:15 AM, stackm...@hotmail.com <javascript:> wrote:
> > Simple feature: Allow the use of compiletime constant strings in asm
> directives. That would allow generating asm through template-meta programs.
> Wouldn't that be damn awesome?
>
> Could you provide an example program that makes use of such a
> feature in a non-trivial way, including the generation of
> the compile-time constant strings? In which way would the
> portability of that program be improved if the standard
> would prescribe the feature you're proposing?
>
The program would not neccessarily be more portable but it would allow (for
example) simple abstractions around common patterns, such as loops,
conditions, or function calls.
Here's a simple example of how this could be used:
typedef function<stdcall, "print_int"> print_int; // assuming that string
literals could be used as template parameters in the future
typedef for_from_to<1, 10, call<print_int>> print_1_to_10;
asm(generate_asm<x86_64, print_1_to_10>::value::c_str);
::value might be some compiletime string type, which itself holds a
constexpr char[] ::c_str.
Now I do admit that this example might not be the best, but it demonstrates
one important aspect of this feature: The programmer does not have to deal
with details, such as calling conventions, as this is handled by the
library that generates the code.
> The current standard doesn't say a lot about "asm" (see section 7.4),
> except that its argument must be a string-literal. And even then,
> the entire asm is conditionally-supported, meaning an implementation
> can simply refuse an "asm" with an error message (and not implement it).
>
Instead of only allowing string literals, I propose to allow constant
string expressions. This would only require a change to the grammar AFAIK.
(?)
--
------=_Part_324_26262145.1352646124819
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>Am Samstag, 10. November 2012 08:16:19 UTC+1 schrieb Jens Maurer:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;">On 11/10/2012 02:15 AM, <a href=
=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"pkN49n5U4rIJ">s=
tackm...@hotmail.com</a> wrote:
<br>> Simple feature: Allow the use of compiletime constant strings in a=
sm directives. That would allow generating asm through template-meta progra=
ms. Wouldn't that be damn awesome?
<br>
<br>Could you provide an example program that makes use of such a
<br>feature in a non-trivial way, including the generation of
<br>the compile-time constant strings? In which way would the
<br>portability of that program be improved if the standard
<br>would prescribe the feature you're proposing?
<br></blockquote><div>The program would not neccessarily be more portable b=
ut it would allow (for example) simple abstractions around common patterns,=
such as loops, conditions, or function calls.<br>Here's a simple example o=
f how this could be used:<br><br>typedef function<stdcall, "print_int"&g=
t; print_int; // assuming that string literals could be used as template pa=
rameters in the future<br>typedef for_from_to<1, 10, call<print_int&g=
t;> print_1_to_10;<br><br>asm(generate_asm<x86_64, print_1_to_10>:=
:value::c_str);<br><br>::value might be some compiletime string type, which=
itself holds a constexpr char[] ::c_str.<br>Now I do admit that this examp=
le might not be the best, but it demonstrates one important aspect of this =
feature: The programmer does not have to deal with details, such as calling=
conventions, as this is handled by the library that generates the code.<br=
></div><div> <br></div><blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Th=
e current standard doesn't say a lot about "asm" (see section 7.4),
<br>except that its argument must be a string-literal. And even then,
<br>the entire asm is conditionally-supported, meaning an implementation
<br>can simply refuse an "asm" with an error message (and not implement it)=
..<br></blockquote><div>Instead of only allowing string literals, I propose =
to allow constant string expressions. This would only require a change to t=
he grammar AFAIK. (?)<br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_324_26262145.1352646124819--
.
Author: Jens Maurer <Jens.Maurer@gmx.net>
Date: Sun, 11 Nov 2012 16:44:14 +0100
Raw View
On 11/11/2012 04:02 PM, stackmachine@hotmail.com wrote:
>
>
> Am Samstag, 10. November 2012 08:16:19 UTC+1 schrieb Jens Maurer:
>
> On 11/10/2012 02:15 AM, stackm...@hotmail.com <javascript:> wrote:
> > Simple feature: Allow the use of compiletime constant strings in asm directives. That would allow generating asm through template-meta programs. Wouldn't that be damn awesome?
>
> Could you provide an example program that makes use of such a
> feature in a non-trivial way, including the generation of
> the compile-time constant strings? In which way would the
> portability of that program be improved if the standard
> would prescribe the feature you're proposing?
>
> The program would not neccessarily be more portable but it would allow (for example) simple abstractions around common patterns, such as loops, conditions, or function calls.
> Here's a simple example of how this could be used:
>
> typedef function<stdcall, "print_int"> print_int; // assuming that string literals could be used as template parameters in the future
Here's the first other extension you'll need.
> typedef for_from_to<1, 10, call<print_int>> print_1_to_10;
>
> asm(generate_asm<x86_64, print_1_to_10>::value::c_str);
This example doesn't convince me. You've got a C++ compiler in your hand, yet
you try to print the numbers from 1 to 10 in semi-handcrafting assembly?
> ::value might be some compiletime string type, which itself holds a constexpr char[] ::c_str.
Please clue me in: How do you do compile-time string concatenation with the
current constexpr feature set? (Yes, the preprocessor can splice string
literals, but that's not what we're talking about here.)
> Now I do admit that this example might not be the best, but it demonstrates one important aspect of this feature: The programmer does not have to deal with details, such as calling conventions, as this is handled by the library that generates the code.
I occasionally have to write inline assembly myself, for example for SIMD
code. In my uses, I never call foreign functions from an asm (the compiler
can do that much better, including passing parameters as appropriate).
Instead, ideally, I write one function that consists entirely of an asm
doing one particular operation that is impossible to achieve with plain C++.
>
> The current standard doesn't say a lot about "asm" (see section 7.4),
> except that its argument must be a string-literal. And even then,
> the entire asm is conditionally-supported, meaning an implementation
> can simply refuse an "asm" with an error message (and not implement it).
>
> Instead of only allowing string literals, I propose to allow constant string expressions. This would only require a change to the grammar AFAIK. (?)
I understand your proposal. I have yet to see a non-trivial use that
makes such a change compelling to me. Just because something can be done
and looks easy at the top level, doesn't mean it should be done. There
is always some extra maintenance cost down the road, cf. the current core
issues list.
Thanks,
Jens
--
.
Author: stackmachine@hotmail.com
Date: Sun, 11 Nov 2012 08:29:34 -0800 (PST)
Raw View
------=_Part_143_23834307.1352651374169
Content-Type: text/plain; charset=ISO-8859-1
Am Sonntag, 11. November 2012 16:44:19 UTC+1 schrieb Jens Maurer:
>
> On 11/11/2012 04:02 PM, stackm...@hotmail.com <javascript:> wrote:
> >
> >
> > Am Samstag, 10. November 2012 08:16:19 UTC+1 schrieb Jens Maurer:
> >
> > On 11/10/2012 02:15 AM, stackm...@hotmail.com <javascript:> wrote:
> > > Simple feature: Allow the use of compiletime constant strings in
> asm directives. That would allow generating asm through template-meta
> programs. Wouldn't that be damn awesome?
> >
> > Could you provide an example program that makes use of such a
> > feature in a non-trivial way, including the generation of
> > the compile-time constant strings? In which way would the
> > portability of that program be improved if the standard
> > would prescribe the feature you're proposing?
> >
> > The program would not neccessarily be more portable but it would allow
> (for example) simple abstractions around common patterns, such as loops,
> conditions, or function calls.
> > Here's a simple example of how this could be used:
> >
> > typedef function<stdcall, "print_int"> print_int; // assuming that
> string literals could be used as template parameters in the future
>
> Here's the first other extension you'll need.
>
No. It's a nice-to-have feature, but certainly not required.
> > typedef for_from_to<1, 10, call<print_int>> print_1_to_10;
> >
> > asm(generate_asm<x86_64, print_1_to_10>::value::c_str);
>
> This example doesn't convince me. You've got a C++ compiler in your hand,
> yet
> you try to print the numbers from 1 to 10 in semi-handcrafting assembly?
>
It's an example, used to demonstrate possible usage. It is not supposed to
be useful.
> > ::value might be some compiletime string type, which itself holds a
> constexpr char[] ::c_str.
>
> Please clue me in: How do you do compile-time string concatenation with
> the
> current constexpr feature set? (Yes, the preprocessor can splice string
> literals, but that's not what we're talking about here.)
>
By using some template magic.
template <char... S>
struct string
{
constexpr char c_str[] = { S..., 0 };
};
template <typename, typename>
struct concat;
template <char... S1, char... S2>
struct concat<string<S1...>, string<S2...>>
{
typedef string<S1..., S2...> value;
};
Possible usage:
typedef string<'a', 'b', 'c'> abc;
typedef string<'d', 'e', 'f'> def;
typedef concat<abc, def>::value abcdef;
std::cout << abcdef::c_str;
> The current standard doesn't say a lot about "asm" (see section 7.4),
> > except that its argument must be a string-literal. And even then,
> > the entire asm is conditionally-supported, meaning an implementation
> > can simply refuse an "asm" with an error message (and not implement
> it).
> >
> > Instead of only allowing string literals, I propose to allow constant
> string expressions. This would only require a change to the grammar AFAIK.
> (?)
>
> I understand your proposal. I have yet to see a non-trivial use that
> makes such a change compelling to me. Just because something can be done
> and looks easy at the top level, doesn't mean it should be done. There
> is always some extra maintenance cost down the road, cf. the current core
> issues list.
>
Note that I'm not proposing an entirely new feature, compilers already
contain the logic to evaluate constant expressions. Therefore I only
request to lift a restriction that does not seem to have a rationale.
I do admit that I don't have a use case for it, I just think it'd be a cool
thing to have.
--
------=_Part_143_23834307.1352651374169
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Am Sonntag, 11. November 2012 16:44:19 UTC+1 schrieb Jens Maurer:<blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;">On 11/11/2012 04:02 PM, <a href=3D"javas=
cript:" target=3D"_blank" gdf-obfuscated-mailto=3D"BfxLsyeKq-IJ">stackm...@=
hotmail.com</a> wrote:
<br>>=20
<br>>=20
<br>> Am Samstag, 10. November 2012 08:16:19 UTC+1 schrieb Jens Maurer:
<br>>=20
<br>> On 11/10/2012 02:15 AM, <a>stackm...@hotmail.com</a>=
<javascript:> wrote:
<br>> > Simple feature: Allow the use of compiletime co=
nstant strings in asm directives. That would allow generating asm through t=
emplate-meta programs. Wouldn't that be damn awesome?
<br>>=20
<br>> Could you provide an example program that makes use =
of such a
<br>> feature in a non-trivial way, including the generati=
on of
<br>> the compile-time constant strings? In which wa=
y would the
<br>> portability of that program be improved if the stand=
ard
<br>> would prescribe the feature you're proposing?
<br>>=20
<br>> The program would not neccessarily be more portable but it would a=
llow (for example) simple abstractions around common patterns, such as loop=
s, conditions, or function calls.
<br>> Here's a simple example of how this could be used:
<br>>=20
<br>> typedef function<stdcall, "print_int"> print_int; // assumin=
g that string literals could be used as template parameters in the future
<br>
<br>Here's the first other extension you'll need.
<br></blockquote><div>No. It's a nice-to-have feature, but certainly not re=
quired. <br></div><div> </div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;">> typedef for_from_to<1, 10, call<print_int>> print_1_=
to_10;
<br>>=20
<br>> asm(generate_asm<x86_64, print_1_to_10>::value::c_str);
<br>
<br>This example doesn't convince me. You've got a C++ compiler in yo=
ur hand, yet
<br>you try to print the numbers from 1 to 10 in semi-handcrafting assembly=
?<br></blockquote><div>It's an example, used to demonstrate possible usage.=
It is not supposed to be useful.<br> </div><blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;">> ::value might be some compiletime string type, whic=
h itself holds a constexpr char[] ::c_str.
<br>
<br>Please clue me in: How do you do compile-time string concatenation with=
the
<br>current constexpr feature set? (Yes, the preprocessor can splice =
string
<br>literals, but that's not what we're talking about here.)
<br></blockquote><div>By using some template magic.<br>template <char...=
S><br>struct string<br>{<br> constexpr char c_str[] =
=3D { S..., 0 };<br>};<br><br>template <typename, typename><br>struct=
concat;<br><br>template <char... S1, char... S2><br>struct concat<=
;string<S1...>, string<S2...>><br>{<br> ty=
pedef string<S1..., S2...> value;<br>};<br><br>Possible usage:<br>typ=
edef string<'a', 'b', 'c'> abc;<br>typedef string<'d', 'e', 'f'>=
; def;<br>typedef concat<abc, def>::value abcdef;<br>std::cout <&l=
t; abcdef::c_str; <br><br></div><blockquote class=3D"gmail_quote" style=3D"=
margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;=
">> The current standard doesn't say a lot about "asm" (se=
e section 7.4),
<br>> except that its argument must be a string-literal. &=
nbsp;And even then,
<br>> the entire asm is conditionally-supported, meaning a=
n implementation
<br>> can simply refuse an "asm" with an error message (an=
d not implement it).
<br>>=20
<br>> Instead of only allowing string literals, I propose to allow const=
ant string expressions. This would only require a change to the grammar AFA=
IK. (?)
<br>
<br>I understand your proposal. I have yet to see a non-trivial use t=
hat
<br>makes such a change compelling to me. Just because something can =
be done
<br>and looks easy at the top level, doesn't mean it should be done. =
There
<br>is always some extra maintenance cost down the road, cf. the current co=
re
<br>issues list.
<br></blockquote><div>Note that I'm not proposing an entirely new feature, =
compilers already contain the logic to evaluate constant expressions. There=
fore I only request to lift a restriction that does not seem to have a rati=
onale.<br>I do admit that I don't have a use case for it, I just think it'd=
be a cool thing to have.<br> </div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_143_23834307.1352651374169--
.
Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Sun, 11 Nov 2012 18:31:31 +0100
Raw View
--e89a8ffba8a3809fac04ce3b8fb9
Content-Type: text/plain; charset=ISO-8859-1
On Sun, Nov 11, 2012 at 5:29 PM, <stackmachine@hotmail.com> wrote:
> It's an example, used to demonstrate possible usage. It is not supposed to
> be useful.
>
Does that mean the proposed feature is also not supposed to be useful? If
it is supposed to be useful, why don't you show that to us instead?
> I do admit that I don't have a use case for it, I just think it'd be a
> cool thing to have.
>
You really want to add a feature *without a use case*? To me that sounds
like wasting everyone's time?
Martinho
--
--e89a8ffba8a3809fac04ce3b8fb9
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On Sun, Nov 11, 2012 at 5:29 PM, <span dir=3D"ltr"><<a href=3D"mailto:s=
tackmachine@hotmail.com" target=3D"_blank">stackmachine@hotmail.com</a>>=
</span> wrote:<br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quo=
te" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"=
>
<div>It's an example, used to demonstrate possible usage. It is not sup=
posed to be useful.<br></div></blockquote><div><br>Does that mean the propo=
sed feature is also not supposed to be useful? If it is supposed to be usef=
ul, why don't you show that to us instead? <br>
</div><div>=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I do admit that I d=
on't have a use case for it, I just think it'd be a cool thing to h=
ave.<span class=3D"HOEnZb"><font color=3D"#888888"><br>
</font></span></div></blockquote><div><br>You really want to add a feature =
*without a use case*? To me that sounds like wasting everyone's time?<b=
r></div></div><br clear=3D"all">Martinho
<p></p>
-- <br />
<br />
<br />
<br />
--e89a8ffba8a3809fac04ce3b8fb9--
.
Author: stackmachine@hotmail.com
Date: Sun, 11 Nov 2012 10:00:54 -0800 (PST)
Raw View
------=_Part_860_25384611.1352656854744
Content-Type: text/plain; charset=ISO-8859-1
Am Sonntag, 11. November 2012 18:31:55 UTC+1 schrieb R. Martinho Fernandes:
>
> On Sun, Nov 11, 2012 at 5:29 PM, <stackm...@hotmail.com <javascript:>>wrote:
>
>> It's an example, used to demonstrate possible usage. It is not supposed
>> to be useful.
>>
>
> Does that mean the proposed feature is also not supposed to be useful? If
> it is supposed to be useful, why don't you show that to us instead?
>
Someonem might find it useful. Dunno.
> I do admit that I don't have a use case for it, I just think it'd be a
>> cool thing to have.
>>
>
> You really want to add a feature *without a use case*? To me that sounds
> like wasting everyone's time?
>
As I already stated, it's not a new feature.
--
------=_Part_860_25384611.1352656854744
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>Am Sonntag, 11. November 2012 18:31:55 UTC+1 schrieb R. Martinho Fe=
rnandes:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Sun, Nov 11, 2012 a=
t 5:29 PM, <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank"=
gdf-obfuscated-mailto=3D"ubvs3_b7YqMJ">stackm...@hotmail.com</a>></span=
> wrote:<br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>It's an example, used to demonstrate possible usage. It is not suppose=
d to be useful.<br></div></blockquote><div><br>Does that mean the proposed =
feature is also not supposed to be useful? If it is supposed to be useful, =
why don't you show that to us instead? <br></div></div></blockquote><div>So=
meonem might find it useful. Dunno.<br> <br></div><blockquote class=3D=
"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc s=
olid;padding-left: 1ex;"><div class=3D"gmail_quote"><div>
</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div>I do admit that I don't have a us=
e case for it, I just think it'd be a cool thing to have.<span><font color=
=3D"#888888"><br>
</font></span></div></blockquote><div><br>You really want to add a feature =
*without a use case*? To me that sounds like wasting everyone's time?<br></=
div></div></blockquote><div>As I already stated, it's not a new feature.<br=
></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_860_25384611.1352656854744--
.