<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: GCC Inline Assembler</title>
	<atom:link href="http://www.airs.com/blog/archives/230/feed" rel="self" type="application/rss+xml" />
	<link>http://www.airs.com/blog/archives/230</link>
	<description>Ian Lance Taylor</description>
	<lastBuildDate>Mon, 26 Jul 2010 08:38:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/230/comment-page-1#comment-14678</link>
		<dc:creator>Ian Lance Taylor</dc:creator>
		<pubDate>Thu, 14 Aug 2008 01:23:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/230#comment-14678</guid>
		<description>davem: you are of course right about condition codes.

alexr: you really do need clobbers if you want to use inline supervisor calls.  I don&#039;t see any way around it.

Generating object files directly would help somewhat with inline assembler, assuming gcc included an assembler, but it wouldn&#039;t help much otherwise.  Several years ago we looked into it, but we realized that it would only help with compile time, and the savings in compile time would be quite small--a couple of percent.  The assembler is fast.</description>
		<content:encoded><![CDATA[<p>davem: you are of course right about condition codes.</p>
<p>alexr: you really do need clobbers if you want to use inline supervisor calls.  I don&#8217;t see any way around it.</p>
<p>Generating object files directly would help somewhat with inline assembler, assuming gcc included an assembler, but it wouldn&#8217;t help much otherwise.  Several years ago we looked into it, but we realized that it would only help with compile time, and the savings in compile time would be quite small&#8211;a couple of percent.  The assembler is fast.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alexr</title>
		<link>http://www.airs.com/blog/archives/230/comment-page-1#comment-14674</link>
		<dc:creator>alexr</dc:creator>
		<pubDate>Wed, 13 Aug 2008 20:48:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/230#comment-14674</guid>
		<description>Metrowerks&#039;s implementation (not merely the syntax that Apple cloned with -fasm-blocks) was capable of scheduling and even optimizing inline asm.

I consider clobbers and the other GCC markup to be abhorrent. Everybody gets them wrong. I mean everybody: kernel engineers and GCC committers alike.

It&#039;s way past time for GCC to generate object files directly.</description>
		<content:encoded><![CDATA[<p>Metrowerks&#8217;s implementation (not merely the syntax that Apple cloned with -fasm-blocks) was capable of scheduling and even optimizing inline asm.</p>
<p>I consider clobbers and the other GCC markup to be abhorrent. Everybody gets them wrong. I mean everybody: kernel engineers and GCC committers alike.</p>
<p>It&#8217;s way past time for GCC to generate object files directly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: davem</title>
		<link>http://www.airs.com/blog/archives/230/comment-page-1#comment-14673</link>
		<dc:creator>davem</dc:creator>
		<pubDate>Wed, 13 Aug 2008 19:53:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/230#comment-14673</guid>
		<description>As much as I love GCC&#039;s inline asm feature (and no, Sun&#039;s is definitely
not better, it is so much less powerful) one thing that irks me is that
there is no way to interface with the condition codes.

Actually,  because of this, I kind of find it amusing that you mention add
with carry instructions, heh.

So you can&#039;t use inline asm to generate condition codes that if
statements act upon, for example.  And this leads to a lot of extra
unnecessary code.

it also makes things like extremely space and time efficient assertion
implementations not possible either.  We have this macro called BUG_ON()
in the Linux kernel that just traps on a given condition, but with certain config
options enabled it also will provide the source file and line number in the
logs when it triggers.

The most optimal implementation would be a builtin_trap() that allowed
annotations to be assosciated with the trap instruction address.  The
power of builtin_trap() is that it is &quot;noreturn&quot;, and also on platforms like
sparc we can use conditional trap instructions.  Nearly zero cost assertions :)
But when you try to use inline asm to add instruction pointer based annotations
you can&#039;t do anything sane because getting at the condition codes calculated
by an expression is simply not possible.

This applies both on the way into the asm and also on the way out.

It would be really hard to provide this kind of facility for a number of
reasons.  For one thing, gcc likes to invert tests and use the reverse
branch during optimizations and code generation, and there is no
easy way to express that in the asm syntax.

I think the ARM backend of GCC tried to support condition code access
with some kind of asm syntax, but that got ripped out because it could
never work reliably.</description>
		<content:encoded><![CDATA[<p>As much as I love GCC&#8217;s inline asm feature (and no, Sun&#8217;s is definitely<br />
not better, it is so much less powerful) one thing that irks me is that<br />
there is no way to interface with the condition codes.</p>
<p>Actually,  because of this, I kind of find it amusing that you mention add<br />
with carry instructions, heh.</p>
<p>So you can&#8217;t use inline asm to generate condition codes that if<br />
statements act upon, for example.  And this leads to a lot of extra<br />
unnecessary code.</p>
<p>it also makes things like extremely space and time efficient assertion<br />
implementations not possible either.  We have this macro called BUG_ON()<br />
in the Linux kernel that just traps on a given condition, but with certain config<br />
options enabled it also will provide the source file and line number in the<br />
logs when it triggers.</p>
<p>The most optimal implementation would be a builtin_trap() that allowed<br />
annotations to be assosciated with the trap instruction address.  The<br />
power of builtin_trap() is that it is &#8220;noreturn&#8221;, and also on platforms like<br />
sparc we can use conditional trap instructions.  Nearly zero cost assertions <img src='http://www.airs.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
But when you try to use inline asm to add instruction pointer based annotations<br />
you can&#8217;t do anything sane because getting at the condition codes calculated<br />
by an expression is simply not possible.</p>
<p>This applies both on the way into the asm and also on the way out.</p>
<p>It would be really hard to provide this kind of facility for a number of<br />
reasons.  For one thing, gcc likes to invert tests and use the reverse<br />
branch during optimizations and code generation, and there is no<br />
easy way to express that in the asm syntax.</p>
<p>I think the ARM backend of GCC tried to support condition code access<br />
with some kind of asm syntax, but that got ripped out because it could<br />
never work reliably.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/230/comment-page-1#comment-14671</link>
		<dc:creator>Ian Lance Taylor</dc:creator>
		<pubDate>Wed, 13 Aug 2008 14:17:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/230#comment-14671</guid>
		<description>Thanks for the comments.  The problem with both the Sun&#039;s compiler approach and the Apple compiler approach is that they don&#039;t (as far as I know) allow you to express clobbers.  That means that you can&#039;t use them to implement supervisor calls (or system calls if you are using a regular Unix kernel).  The supervisor call will clobber some specified set of registers.  You need to be able to explain that to the compiler so that the optimizers understand what the asm block is doing.

gcc&#039;s asm syntax allows you to specify exactly what the asm generates, and thus the optimizer can actually delete the asm if it is unused (and not volatile).  This is very useful when working with things like add-with-carry, where the optimizer can reasonably determine that the result is not needed in some cases.

In other words these other asm syntaxes are easier to use but they are not, I believe, as powerful.</description>
		<content:encoded><![CDATA[<p>Thanks for the comments.  The problem with both the Sun&#8217;s compiler approach and the Apple compiler approach is that they don&#8217;t (as far as I know) allow you to express clobbers.  That means that you can&#8217;t use them to implement supervisor calls (or system calls if you are using a regular Unix kernel).  The supervisor call will clobber some specified set of registers.  You need to be able to explain that to the compiler so that the optimizers understand what the asm block is doing.</p>
<p>gcc&#8217;s asm syntax allows you to specify exactly what the asm generates, and thus the optimizer can actually delete the asm if it is unused (and not volatile).  This is very useful when working with things like add-with-carry, where the optimizer can reasonably determine that the result is not needed in some cases.</p>
<p>In other words these other asm syntaxes are easier to use but they are not, I believe, as powerful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Villiom Podlaski Christiansen</title>
		<link>http://www.airs.com/blog/archives/230/comment-page-1#comment-14670</link>
		<dc:creator>Dan Villiom Podlaski Christiansen</dc:creator>
		<pubDate>Wed, 13 Aug 2008 13:38:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/230#comment-14670</guid>
		<description>I believe Apple added support for assembly blocks when using the -fasm-blocks flag. How does your suggestion compare to it?</description>
		<content:encoded><![CDATA[<p>I believe Apple added support for assembly blocks when using the -fasm-blocks flag. How does your suggestion compare to it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ppluzhnikov</title>
		<link>http://www.airs.com/blog/archives/230/comment-page-1#comment-14667</link>
		<dc:creator>ppluzhnikov</dc:creator>
		<pubDate>Wed, 13 Aug 2008 07:29:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/230#comment-14667</guid>
		<description>Sun compiler supports this in arguably cleaner way:
http://groups.google.com/group/comp.unix.solaris/msg/4fa096b9fe24c2bc</description>
		<content:encoded><![CDATA[<p>Sun compiler supports this in arguably cleaner way:<br />
<a href="http://groups.google.com/group/comp.unix.solaris/msg/4fa096b9fe24c2bc" rel="nofollow">http://groups.google.com/group/comp.unix.solaris/msg/4fa096b9fe24c2bc</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
