2
$Id: n386mem.pas,v 1.60 2004/02/27 10:21:05 florian Exp $
3
Copyright (c) 1998-2002 by Florian Klaempfl
5
Generate i386 assembler for in memory related nodes
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
****************************************************************************
30
cgbase,cpuinfo,cpubase,
34
ti386addrnode = class(tcgaddrnode)
35
procedure pass_2;override;
38
ti386derefnode = class(tcgderefnode)
39
procedure pass_2;override;
42
ti386vecnode = class(tcgvecnode)
43
procedure update_reference_reg_mul(reg:tregister;l:aword);override;
44
procedure pass_2;override;
60
{*****************************************************************************
62
*****************************************************************************}
64
procedure ti386addrnode.pass_2;
68
{ for use of other segments }
69
if left.location.reference.segment<>NR_NO then
70
location.segment:=left.location.reference.segment;
74
{*****************************************************************************
76
*****************************************************************************}
78
procedure ti386derefnode.pass_2;
81
if tpointerdef(left.resulttype.def).is_far then
82
location.reference.segment:=NR_FS;
86
{*****************************************************************************
88
*****************************************************************************}
90
procedure ti386vecnode.update_reference_reg_mul(reg:tregister;l:aword);
95
{ Optimized for x86 to use the index register and scalefactor }
96
if location.reference.index=NR_NO then
98
{ no preparations needed }
100
else if location.reference.base=NR_NO then
102
case location.reference.scalefactor of
103
2 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,1,location.reference.index);
104
4 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,2,location.reference.index);
105
8 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,3,location.reference.index);
107
location.reference.base:=location.reference.index;
111
cg.ungetreference(exprasmlist,location.reference);
112
hreg := cg.getaddressregister(exprasmlist);
113
cg.a_loadaddr_ref_reg(exprasmlist,location.reference,hreg);
114
reference_reset_base(location.reference,hreg,0);
116
{ insert the new index register and scalefactor or
117
do the multiplication manual }
119
1,2,4,8 : location.reference.scalefactor:=l;
122
if ispowerof2(l,l2) then
123
cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,l2,reg)
125
cg.a_op_const_reg(exprasmlist,OP_IMUL,OS_ADDR,l,reg);
128
location.reference.index:=reg;
132
procedure ti386vecnode.pass_2;
135
if nf_memseg in flags then
136
location.reference.segment:=NR_FS;
141
caddrnode:=ti386addrnode;
142
cderefnode:=ti386derefnode;
143
cvecnode:=ti386vecnode;
146
$Log: n386mem.pas,v $
147
Revision 1.60 2004/02/27 10:21:05 florian
149
+ refaddr to treference added
150
+ refsymbol to treference added
151
* top_local stuff moved to an extra record to save memory
153
* tppufile.get/putint64/aint implemented
155
Revision 1.59 2003/10/21 15:13:27 peter
156
* fix vecnode code that caused to much register conflicts
158
Revision 1.58 2003/10/10 17:48:14 peter
159
* old trgobj moved to x86/rgcpu and renamed to trgx86fpu
160
* tregisteralloctor renamed to trgobj
161
* removed rgobj from a lot of units
162
* moved location_* and reference_* to cgobj
163
* first things for mmx register allocation
165
Revision 1.57 2003/10/09 21:31:37 daniel
166
* Register allocator splitted, ans abstract now
168
Revision 1.56 2003/10/01 20:34:49 peter
169
* procinfo unit contains tprocinfo
170
* cginfo renamed to cgbase
171
* moved cgmessage to verbose
172
* fixed ppc and sparc compiles
174
Revision 1.55 2003/09/29 20:58:56 peter
175
* optimized releasing of registers
177
Revision 1.54 2003/09/03 15:55:01 peter
178
* NEWRA branch merged
180
Revision 1.53.2.2 2003/08/31 15:46:26 peter
181
* more updates for tregister
183
Revision 1.53.2.1 2003/08/29 17:29:00 peter
184
* next batch of updates
186
Revision 1.53 2003/06/01 21:38:06 peter
187
* getregisterfpu size parameter added
188
* op_const_reg size parameter added
191
Revision 1.52 2003/04/22 14:33:38 peter
192
* removed some notes/hints
194
Revision 1.51 2003/03/28 19:16:57 peter
195
* generic constructor working for i386
196
* remove fixed self register
197
* esi added as address register for i386
199
Revision 1.50 2003/02/19 22:00:15 daniel
200
* Code generator converted to new register notation
201
- Horribily outdated todo.txt removed
203
Revision 1.49 2003/01/13 18:37:44 daniel
204
* Work on register conversion
206
Revision 1.48 2003/01/08 18:43:57 daniel
207
* Tregister changed into a record
209
Revision 1.47 2002/12/03 22:14:12 carl
210
+ use FPC_CHECKPOINTER once again
212
Revision 1.46 2002/11/25 17:43:27 peter
213
* splitted defbase in defutil,symutil,defcmp
214
* merged isconvertable and is_equal into compare_defs(_ext)
215
* made operator search faster by walking the list only once
217
Revision 1.45 2002/11/23 22:50:09 carl
218
* some small speed optimizations
219
+ added several new warnings/hints
221
Revision 1.44 2002/09/07 15:25:11 peter
222
* old logs removed and tabs fixed
224
Revision 1.43 2002/09/01 19:27:35 peter
225
* use index register when available for generating a reference with
226
only a signle register. Using the base register could possibly
227
destroy the framepointer
229
Revision 1.42 2002/09/01 18:46:01 peter
230
* fixed generic tcgvecnode
231
* move code that updates a reference with index register and multiplier
232
to separate method so it can be overriden for scaled indexing
233
* i386 uses generic tcgvecnode
235
Revision 1.41 2002/08/11 14:32:30 peter
236
* renamed current_library to objectlibrary
238
Revision 1.40 2002/08/11 13:24:17 peter
239
* saving of asmsymbols in ppu supported
240
* asmsymbollist global is removed and moved into a new class
241
tasmlibrarydata that will hold the info of a .a file which
242
corresponds with a single module. Added librarydata to tmodule
243
to keep the library info stored for the module. In the future the
244
objectfiles will also be stored to the tasmlibrarydata class
245
* all getlabel/newasmsymbol and friends are moved to the new class
247
Revision 1.39 2002/07/28 21:34:31 florian
251
Revision 1.38 2002/07/20 11:58:04 florian
252
* types.pas renamed to defbase.pas because D6 contains a types
253
unit so this would conflicts if D6 programms are compiled
254
+ Willamette/SSE2 instructions to assembler added
256
Revision 1.37 2002/07/11 14:41:33 florian
257
* start of the new generic parameter handling
259
Revision 1.36 2002/07/07 09:52:34 florian
260
* powerpc target fixed, very simple units can be compiled
261
* some basic stuff for better callparanode handling, far from being finished
263
Revision 1.35 2002/07/01 18:46:33 peter
265
* reorganized aasm layer
267
Revision 1.34 2002/06/24 12:43:01 jonas
268
* fixed errors found with new -CR code from Peter when cycling with -O2p3r
270
Revision 1.33 2002/05/18 13:34:25 peter
271
* readded missing revisions
273
Revision 1.32 2002/05/16 19:46:51 carl
274
+ defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
275
+ try to fix temp allocation (still in ifdef)
276
+ generic constructor calls
277
+ start of tassembler / tmodulebase class cleanup
279
Revision 1.30 2002/05/13 19:54:38 peter
280
* removed n386ld and n386util units
281
* maybe_save/maybe_restore added instead of the old maybe_push
283
Revision 1.29 2002/05/12 16:53:17 peter
284
* moved entry and exitcode to ncgutil and cgobj
285
* foreach gets extra argument for passing local data to the
287
* -CR checks also class typecasts at runtime by changing them
289
* fixed compiler to cycle with the -CR option
290
* fixed stabs with elf writer, finally the global variables can
292
* removed a lot of routines from cga unit and replaced them by
294
* u32bit-s32bit updates for and,or,xor nodes. When one element is
295
u32bit then the other is typecasted also to u32bit without giving
296
a rangecheck warning/error.
297
* fixed pascal calling method with reversing also the high tree in
298
the parast, detected by tcalcst3 test
300
Revision 1.28 2002/04/21 19:02:07 peter
301
* removed newn and disposen nodes, the code is now directly
303
* -an option that will write the secondpass nodes to the .s file, this
304
requires EXTDEBUG define to actually write the info
305
* fixed various internal errors and crashes due recent code changes
307
Revision 1.27 2002/04/20 21:37:07 carl
308
+ generic FPC_CHECKPOINTER
309
+ first parameter offset in stack now portable
310
* rename some constants
311
+ move some cpu stuff to other units
312
- remove unused constents
313
* fix stacksize for some targets
314
* fix generic size problems which depend now on EXTEND_SIZE constant
315
* removing frame pointer in routines is only available for : i386,m68k and vis targets
317
Revision 1.26 2002/04/19 15:39:35 peter
318
* removed some more routines from cga
319
* moved location_force_reg/mem to ncgutil
320
* moved arrayconstructnode secondpass to ncgld
322
Revision 1.25 2002/04/15 19:12:09 carl
323
+ target_info.size_of_pointer -> pointer_size
324
+ some cleanup of unused types/variables
325
* move several constants from cpubase to their specific units
326
(where they are used)
327
+ att_Reg2str -> gas_reg2str
328
+ int_reg2str -> std_reg2str
330
Revision 1.24 2002/04/04 19:06:12 peter
331
* removed unused units
332
* use tlocation.size in cg.a_*loc*() routines
334
Revision 1.23 2002/04/02 17:11:36 peter
335
* tlocation,treference update
336
* LOC_CONSTANT added for better constant handling
337
* secondadd splitted in multiple routines
338
* location_force_reg added for loading a location to a register
340
* secondassignment parses now first the right and then the left node
341
(this is compatible with Kylix). This saves a lot of push/pop especially
342
with string operations
343
* adapted some routines to use the new cg methods