2
$Id: aoptcpub.pas,v 1.2 2002/09/07 15:25:14 peter Exp $
3
Copyright (c) 1998-2000 by Jonas Maebe, member of the Free Pascal
6
This unit contains several types and constants necessary for the
7
optimizer to work on the 80x86 architecture
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
****************************************************************************
25
Unit aoptcpub; { Assembler OPTimizer CPU specific Base }
27
{ enable the following define if memory references can have both a base and }
28
{ index register in 1 operand }
30
{$define RefsHaveIndexReg}
32
{ enable the following define if memory references can have a scaled index }
34
{$define RefsHaveScale}
36
{ enable the following define if memory references can have a segment }
39
{$define RefsHaveSegment}
43
uses aasm, cpubase, cpuasm, aoptbase;
47
{ possible actions on an operand: read, write or modify (= read & write) }
48
TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
50
{ type of a normal instruction }
56
TFlagContents = (F_Unknown, F_Clear, F_Set);
58
{ ************************************************************************* }
59
{ **************************** TCondRegs ********************************** }
60
{ ************************************************************************* }
61
{ Info about the conditional registers }
63
Flags: Array[TFlag] of TFlagContents;
65
Procedure InitFlag(f: TFlag);
66
Procedure SetFlag(f: TFlag);
67
Procedure ClearFlag(f: TFlag);
68
Function GetFlag(f: TFlag): TFlagContents;
72
{ ************************************************************************* }
73
{ **************************** TAoptBaseCpu ******************************* }
74
{ ************************************************************************* }
76
TAoptBaseCpu = Object(TAoptBase)
77
Function RegMaxSize(Reg: TRegister): TRegister; Virtual;
78
Function RegsSameSize(Reg1, Reg2: TRegister): Boolean; Virtual;
79
Function IsLoadMemReg(p: pai): Boolean; Virtual;
80
Function IsLoadConstReg(p: pai): Boolean; Virtual;
81
Function IsStoreRegMem(p: pai): Boolean; Virtual;
83
Function a_load_reg_reg(reg1, reg2: TRegister): paicpu; virtual;
86
{ ************************************************************************* }
87
{ ******************************* Constants ******************************* }
88
{ ************************************************************************* }
90
{ the maximum number of operands an instruction has }
94
{Oper index of operand that contains the source (reference) with a load }
99
{Oper index of operand that contains the destination (register) with a load }
104
{Oper index of operand that contains the source (register) with a store }
109
{Oper index of operand that contains the destination (reference) with a load }
119
{ ************************************************************************* }
120
{ **************************** TCondRegs ********************************** }
121
{ ************************************************************************* }
122
Constructor TCondRegs.init;
124
FillChar(Flags, SizeOf(Flags), Byte(F_Unknown))
127
Procedure TCondRegs.InitFlag(f: TFlag);
129
Flags[f] := F_Unknown
132
Procedure TCondRegs.SetFlag(f: TFlag);
137
Procedure TCondRegs.ClearFlag(f: TFlag);
142
Function TCondRegs.GetFlag(f: TFlag): TFlagContents;
147
Destructor TCondRegs.Done; {$ifdef inl} inline; {$endif inl}
150
{ ************************************************************************* }
151
{ **************************** TAoptBaseCpu ******************************* }
152
{ ************************************************************************* }
154
Function TAoptBaseCpu.RegMaxSize(Reg: TRegister): TRegister;
160
Then RegMaxSize := Reg16ToReg32(Reg)
163
Then RegMaxSize := Reg8toReg32(Reg)
166
Function TAOptBaseCpu.RegsSameSize(Reg1, Reg2: TRegister): Boolean;
169
Then RegsSameSize := (Reg2 <= R_EDI)
172
Then RegsSameSize := (Reg2 in [R_AX..R_DI])
175
Then RegsSameSize := (Reg2 in [R_AL..R_BL])
176
Else RegsSameSize := False
179
Function TAOptBaseCpu.IsLoadMemReg(p: pai): Boolean;
182
(p^.typ = ait_instruction) and
183
((PInstr(p)^.OpCode = A_MOV) or
184
(PInstr(p)^.OpCode = A_MOVZX) or
185
(PInstr(p)^.OpCode = A_MOVSX)) And
186
(PInstr(p)^.oper[LoadSrc].typ = top_ref);
189
Function TAOptBaseCpu.IsLoadConstReg(p: pai): Boolean;
192
(p^.typ = ait_instruction) and
193
(PInstr(p)^.OpCode = A_MOV) And
194
(PInstr(p)^.oper[LoadSrc].typ = top_const);
197
Function TAOptBaseCpu.IsStoreRegMem(p: pai): Boolean;
200
(p^.typ = ait_instruction) and
201
((PInstr(p)^.OpCode = A_MOV) or
202
(PInstr(p)^.OpCode = A_MOVZX) or
203
(PInstr(p)^.OpCode = A_MOVSX)) And
204
(PInstr(p)^.oper[StoreDst].typ = top_ref);
207
Function TAOptBaseCpu.a_load_reg_reg(reg1, reg2: TRegister): paicpu;
209
a_load_reg_Reg := New(paicpu,Op_Reg_Reg(A_MOV, S_L, reg1, reg2))
216
$Log: aoptcpub.pas,v $
217
Revision 1.2 2002/09/07 15:25:14 peter
218
* old logs removed and tabs fixed