public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* An i386 fp register name patch
@ 1999-08-27 12:18 H.J. Lu
  1999-08-28  6:05 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 1999-08-27 12:18 UTC (permalink / raw)
  To: binutils

Here is a patch to handle spaces ina i386 FP register names. I am
enclosing a testcase here.

----
	fxch   %st( 1)
	fxch   %st( 1 )
	fxch   %st ( 1 )
	fxch   %st (1)
	fxch   %st(1)
	fxch   % st(1)
	fxch   %           st(1)
----

Thanks.

-- 
H.J. Lu (hjl@gnu.org)
--
Fri Aug 27 11:31:30 1999  H.J. Lu  (hjl@gnu.org)

	* config/tc-i386.c (i386_extract_reg): New function. Handle
	spaces in FP register names.
	(i386_is_reg): Use it.
	(parse_register): Likewise.

Index: config/tc-i386.c
===================================================================
RCS file: /work/cvs/gnu/binutils/gas/config/tc-i386.c,v
retrieving revision 1.5
diff -u -p -r1.5 tc-i386.c
--- config/tc-i386.c	1999/08/21 18:02:59	1.5
+++ config/tc-i386.c	1999/08/27 18:24:16
@@ -2507,25 +2507,57 @@ md_assemble (line)
   }
 }
 \f
+static char * i386_extract_reg PARAMS ((char *, char *, int));
+
+static char *
+i386_extract_reg (s, reg, len)
+     char *s;
+     char *reg;
+     int len;
+{
+  register char *p;
+
+  while (is_space_char (*s))
+    ++s;
+
+  p = reg;
+  while (register_chars[(unsigned char) *s] != '\0'
+	  || is_space_char (*s))
+    {
+      if (p >= &reg [2] && tolower (reg [0]) == 's'
+	  && tolower (reg [1]) == 't'
+	  && (p == &reg [2]
+	      || (reg [2] == '('
+		  && (p == &reg [3]
+		      || (*(p - 1) >= '0' && *(p - 1) <= '9')))))
+	/*
+	  1. %st (1).
+	  2. %st ( 1).
+	  3. %st ( 1 ).
+	*/
+      while (is_space_char (*s))
+	++s;
+
+      if ((*p++ = register_chars[(unsigned char) *s++]) == '\0')
+        break;
+      if (p >= reg + len)
+        return NULL;
+    }
+
+  *p++ = register_chars[(unsigned char) *s++];
+  return (p >= reg + len) ? NULL: s;
+}
+
 static int i386_is_reg PARAMS ((char *));
 
 static int
 i386_is_reg (reg_string)
      char *reg_string;
 {
-  register char *s = reg_string;
-  register char *p;
   char reg_name_given[MAX_REG_NAME_SIZE + 1];
-
-  if (is_space_char (*s))
-    ++s;
 
-  p = reg_name_given;
-  while ((*p++ = register_chars[(unsigned char) *s++]) != '\0')
-    if (p >= reg_name_given + MAX_REG_NAME_SIZE)
-      return 0;
-
-  if (!hash_find (reg_hash, reg_name_given))
+  if (!i386_extract_reg (reg_string, reg_name_given, MAX_REG_NAME_SIZE)
+      || !hash_find (reg_hash, reg_name_given))
     return 0;
   else
     return 1;
@@ -4137,7 +4169,6 @@ parse_register (reg_string, end_op)
      char **end_op;
 {
   register char *s = reg_string;
-  register char *p;
   char reg_name_given[MAX_REG_NAME_SIZE + 1];
   const reg_entry *r;
 
@@ -4145,23 +4176,16 @@ parse_register (reg_string, end_op)
   if (*s == REGISTER_PREFIX)
     ++s;
 
-  if (is_space_char (*s))
-    ++s;
-
-  p = reg_name_given;
-  while ((*p++ = register_chars[(unsigned char) *s++]) != '\0')
+  s = i386_extract_reg (s, reg_name_given, MAX_REG_NAME_SIZE);
+  if (s == NULL)
     {
-      if (p >= reg_name_given + MAX_REG_NAME_SIZE)
+      if (!allow_naked_reg)
 	{
-	  if (!allow_naked_reg)
-	    {
-	      *p = '\0';
-	      as_bad (_("bad register name `%s'"), reg_name_given);
-	    }
-	  return (const reg_entry *) NULL;
+	  reg_name_given [MAX_REG_NAME_SIZE] = '\0';
+	  as_bad (_("bad register name `%s'"), reg_name_given);
 	}
+      return (const reg_entry *) NULL;
     }
-
   *end_op = s - 1;
 
   r = (const reg_entry *) hash_find (reg_hash, reg_name_given);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: An i386 fp register name patch
  1999-08-27 12:18 An i386 fp register name patch H.J. Lu
@ 1999-08-28  6:05 ` Alan Modra
  1999-08-28  8:38   ` H.J. Lu
  1999-08-29 14:05   ` Ian Lance Taylor
  0 siblings, 2 replies; 4+ messages in thread
From: Alan Modra @ 1999-08-28  6:05 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Fri, 27 Aug 1999, H.J. Lu wrote:

> Here is a patch to handle spaces ina i386 FP register names. I am
> enclosing a testcase here.

Hello HJ,
  As you probably know, we already allow spaces in lots of places.  eg.
	mov % al , 5 ( % ebp , % ebx , 1 )
Notice that no spaces are allowed *in* a register name, or for that
matter in an instruction mnemonic.  eg.
	mov $1, % a l
is illegal.

So there is a philosophical question as to whether "st(1)" is really an
indivisible register name token or not.  You seem to say that the register
name is "st" with an index, so therefore we should allow spaces, eg.
"st ( 1 )".  I'm inclined to say that "st(1)" is really just a name like
any other register name, so spaces shouldn't be allowed (or if we do
allow spaces here then why not in "% a l" - something I don't like).

Where did you run into a need for spaces in fp reg names?  C asm macros?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: An i386 fp register name patch
  1999-08-28  6:05 ` Alan Modra
@ 1999-08-28  8:38   ` H.J. Lu
  1999-08-29 14:05   ` Ian Lance Taylor
  1 sibling, 0 replies; 4+ messages in thread
From: H.J. Lu @ 1999-08-28  8:38 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

> 
> 
> On Fri, 27 Aug 1999, H.J. Lu wrote:
> 
> > Here is a patch to handle spaces ina i386 FP register names. I am
> > enclosing a testcase here.
> 
> Hello HJ,
>   As you probably know, we already allow spaces in lots of places.  eg.
> 	mov % al , 5 ( % ebp , % ebx , 1 )
> Notice that no spaces are allowed *in* a register name, or for that
> matter in an instruction mnemonic.  eg.
> 	mov $1, % a l
> is illegal.
> 
> So there is a philosophical question as to whether "st(1)" is really an
> indivisible register name token or not.  You seem to say that the register
> name is "st" with an index, so therefore we should allow spaces, eg.
> "st ( 1 )".  I'm inclined to say that "st(1)" is really just a name like
> any other register name, so spaces shouldn't be allowed (or if we do
> allow spaces here then why not in "% a l" - something I don't like).
> 
> Where did you run into a need for spaces in fp reg names?  C asm macros?
> 
> 

I got a report from Mesa people. FWIW, assembler on Solaris &/x86 takes

        fxch   %st( 1) 
        fxch   %st( 1 )
        fxch   %st ( 1 )
        fxch   %st (1) 
        fxch   %st(1)  

But not

        fxch   % st(1) 
        fxch   %           st(1)   

I got

# cat foo.s
        fxch   %st( 1)
        fxch   %st( 1 )
        fxch   %st ( 1 )
        fxch   %st (1)
        fxch   %st(1)
        fxch   % st(1)
        fxch   %           st(1)
# /usr/ccs/bin/as -o foo.o foo.s 
Assembler: 
        aline 6 : Illegal register
        aline 6 : syntax error
        aline 7 : Illegal register
        aline 7 : syntax error

It looks like gas has some extensions, but doesn't have features
supported by other x86 assemblers. In any case, I will support it
in the Linux version of binutils.

-- 
H.J. Lu (hjl@gnu.org)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: An i386 fp register name patch
  1999-08-28  6:05 ` Alan Modra
  1999-08-28  8:38   ` H.J. Lu
@ 1999-08-29 14:05   ` Ian Lance Taylor
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 1999-08-29 14:05 UTC (permalink / raw)
  To: alan; +Cc: hjl, binutils

   Date: Sat, 28 Aug 1999 22:34:51 +0930 (CST)
   From: Alan Modra <alan@SPRI.Levels.UniSA.Edu.Au>

     As you probably know, we already allow spaces in lots of places.  eg.
	   mov % al , 5 ( % ebp , % ebx , 1 )
   Notice that no spaces are allowed *in* a register name, or for that
   matter in an instruction mnemonic.  eg.
	   mov $1, % a l
   is illegal.

   So there is a philosophical question as to whether "st(1)" is really an
   indivisible register name token or not.  You seem to say that the register
   name is "st" with an index, so therefore we should allow spaces, eg.
   "st ( 1 )".  I'm inclined to say that "st(1)" is really just a name like
   any other register name, so spaces shouldn't be allowed (or if we do
   allow spaces here then why not in "% a l" - something I don't like).

While philosophically %st(1) is a single register name, I think that
given the format of the name we should allow spaces around the
parenthesis.  ``Be liberal in what you accept.''

On the other hand, I don't think we should accept "% a l".  That just
seems too error prone.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-08-29 14:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-27 12:18 An i386 fp register name patch H.J. Lu
1999-08-28  6:05 ` Alan Modra
1999-08-28  8:38   ` H.J. Lu
1999-08-29 14:05   ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).