This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: MS/CW-style inline assembly for GCC
On Mon, May 10, 2004 at 10:29:49AM +0100, Richard Earnshaw wrote:
> > Why wouldn't you write the code in C in these cases? It seems to me
> > that if you're willing to have the compiler schedule the code, you
> > might as well let it select the instructions and do register
> > allocation as well.
>
> All sorts of reasons. Maybe C has no way to express the problem
> efficiently (eg arbitrary-precision arithmetic).
Actually pretty much all MPI math can be implemented efficiently in plain
C. The one exception is getting access to the 64x64->128 bit multiply on most
64-bit machines, you need a little bit of inline asm for that. (I know that GCC
has a builtin for umulh on Alpha, but AFAIK doesn't have similiar builtins for
other 64-bit machines that have this type of instruction).
Of course hand-tuned assembly can be faster than compiler produced code through
a wide variety of tricks (take a look at some of the MPI asm in GNU MP and
OpenSSL, people have come up with some pretty smart/scary techniques for
writing MPI code in asm). There is no algorithmic advantage, though.
Given a sufficiently smart compiler, C code should be able to take advantage of
available machine resources/abilities (like how ICC will generate MMX or SSE
code if you write your scalar-based loops right). However, not all compilers
are sufficiently smart. :)
Of course for things that C just doesn't have the concept of (rings, sync
primitives, etc), asm is the only game in town.
-Jack