This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: Feature request: Set the direction flag on x86/x64 register->register operations


On Thu, Dec 18, 2008 at 9:16 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Dec 9, 2008 at 4:51 AM, Stefan Dösinger <stefan@codeweavers.com> wrote:
>> Hi,
>>
>> Here is another version of my patch to set the direction flag on
>> register->register operations.
>>
>> The main change is that it is now controlled by a per-instruction suffix
>> instead of a command line switch. Alexandre Julliard didn't like the idea of
>> the command line switch, he prefers gcc to control the bit. I have to modify
>> gcc to make it generate a "movl %edi, %edi" like Windows has it anyway, so
>> going this route is ok for me.
>>
>> I added a test for this feature which specifically tests the instructions
>> that are important to me(mov %edi, %edi and mov %esp, %ebp) and a few more.
>> I ran the existing tests with the flag forced on for all instructions, and
>> they pass. There are a few false positives obviously because the patch
>> changes the encoding, but I checked all of those cases and the code works
>> correctly.
>>
>> I verified the behavior against msvc, and it does set the flag on 8, 16 and
>> 32 bit operations for sure. I didn't check 64 bit ones because I do not have
>> a 64 bit Windows installation to test, but this is moot now anyway because
>> gcc controls the flag. It doesn't affect this patch any longer.
>>
>
> Please use "movl.r" instead of "movlr".

That is what I have in mind:

--- ./tc-i386.c.reverse	2008-12-12 11:24:10.000000000 -0800
+++ ./tc-i386.c	2008-12-18 10:44:52.000000000 -0800
@@ -228,6 +228,10 @@ struct _i386_insn
     /* TM holds the template for the insn were currently assembling.  */
     template tm;

+    /* MATCH holds insn match options.  */
+    unsigned int options;
+#define OPTION_REVERSE_DIRECTION_BIT	1
+
     /* SUFFIX holds the instruction size suffix for byte, word, dword
        or qword, if given.  */
     char suffix;
@@ -2990,6 +2994,21 @@ parse_insn (char *line, char *mnemonic)

   if (!current_templates)
     {
+      /* Check match options.  */
+      if (mnem_p[-2] == '.')
+	{
+	  if (mnem_p[-1] == 'r')
+	    i.options |= OPTION_REVERSE_DIRECTION_BIT;
+	  else
+	    goto check_suffix;
+	  mnem_p[-2] = '\0';
+	  current_templates = hash_find (op_hash, mnemonic);
+	}
+    }
+
+  if (!current_templates)
+    {
+check_suffix:
       /* See if we can get a match by trimming off a suffix.  */
       switch (mnem_p[-1])
 	{
@@ -3712,6 +3731,11 @@ match_template (void)
 	      && operand_type_equal (&i.types [0], &acc32)
 	      && operand_type_equal (&i.types [1], &acc32))
 	    continue;
+	  if ((i.options & OPTION_REVERSE_DIRECTION_BIT) != 0
+	      && (t->opcode_modifier.d
+		  || t->opcode_modifier.floatd))
+	    goto reverse;
+
 	case 3:
 	case 4:
 	case 5:
@@ -3728,6 +3752,7 @@ match_template (void)
 	      if (!t->opcode_modifier.d && !t->opcode_modifier.floatd)
 		continue;

+reverse:
 	      /* Try reversing direction of operands.  */
 	      overlap0 = operand_type_and (i.types[0], operand_types[1]);
 	      overlap1 = operand_type_and (i.types[1], operand_types[0]);

Will it work for you?


-- 
H.J.


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