patch: inline asm functionality: which_alternative %% command

Dylan_S_Cuthbert@hq.scei.sony.co.jp Dylan_S_Cuthbert@hq.scei.sony.co.jp
Mon Jun 12 02:58:00 GMT 2000


I'm not working in a regular gcc environment so I haven't been able to test this
with any version of the compiler other than the one I am using which isn't
public domain (due to NDA reasons).

It works with absolutely no problems on the "gcc version 2.9-ee-991111" version
of gcc that I am using.

It is such a simple addition that I grabbed the latest 2.9.2 version from
gnu.org, made my changes and have produced the diff below:

Please could someone look at the change, re-write it (thus transferring
"ownership" and avoiding legalities) and apply and test it against the latest
version of the compiler please.

The reasons for the change are as follows: (snipped from thread in
gcc@gcc.gnu.org)

---
Currently, the gcc inline "asm" instruction supports "alternative"
constraints for the operands supplied which is a great idea to help the
compiler optimize for commands it can't even see.

Unfortunately, this rather useful feature is fundamentally flawed in its
current implementation.  This part of asm's *functionality* is
"machine-dependent", in fact, it is worse than that!  It is assembler
mnemonic dependent!  So much so, that this very nice feature is *completely*
unusable for MIPS processors as far as I can see.

It relies too much on the assembler's mnemonic format being able to take
arguments of different types.  This is way too arbitrary for such a generic
and otherwise multi-platform compiler such as gcc. (IMHO)

I think we need to give inline assembler programmers (who have a hard enough
time as it is) the ability to use the fastest "alternative" the compiler has
calculated it can provide, regardless of what processor they are working
with.

eg. Using %An equates to 1 if alternative "n" was chosen by the compiler, and to
 zero
if it wasn't, meaning programmers can use standard ".if" and ".else" type
constructs
to generate the exact mnemonic required for the operands.
---

Bear in mind, I don't think %A is a suitable character to use because a-z,A-Z
seem to have a historical assignment to target options, however, I just didn't
know what characters are generally in use so I thought it best to leave it up to
someone who does.

Please include this patch as it really helps programmers who have no choice
regarding "hitting the metal" but still want gcc to help them as much as
possible.

Regards

Dylan Cuthbert
(all views are mine and noone else's, etc etc...)


cvs diff -c3p final.c newfinal.c:

--- snip ---

*** final.c     Tue Jun 22 08:21:23 1999
--- newfinal.c  Mon Jun 12 18:32:38 2000
*************** final_scan_insn (insn, file, optimize, p
*** 2540,2545 ****
--- 2540,2552 ----
            /* Get out the operand values.  */
            string = decode_asm_operands (body, ops, NULL_PTR,
                                          NULL_PTR, NULL_PTR);
+
+             /* we've lost "which_alternative" because of instructions
+                used to load up the operands for the asm statement but %A
+                needs it, so run through the operands one last time */
+
+             check_asm_operands( body );
+
            /* Inhibit aborts on what would otherwise be compiler bugs.  */
            insn_noperands = noperands;
            this_is_asm_operands = insn;
*************** output_asm_insn (template, operands)
*** 3419,3426 ****
  #endif

        case '%':
        /* %% outputs a single %.  */
!       if (*p == '%')
          {
            p++;
            putc (c, asm_out_file);
--- 3426,3447 ----
  #endif

        case '%':
+
+         /* %An outputs either a zero (false) or 1 (true) depending on
+            whether which_alternative == n */
+         if (*p == 'A')
+           {
+             p++;
+             c = atoi(p);
+             if (! (*p >= '0' && *p <= '9') || c > 9)
+               output_operand_lossage ("alternative identifier invalid");
+             else
+               fputc( (which_alternative == c)?'1':'0', asm_out_file );
+             p++;
+           }
+
        /* %% outputs a single %.  */
!       else if (*p == '%')
          {
            p++;
            putc (c, asm_out_file);

--- snip ---




More information about the Gcc-patches mailing list