~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to compiler/new/i386/aoptcpub.pas

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 {
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
4
 
    Development Team
5
 
 
6
 
    This unit contains several types and constants necessary for the
7
 
    optimizer to work on the 80x86 architecture
8
 
 
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.
13
 
 
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.
18
 
 
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.
22
 
 
23
 
 ****************************************************************************
24
 
}
25
 
Unit aoptcpub; { Assembler OPTimizer CPU specific Base }
26
 
 
27
 
{ enable the following define if memory references can have both a base and }
28
 
{ index register in 1 operand                                               }
29
 
 
30
 
{$define RefsHaveIndexReg}
31
 
 
32
 
{ enable the following define if memory references can have a scaled index }
33
 
 
34
 
{$define RefsHaveScale}
35
 
 
36
 
{ enable the following define if memory references can have a segment }
37
 
{ override                                                            }
38
 
 
39
 
{$define RefsHaveSegment}
40
 
 
41
 
Interface
42
 
 
43
 
uses aasm, cpubase, cpuasm, aoptbase;
44
 
 
45
 
Type
46
 
 
47
 
{ possible actions on an operand: read, write or modify (= read & write) }
48
 
  TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
49
 
 
50
 
{ type of a normal instruction }
51
 
  TInstr = Taicpu;
52
 
  PInstr = ^TInstr;
53
 
 
54
 
  TFlag = (DirFlag);
55
 
 
56
 
  TFlagContents = (F_Unknown, F_Clear, F_Set);
57
 
 
58
 
{ ************************************************************************* }
59
 
{ **************************** TCondRegs ********************************** }
60
 
{ ************************************************************************* }
61
 
{ Info about the conditional registers                                      }
62
 
  TCondRegs = Object
63
 
    Flags: Array[TFlag] of TFlagContents;
64
 
    Constructor Init;
65
 
    Procedure InitFlag(f: TFlag);
66
 
    Procedure SetFlag(f: TFlag);
67
 
    Procedure ClearFlag(f: TFlag);
68
 
    Function GetFlag(f: TFlag): TFlagContents;
69
 
    Destructor Done;
70
 
  End;
71
 
 
72
 
{ ************************************************************************* }
73
 
{ **************************** TAoptBaseCpu ******************************* }
74
 
{ ************************************************************************* }
75
 
 
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;
82
 
 
83
 
    Function a_load_reg_reg(reg1, reg2: TRegister): paicpu; virtual;
84
 
  End;
85
 
 
86
 
{ ************************************************************************* }
87
 
{ ******************************* Constants ******************************* }
88
 
{ ************************************************************************* }
89
 
Const
90
 
{ the maximum number of operands an instruction has }
91
 
 
92
 
  MaxOps = 3;
93
 
 
94
 
{Oper index of operand that contains the source (reference) with a load }
95
 
{instruction                                                            }
96
 
 
97
 
  LoadSrc = 0;
98
 
 
99
 
{Oper index of operand that contains the destination (register) with a load }
100
 
{instruction                                                                }
101
 
 
102
 
  LoadDst = 1;
103
 
 
104
 
{Oper index of operand that contains the source (register) with a store }
105
 
{instruction                                                            }
106
 
 
107
 
  StoreSrc = 0;
108
 
 
109
 
{Oper index of operand that contains the destination (reference) with a load }
110
 
{instruction                                                                 }
111
 
 
112
 
  StoreDst = 1;
113
 
 
114
 
 
115
 
Implementation
116
 
 
117
 
uses cpuinfo;
118
 
 
119
 
{ ************************************************************************* }
120
 
{ **************************** TCondRegs ********************************** }
121
 
{ ************************************************************************* }
122
 
Constructor TCondRegs.init;
123
 
Begin
124
 
  FillChar(Flags, SizeOf(Flags), Byte(F_Unknown))
125
 
End;
126
 
 
127
 
Procedure TCondRegs.InitFlag(f: TFlag);
128
 
Begin
129
 
  Flags[f] := F_Unknown
130
 
End;
131
 
 
132
 
Procedure TCondRegs.SetFlag(f: TFlag);
133
 
Begin
134
 
  Flags[f] := F_Set
135
 
End;
136
 
 
137
 
Procedure TCondRegs.ClearFlag(f: TFlag);
138
 
Begin
139
 
  Flags[f] := F_Clear
140
 
End;
141
 
 
142
 
Function TCondRegs.GetFlag(f: TFlag): TFlagContents;
143
 
Begin
144
 
  GetFlag := Flags[f]
145
 
End;
146
 
 
147
 
Destructor TCondRegs.Done; {$ifdef inl} inline; {$endif inl}
148
 
Begin
149
 
End;
150
 
{ ************************************************************************* }
151
 
{ **************************** TAoptBaseCpu ******************************* }
152
 
{ ************************************************************************* }
153
 
 
154
 
Function TAoptBaseCpu.RegMaxSize(Reg: TRegister): TRegister;
155
 
Begin
156
 
  RegMaxSize := Reg;
157
 
  If (Reg >= R_AX)
158
 
    Then
159
 
      If (Reg <= R_DI)
160
 
        Then RegMaxSize := Reg16ToReg32(Reg)
161
 
        Else
162
 
          If (Reg <= R_BL)
163
 
            Then RegMaxSize := Reg8toReg32(Reg)
164
 
End;
165
 
 
166
 
Function TAOptBaseCpu.RegsSameSize(Reg1, Reg2: TRegister): Boolean;
167
 
Begin
168
 
  If (Reg1 <= R_EDI)
169
 
    Then RegsSameSize := (Reg2 <= R_EDI)
170
 
    Else
171
 
      If (Reg1 <= R_DI)
172
 
        Then RegsSameSize := (Reg2 in [R_AX..R_DI])
173
 
        Else
174
 
          If (Reg1 <= R_BL)
175
 
            Then RegsSameSize := (Reg2 in [R_AL..R_BL])
176
 
            Else RegsSameSize := False
177
 
End;
178
 
 
179
 
Function TAOptBaseCpu.IsLoadMemReg(p: pai): Boolean;
180
 
Begin
181
 
  IsLoadMemReg :=
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);
187
 
End;
188
 
 
189
 
Function TAOptBaseCpu.IsLoadConstReg(p: pai): Boolean;
190
 
Begin
191
 
  IsLoadConstReg :=
192
 
    (p^.typ = ait_instruction) and
193
 
    (PInstr(p)^.OpCode = A_MOV) And
194
 
    (PInstr(p)^.oper[LoadSrc].typ = top_const);
195
 
End;
196
 
 
197
 
Function TAOptBaseCpu.IsStoreRegMem(p: pai): Boolean;
198
 
Begin
199
 
  IsStoreRegMem :=
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);
205
 
End;
206
 
 
207
 
Function TAOptBaseCpu.a_load_reg_reg(reg1, reg2: TRegister): paicpu;
208
 
Begin
209
 
  a_load_reg_Reg := New(paicpu,Op_Reg_Reg(A_MOV, S_L, reg1, reg2))
210
 
End;
211
 
 
212
 
 
213
 
End.
214
 
 
215
 
{
216
 
 $Log: aoptcpub.pas,v $
217
 
 Revision 1.2  2002/09/07 15:25:14  peter
218
 
   * old logs removed and tabs fixed
219
 
 
220
 
}