Browse Source

+ search optimial register to use in alignment code (compile with
-dalignreg, -dalignregdebug to see chosen register in
assembler code). Still needs support in ag386bin.

Jonas Maebe 26 years ago
parent
commit
d70b3211a4
2 changed files with 58 additions and 25 deletions
  1. 49 24
      compiler/csopt386.pas
  2. 9 1
      compiler/symtable.pas

+ 49 - 24
compiler/csopt386.pas

@@ -53,6 +53,7 @@ Begin
   PaiInSequence := TmpResult;
   PaiInSequence := TmpResult;
 End;
 End;
 }
 }
+
 Function CheckSequence(p: Pai; Reg: TRegister; Var Found: Longint; Var RegInfo: TRegInfo): Boolean;
 Function CheckSequence(p: Pai; Reg: TRegister; Var Found: Longint; Var RegInfo: TRegInfo): Boolean;
 {checks whether the current instruction sequence (starting with p) and the
 {checks whether the current instruction sequence (starting with p) and the
  one between StartMod and EndMod of Reg are the same. If so, the number of
  one between StartMod and EndMod of Reg are the same. If so, the number of
@@ -240,6 +241,7 @@ End;
 
 
 {$ifdef alignreg}
 {$ifdef alignreg}
 Procedure SetAlignReg(p: Pai);
 Procedure SetAlignReg(p: Pai);
+Const alignSearch = 12;
 var regsUsable: TRegSet;
 var regsUsable: TRegSet;
     prevInstrCount, nextInstrCount: Longint;
     prevInstrCount, nextInstrCount: Longint;
     prevState, nextWState,nextRState: Array[R_EAX..R_EDI] of byte;
     prevState, nextWState,nextRState: Array[R_EAX..R_EDI] of byte;
@@ -263,18 +265,29 @@ begin
   prevInstrCount := 0;
   prevInstrCount := 0;
   while ((assigned(prev) and
   while ((assigned(prev) and
           assigned(prev^.optInfo) and
           assigned(prev^.optInfo) and
-          (prevInstrCount < 10)) or
+          (prevInstrCount < alignSearch)) or
          (assigned(next) and
          (assigned(next) and
           assigned(next^.optInfo) and
           assigned(next^.optInfo) and
-          (nextInstrCount < 10))) And
-        (regsUsable <> []) Do
+          (nextInstrCount < alignSearch))) And
+        (regsUsable <> []) do
     begin
     begin
+{$ifdef alignregdebug}
+      if assigned(prev) then
+        begin
+          temp := new(pai_asm_comment,init(strpnew('got here')));
+          temp^.next := prev^.next;
+          temp^.previous := prev;
+          prev^.next := temp;
+          if assigned(temp^.next) then
+            temp^.next^.previous := temp;
+        end;
+{$endif alignregdebug}
       if assigned(prev) and assigned(prev^.optinfo) and
       if assigned(prev) and assigned(prev^.optinfo) and
-         (prevInstrCount < 10) then
+         (prevInstrCount < alignSearch) then
         begin
         begin
           if (prev^.typ = ait_instruction) And
           if (prev^.typ = ait_instruction) And
              (insProp[PaiCpu(prev)^.opcode].ch[1] <> Ch_ALL) and
              (insProp[PaiCpu(prev)^.opcode].ch[1] <> Ch_ALL) and
-             (PaiCpu(prev)^.opcode <> a_jmp) then
+             (PaiCpu(prev)^.opcode <> A_JMP) then
             begin
             begin
               inc(prevInstrCount);
               inc(prevInstrCount);
               for regCounter := R_EAX to R_EDI do
               for regCounter := R_EAX to R_EDI do
@@ -285,7 +298,14 @@ begin
                     begin
                     begin
                       lastRemoved := regCounter;
                       lastRemoved := regCounter;
                       exclude(regsUsable,regCounter);
                       exclude(regsUsable,regCounter);
-  {$ifdef alignregdebug}
+{$ifdef alignregdebug}
+                      temp := new(pai_asm_comment,init(strpnew(
+                                att_reg2str[regCounter]+' removed')));
+                      temp^.next := prev^.next;
+                      temp^.previous := prev;
+                      prev^.next := temp;
+                      if assigned(temp^.next) then
+                        temp^.next^.previous := temp;
                       if regsUsable = [] then
                       if regsUsable = [] then
                         begin
                         begin
                           temp := new(pai_asm_comment,init(strpnew(
                           temp := new(pai_asm_comment,init(strpnew(
@@ -296,24 +316,26 @@ begin
                           if assigned(temp^.next) then
                           if assigned(temp^.next) then
                             temp^.next^.previous := temp;
                             temp^.next^.previous := temp;
                         end;
                         end;
-  {$endif alignregdebug}
+{$endif alignregdebug}
                     end;
                     end;
                   prevState[regCounter] :=
                   prevState[regCounter] :=
                     PPaiProp(prev^.optInfo)^.Regs[regCounter].wState;
                     PPaiProp(prev^.optInfo)^.Regs[regCounter].wState;
-                end
+                end;
+              getLastInstruction(prev,prev);
             end
             end
           else
           else
-            for regCounter := R_EAX to R_EDI do
-              prevState[regCounter] :=
-                PPaiProp(prev^.optInfo)^.Regs[regCounter].wState;
-          getLastInstruction(prev,prev);
+            If GetLastInstruction(prev,prev) and
+               assigned(prev^.optinfo) then
+              for regCounter := R_EAX to R_EDI do
+                prevState[regCounter] :=
+                  PPaiProp(prev^.optInfo)^.Regs[regCounter].wState
         end;
         end;
       if assigned(next) and assigned(next^.optInfo) and
       if assigned(next) and assigned(next^.optInfo) and
-         (nextInstrCount < 10) then
+         (nextInstrCount < alignSearch) then
         begin
         begin
           if (next^.typ = ait_instruction) and
           if (next^.typ = ait_instruction) and
              (insProp[PaiCpu(next)^.opcode].ch[1] <> Ch_ALL) and
              (insProp[PaiCpu(next)^.opcode].ch[1] <> Ch_ALL) and
-             (PaiCpu(next)^.opcode <> a_jmp) then
+             (PaiCpu(next)^.opcode <> A_JMP) then
             begin
             begin
               inc(nextInstrCount);
               inc(nextInstrCount);
               for regCounter := R_EAX to R_EDI do
               for regCounter := R_EAX to R_EDI do
@@ -327,6 +349,13 @@ begin
                       lastRemoved := regCounter;
                       lastRemoved := regCounter;
                       exclude(regsUsable,regCounter);
                       exclude(regsUsable,regCounter);
 {$ifdef alignregdebug}
 {$ifdef alignregdebug}
+                      temp := new(pai_asm_comment,init(strpnew(
+                                att_reg2str[regCounter]+' removed')));
+                      temp^.next := next^.next;
+                      temp^.previous := next;
+                      next^.next := temp;
+                      if assigned(temp^.next) then
+                        temp^.next^.previous := temp;
                       if regsUsable = [] then
                       if regsUsable = [] then
                         begin
                         begin
                           temp := new(pai_asm_comment,init(strpnew(
                           temp := new(pai_asm_comment,init(strpnew(
@@ -360,15 +389,6 @@ begin
     for regCounter := R_EAX to R_EDI do
     for regCounter := R_EAX to R_EDI do
       if regCounter in regsUsable then
       if regCounter in regsUsable then
         begin
         begin
-{$ifdef alignregdebug}
-          next := new(pai_asm_comment,init(strpnew('regsusable not empty')));
-          next^.next := p^.next;
-          next^.previous := p;
-          p^.next := next;
-          if assigned(next^.next) then
-            next^.next^.previous := next;
-{$endif alignregdebug}
-
           lastRemoved := regCounter;
           lastRemoved := regCounter;
           break
           break
         end;
         end;
@@ -681,7 +701,12 @@ End.
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.30  1999-11-06 14:34:20  peter
+ Revision 1.31  1999-11-06 16:21:57  jonas
+   + search optimial register to use in alignment code (compile with
+     -dalignreg, -dalignregdebug to see chosen register in
+     assembler code). Still needs support in ag386bin.
+
+ Revision 1.30  1999/11/06 14:34:20  peter
    * truncated log to 20 revs
    * truncated log to 20 revs
 
 
  Revision 1.29  1999/11/05 16:01:46  jonas
  Revision 1.29  1999/11/05 16:01:46  jonas

+ 9 - 1
compiler/symtable.pas

@@ -445,6 +445,9 @@ implementation
 {$ifdef BrowserLog}
 {$ifdef BrowserLog}
      ,browlog
      ,browlog
 {$endif BrowserLog}
 {$endif BrowserLog}
+{$ifdef alignreg}
+     ,cpuasm
+{$endif alignreg}
      ;
      ;
 
 
   var
   var
@@ -2465,7 +2468,12 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.58  1999-11-06 14:34:28  peter
+  Revision 1.59  1999-11-06 16:21:57  jonas
+    + search optimial register to use in alignment code (compile with
+      -dalignreg, -dalignregdebug to see chosen register in
+      assembler code). Still needs support in ag386bin.
+
+  Revision 1.58  1999/11/06 14:34:28  peter
     * truncated log to 20 revs
     * truncated log to 20 revs
 
 
   Revision 1.57  1999/11/05 17:18:03  pierre
   Revision 1.57  1999/11/05 17:18:03  pierre