aoptcpu.pas 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. {
  2. Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
  3. Development Team
  4. This unit implements the PowerPC optimizer object
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. Unit aoptcpu;
  19. Interface
  20. {$i fpcdefs.inc}
  21. uses cpubase, aoptobj, aoptcpub, aopt, aasmtai;
  22. Type
  23. TCpuAsmOptimizer = class(TAsmOptimizer)
  24. { uses the same constructor as TAopObj }
  25. function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
  26. End;
  27. Implementation
  28. uses
  29. cutils, aasmcpu;
  30. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  31. var
  32. next1, next2: tai;
  33. l1, l2: longint;
  34. begin
  35. result := false;
  36. case p.typ of
  37. ait_instruction:
  38. begin
  39. case taicpu(p).opcode of
  40. A_RLWINM:
  41. begin
  42. if getnextinstruction(p,next1) and
  43. (next1.typ = ait_instruction) and
  44. (taicpu(next1).opcode = A_RLWINM) and
  45. (taicpu(next1).oper[0]^.reg = taicpu(p).oper[0]^.reg) and
  46. // both source and target of next1 must equal target of p
  47. (taicpu(next1).oper[1]^.reg = taicpu(p).oper[0]^.reg) and
  48. (taicpu(next1).oper[2]^.val = 0) then
  49. begin
  50. l1 := taicpu(p).oper[4]^.val;
  51. if (l1 < taicpu(p).oper[3]^.val) then
  52. inc(l1,32);
  53. l2 := taicpu(next1).oper[4]^.val;
  54. if (l2 < taicpu(next1).oper[3]^.val) then
  55. inc(l2,32);
  56. if (taicpu(p).oper[3]^.val > l2) or
  57. (taicpu(next1).oper[3]^.val > l1) then
  58. begin
  59. // masks have no bits in common
  60. taicpu(p).opcode := A_LI;
  61. taicpu(p).loadconst(1,0);
  62. taicpu(p).clearop(2);
  63. taicpu(p).clearop(3);
  64. taicpu(p).clearop(4);
  65. end
  66. else
  67. begin
  68. taicpu(p).oper[3]^.val := max(taicpu(p).oper[3]^.val,taicpu(next1).oper[3]^.val);
  69. taicpu(p).oper[4]^.val := min(taicpu(p).oper[4]^.val,taicpu(next1).oper[4]^.val);
  70. end;
  71. asml.remove(next1);
  72. next1.free;
  73. end;
  74. end;
  75. end;
  76. end;
  77. end;
  78. end;
  79. begin
  80. casmoptimizer:=TCpuAsmOptimizer;
  81. End.