Browse Source

* fix the FDIV FDIVR FSUB FSUBR and popping equivalent
simply by swapping from reverse to normal and vice-versa
when passing from one syntax to the other !

pierre 25 years ago
parent
commit
5f4ec1b1ff
5 changed files with 104 additions and 5 deletions
  1. 8 1
      compiler/ag386int.pas
  2. 8 1
      compiler/ag386nsm.pas
  3. 40 1
      compiler/cpuasm.pas
  4. 40 1
      compiler/ra386.pas
  5. 8 1
      compiler/ra386int.pas

+ 8 - 1
compiler/ag386int.pas

@@ -482,6 +482,8 @@ unit ag386int;
     ait_symbol_end : begin
                      end;
    ait_instruction : begin
+                     { Must be done with args in ATT order }
+                       paicpu(hp)^.CheckNonCommutativeOpcodes;
                      { We need intel order, no At&t }
                        paicpu(hp)^.SwapOperands;
                      { Reset }
@@ -643,7 +645,12 @@ ait_stab_function_name : ;
 end.
 {
   $Log$
-  Revision 1.61  2000-05-09 21:44:27  pierre
+  Revision 1.62  2000-05-12 21:26:22  pierre
+    * fix the FDIV FDIVR FSUB FSUBR and popping equivalent
+      simply by swapping from reverse to normal and vice-versa
+      when passing from one syntax to the other !
+
+  Revision 1.61  2000/05/09 21:44:27  pierre
     * add .byte 066h to force correct pushw %es
     * handle push es as a pushl %es
 

+ 8 - 1
compiler/ag386nsm.pas

@@ -627,6 +627,8 @@ unit ag386nsm;
 
            ait_instruction :
              begin
+             { Must be done with args in ATT order }
+               paicpu(hp)^.CheckNonCommutativeOpcodes;
              { We need intel order, no At&t }
                paicpu(hp)^.SwapOperands;
              { Reset
@@ -764,7 +766,12 @@ unit ag386nsm;
 end.
 {
   $Log$
-  Revision 1.58  2000-05-09 21:44:27  pierre
+  Revision 1.59  2000-05-12 21:26:22  pierre
+    * fix the FDIV FDIVR FSUB FSUBR and popping equivalent
+      simply by swapping from reverse to normal and vice-versa
+      when passing from one syntax to the other !
+
+  Revision 1.58  2000/05/09 21:44:27  pierre
     * add .byte 066h to force correct pushw %es
     * handle push es as a pushl %es
 

+ 40 - 1
compiler/cpuasm.pas

@@ -114,6 +114,7 @@ type
      function  getcopy:plinkedlist_item;virtual;
      function  GetString:string;
      procedure SwapOperands;
+     procedure CheckNonCommutativeOpcodes;
   private
      segprefix : tregister;
      procedure init(op : tasmop;_size : topsize); { this need to be called by all constructor }
@@ -678,6 +679,39 @@ uses
         end;
       end;
 
+{ This check must be done with the operand in ATT order
+  i.e.after swapping in the intel reader
+  but before swapping in the NASM and TASM writers PM }
+procedure taicpu.CheckNonCommutativeOpcodes;
+begin
+  if ((ops=2) and
+     (oper[0].typ=top_reg) and
+     (oper[1].typ=top_reg) and
+     { if the first is ST and the second is also a register
+       it is necessarily ST1 .. ST7 }
+     (oper[0].reg=R_ST)) or
+     ((ops=1) and
+      (oper[0].typ=top_reg) and
+      (oper[0].reg in [R_ST1..R_ST7])) or
+     (ops=0) then
+      if opcode=A_FSUBR then
+        opcode:=A_FSUB
+      else if opcode=A_FSUB then
+        opcode:=A_FSUBR
+      else if opcode=A_FDIVR then
+        opcode:=A_FDIV
+      else if opcode=A_FDIV then
+        opcode:=A_FDIVR
+      else if opcode=A_FSUBRP then
+        opcode:=A_FSUBP
+      else if opcode=A_FSUBP then
+        opcode:=A_FSUBRP
+      else if opcode=A_FDIVRP then
+        opcode:=A_FDIVP
+      else if opcode=A_FDIVP then
+        opcode:=A_FDIVRP;
+end;
+
 
 {*****************************************************************************
                                 Assembler
@@ -1613,7 +1647,12 @@ end;
 end.
 {
   $Log$
-  Revision 1.13  2000-05-09 14:12:35  pierre
+  Revision 1.14  2000-05-12 21:26:22  pierre
+    * fix the FDIV FDIVR FSUB FSUBR and popping equivalent
+      simply by swapping from reverse to normal and vice-versa
+      when passing from one syntax to the other !
+
+  Revision 1.13  2000/05/09 14:12:35  pierre
    * fix for test/testpusw problem
 
   Revision 1.12  2000/02/09 13:22:51  peter

+ 40 - 1
compiler/ra386.pas

@@ -45,6 +45,7 @@ type
     procedure AddReferenceSizes;
     procedure SetInstructionOpsize;
     procedure CheckOperandSizes;
+    procedure CheckNonCommutativeOpcodes;
     { opcode adding }
     procedure ConcatInstruction(p : paasmoutput);virtual;
   end;
@@ -329,6 +330,39 @@ begin
 end;
 
 
+{ This check must be done with the operand in ATT order
+  i.e.after swapping in the intel reader
+  but before swapping in the NASM and TASM writers PM }
+procedure T386Instruction.CheckNonCommutativeOpcodes;
+begin
+  if ((ops=2) and
+     (operands[1]^.opr.typ=OPR_REGISTER) and
+     (operands[2]^.opr.typ=OPR_REGISTER) and
+     { if the first is ST and the second is also a register
+       it is necessarily ST1 .. ST7 }
+     (operands[1]^.opr.reg=R_ST)) or
+     ((ops=1) and
+      (operands[1]^.opr.typ=OPR_REGISTER) and
+      (operands[1]^.opr.reg in [R_ST1..R_ST7])) or
+      (ops=0)  then
+      if opcode=A_FSUBR then
+        opcode:=A_FSUB
+      else if opcode=A_FSUB then
+        opcode:=A_FSUBR
+      else if opcode=A_FDIVR then
+        opcode:=A_FDIV
+      else if opcode=A_FDIV then
+        opcode:=A_FDIVR
+      else if opcode=A_FSUBRP then
+        opcode:=A_FSUBP
+      else if opcode=A_FSUBP then
+        opcode:=A_FSUBRP
+      else if opcode=A_FDIVRP then
+        opcode:=A_FDIVP
+      else if opcode=A_FDIVP then
+        opcode:=A_FDIVRP;
+end;
+
 {*****************************************************************************
                               opcode Adding
 *****************************************************************************}
@@ -380,7 +414,12 @@ end;
 end.
 {
   $Log$
-  Revision 1.16  2000-05-10 08:55:08  pierre
+  Revision 1.17  2000-05-12 21:26:22  pierre
+    * fix the FDIV FDIVR FSUB FSUBR and popping equivalent
+      simply by swapping from reverse to normal and vice-versa
+      when passing from one syntax to the other !
+
+  Revision 1.16  2000/05/10 08:55:08  pierre
    * no warning nor error for pushl of segment register
 
   Revision 1.15  2000/05/09 21:44:28  pierre

+ 8 - 1
compiler/ra386int.pas

@@ -1772,6 +1772,8 @@ Begin
           instr.BuildOpcode;
           { We need AT&T style operands }
           instr.SwapOperands;
+          { Must be done with args in ATT order }
+          instr.CheckNonCommutativeOpcodes;
           instr.AddReferenceSizes;
           instr.SetInstructionOpsize;
           instr.CheckOperandSizes;
@@ -1826,7 +1828,12 @@ begin
 end.
 {
   $Log$
-  Revision 1.67  2000-05-11 09:56:21  pierre
+  Revision 1.68  2000-05-12 21:26:23  pierre
+    * fix the FDIV FDIVR FSUB FSUBR and popping equivalent
+      simply by swapping from reverse to normal and vice-versa
+      when passing from one syntax to the other !
+
+  Revision 1.67  2000/05/11 09:56:21  pierre
     * fixed several compare problems between longints and
       const > $80000000 that are treated as int64 constanst
       by Delphi reported by Kovacs Attila Zoltan