[cfe-dev] AT&T inline assembly macros

Mark Schimmel Mark.Schimmel at synopsys.com
Wed Jul 24 16:43:13 PDT 2013


I would like to add support for AT&T style ASM macros to Clang, but
this will be my first experience changing Clang.  Would anybody
volunteer to exchange email related to this topic?  I'd like it if
someone could steer me back to the right course if I head down the
wrong path.

There are some unfortunate "features" in asm macros.  For instance
they don't lex the same as C.  What constitutes a token in C isn't
necessarily the same in assembly.  Another issue is how asm macros
"return" a result.  In the following example the result is "returned"
by writing to the ABI integer result register.

However, one might argue that ASM macros are easier to read than GNU
style inline assembly.


Here's a link that defines AT&T style ASM macros:
http://www.vxdev.com/docs/vx55man/diab5.0ppc/c-embed_.htm#2999814


An ASM macro behaves similarly to a preprocessor macro.  It's expanded
(or inlined) at the call site.  Example:

__asm__ int f(int x) {
%reg x
!"r0"
        add r0,x,x
}

int y(int p) {
    return f(p);
}

This would be similar to the GNU asm:

int y(int x) {
    register int result;
    asm ("add %0,%1,%1"
                :"=r" (result)      /*output*/
                : "r" (x) /*input*/
                );
    return result;
}

Thanks in advance

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130724/07aeb330/attachment.html>


More information about the cfe-dev mailing list