This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] asm goto



In the initial thread(s) about this problem there was some alternate
syntax modelled after __builtin_expect, ala:

   if (__builtin_newname(ID))
     { do tracing stuff }
   [else
      { do non-tracing stuff } ]
   { do common stuff }

where internally that __builtin_newname would do essentially the above
asm magic.  It would be nice if something like this syntax could be
implemented with asm gotos but I don't immediately see how, due to the
need of the artificial label.

You can do something almost equivalent:


#ifdef DO_TRACE
#define IF_TRACE()      if (({ goto trace; 0; })) ; else if (0) trace:
#else
#define IF_TRACE()      if (({ 0; })) ; else if (0) trace:
#endif

int main()
{
        IF_TRACE()
                puts ("trace");
        else
                puts ("notrace");

        puts ("common");
}

which would give (untested of course):

#define IF_TRACE(ID, NUM)                   \
  if (({                                    \
    asm goto ("0: nop;"                     \
              ".pushsection trace_table;"   \
              ".long 0b, %l0;"              \
              ".popsection"                 \
             : : : : trace##NUM);           \
    0;                                      \
  })) ; else if (0) trace##NUM:

I don't think I ever wrote anything this ugly.

Paolo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]