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

« back to all changes in this revision

Viewing changes to compiler/mips/aasmcpu.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: aasmcpu.pas,v 1.3 2005/03/24 13:30:17 florian Exp $
 
3
    Copyright (c) 2003 by Florian Klaempfl
 
4
 
 
5
    Contains the assembler object for MIPS
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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.
 
20
 
 
21
 ****************************************************************************
 
22
}
 
23
unit aasmcpu;
 
24
 
 
25
{$i fpcdefs.inc}
 
26
 
 
27
interface
 
28
 
 
29
uses
 
30
  cclasses,aasmtai,
 
31
  aasmbase,globtype,globals,verbose,
 
32
  cpubase,cpuinfo,cgbase,cgutils;
 
33
 
 
34
    const
 
35
      { "mov reg,reg" source operand number }
 
36
      O_MOV_SOURCE = 1;
 
37
      { "mov reg,reg" source operand number }
 
38
      O_MOV_DEST = 0;
 
39
 
 
40
    type
 
41
      taicpu = class(tai_cpu_abstract)
 
42
         constructor op_none(op : tasmop);
 
43
 
 
44
         constructor op_reg(op : tasmop;_op1 : tregister);
 
45
         constructor op_const(op : tasmop;_op1 : longint);
 
46
 
 
47
         constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
 
48
         constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
 
49
         constructor op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
 
50
 
 
51
         constructor op_ref_regset(op:tasmop; _op1: treference; _op2: tcpuregisterset);
 
52
 
 
53
         constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
 
54
         constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
 
55
         constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
 
56
         constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
 
57
         { SFM/LFM }
 
58
         constructor op_reg_const_ref(op : tasmop;_op1 : tregister;_op2 : aint;_op3 : treference);
 
59
 
 
60
         { this is for Jmp instructions }
 
61
         constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
 
62
 
 
63
         constructor op_sym(op : tasmop;_op1 : tasmsymbol);
 
64
         constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
 
65
         constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
 
66
         constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
 
67
 
 
68
         function is_same_reg_move(regtype: Tregistertype):boolean; override;
 
69
 
 
70
         function spilling_get_operation_type(opnr: longint): topertype;override;
 
71
      end;
 
72
      tai_align = class(tai_align_abstract)
 
73
        { nothing to add }
 
74
      end;
 
75
 
 
76
    function spilling_create_load(const ref:treference;r:tregister): tai;
 
77
    function spilling_create_store(r:tregister; const ref:treference): tai;
 
78
 
 
79
    procedure InitAsm;
 
80
    procedure DoneAsm;
 
81
 
 
82
 
 
83
implementation
 
84
 
 
85
  uses
 
86
    cutils,rgobj,itcpugas;
 
87
 
 
88
 
 
89
{*****************************************************************************
 
90
                                 taicpu Constructors
 
91
*****************************************************************************}
 
92
 
 
93
    constructor taicpu.op_none(op : tasmop);
 
94
      begin
 
95
         inherited create(op);
 
96
      end;
 
97
 
 
98
 
 
99
    constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
 
100
      begin
 
101
         inherited create(op);
 
102
         ops:=1;
 
103
         loadreg(0,_op1);
 
104
      end;
 
105
 
 
106
 
 
107
    constructor taicpu.op_const(op : tasmop;_op1 : longint);
 
108
      begin
 
109
         inherited create(op);
 
110
         ops:=1;
 
111
         loadconst(0,aint(_op1));
 
112
      end;
 
113
 
 
114
 
 
115
    constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
 
116
      begin
 
117
         inherited create(op);
 
118
         ops:=2;
 
119
         loadreg(0,_op1);
 
120
         loadreg(1,_op2);
 
121
      end;
 
122
 
 
123
 
 
124
    constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
 
125
      begin
 
126
         inherited create(op);
 
127
         ops:=2;
 
128
         loadreg(0,_op1);
 
129
         loadconst(1,aint(_op2));
 
130
      end;
 
131
 
 
132
 
 
133
    constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
 
134
      begin
 
135
         inherited create(op);
 
136
         ops:=2;
 
137
         loadreg(0,_op1);
 
138
         loadref(1,_op2);
 
139
      end;
 
140
 
 
141
 
 
142
    constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
 
143
      begin
 
144
         inherited create(op);
 
145
         ops:=3;
 
146
         loadreg(0,_op1);
 
147
         loadreg(1,_op2);
 
148
         loadreg(2,_op3);
 
149
      end;
 
150
 
 
151
 
 
152
     constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
 
153
       begin
 
154
         inherited create(op);
 
155
         ops:=3;
 
156
         loadreg(0,_op1);
 
157
         loadreg(1,_op2);
 
158
         loadconst(2,aint(_op3));
 
159
      end;
 
160
 
 
161
 
 
162
    constructor taicpu.op_reg_const_ref(op : tasmop;_op1 : tregister;_op2 : aint;_op3 : treference);
 
163
      begin
 
164
         inherited create(op);
 
165
         ops:=3;
 
166
         loadreg(0,_op1);
 
167
         loadconst(1,_op2);
 
168
         loadref(2,_op3);
 
169
      end;
 
170
 
 
171
 
 
172
     constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
 
173
       begin
 
174
         inherited create(op);
 
175
         ops:=3;
 
176
         loadreg(0,_op1);
 
177
         loadreg(1,_op2);
 
178
         loadsymbol(0,_op3,_op3ofs);
 
179
      end;
 
180
 
 
181
 
 
182
     constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
 
183
       begin
 
184
         inherited create(op);
 
185
         ops:=3;
 
186
         loadreg(0,_op1);
 
187
         loadreg(1,_op2);
 
188
         loadref(2,_op3);
 
189
      end;
 
190
 
 
191
 
 
192
    constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
 
193
      begin
 
194
         inherited create(op);
 
195
         condition:=cond;
 
196
         ops:=1;
 
197
         loadsymbol(0,_op1,0);
 
198
      end;
 
199
 
 
200
 
 
201
    constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
 
202
      begin
 
203
         inherited create(op);
 
204
         ops:=1;
 
205
         loadsymbol(0,_op1,0);
 
206
      end;
 
207
 
 
208
 
 
209
    constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
 
210
      begin
 
211
         inherited create(op);
 
212
         ops:=1;
 
213
         loadsymbol(0,_op1,_op1ofs);
 
214
      end;
 
215
 
 
216
 
 
217
     constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
 
218
      begin
 
219
         inherited create(op);
 
220
         ops:=2;
 
221
         loadreg(0,_op1);
 
222
         loadsymbol(1,_op2,_op2ofs);
 
223
      end;
 
224
 
 
225
 
 
226
    constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
 
227
      begin
 
228
         inherited create(op);
 
229
         ops:=2;
 
230
         loadsymbol(0,_op1,_op1ofs);
 
231
         loadref(1,_op2);
 
232
      end;
 
233
 
 
234
 
 
235
{ ****************************** newra stuff *************************** }
 
236
 
 
237
    function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
 
238
      begin
 
239
        { allow the register allocator to remove unnecessary moves }
 
240
        result:=(((opcode=A_MOVE) and (regtype = R_INTREGISTER)) or
 
241
                 ((opcode=A_MOVF) and (regtype = R_FPUREGISTER))
 
242
                ) and
 
243
                (condition=C_None) and
 
244
                (ops=2) and
 
245
                (oper[0]^.typ=top_reg) and
 
246
                (oper[1]^.typ=top_reg) and
 
247
                (oper[0]^.reg=oper[1]^.reg);
 
248
      end;
 
249
 
 
250
 
 
251
    function spilling_create_load(const ref:treference;r:tregister): tai;
 
252
      begin
 
253
        case getregtype(r) of
 
254
          R_INTREGISTER :
 
255
            result:=taicpu.op_reg_ref(A_LDR,r,ref);
 
256
          R_FPUREGISTER :
 
257
            { use lfm because we don't know the current internal format
 
258
              and avoid exceptions
 
259
            }
 
260
            result:=taicpu.op_reg_const_ref(A_LFM,r,1,ref);
 
261
          else
 
262
            internalerror(200401041);
 
263
        end;
 
264
      end;
 
265
 
 
266
 
 
267
    function spilling_create_store(r:tregister; const ref:treference): tai;
 
268
      begin
 
269
        case getregtype(r) of
 
270
          R_INTREGISTER :
 
271
            result:=taicpu.op_reg_ref(A_STR,r,ref);
 
272
          R_FPUREGISTER :
 
273
            { use sfm because we don't know the current internal format
 
274
              and avoid exceptions
 
275
            }
 
276
            result:=taicpu.op_reg_const_ref(A_SFM,r,1,ref);
 
277
          else
 
278
            internalerror(200401041);
 
279
        end;
 
280
      end;
 
281
 
 
282
 
 
283
    function taicpu.spilling_get_operation_type(opnr: longint): topertype;
 
284
      begin
 
285
        case opcode of
 
286
          A_ADC,A_ADD,A_AND,
 
287
          A_EOR,A_CLZ,
 
288
          A_LDR,A_LDRB,A_LDRD,A_LDRBT,A_LDRH,A_LDRSB,
 
289
          A_LDRSH,A_LDRT,
 
290
          A_MOV,A_MVN,A_MLA,A_MUL,
 
291
          A_ORR,A_RSB,A_RSC,A_SBC,A_SUB,
 
292
          A_SWP,A_SWPB,
 
293
          A_LDF,A_FLT,A_FIX,
 
294
          A_ADF,A_DVF,A_FDV,A_FML,
 
295
          A_RFS,A_RFC,A_RDF,
 
296
          A_RMF,A_RPW,A_RSF,A_SUF,A_ABS,A_ACS,A_ASN,A_ATN,A_COS,
 
297
          A_EXP,A_LOG,A_LGN,A_MVF,A_MNF,A_FRD,A_MUF,A_POL,A_RND,A_SIN,A_SQT,A_TAN,
 
298
          A_LFM:
 
299
            if opnr=0 then
 
300
              result:=operand_write
 
301
            else
 
302
              result:=operand_read;
 
303
          A_BIC,A_BKPT,A_B,A_BL,A_BLX,A_BX,
 
304
          A_CMN,A_CMP,A_TEQ,A_TST,
 
305
          A_CMF,A_CMFE,A_WFS,A_CNF:
 
306
            result:=operand_read;
 
307
          A_SMLAL,A_UMLAL:
 
308
            if opnr in [0,1] then
 
309
              result:=operand_readwrite
 
310
            else
 
311
              result:=operand_read;
 
312
           A_SMULL,A_UMULL:
 
313
            if opnr in [0,1] then
 
314
              result:=operand_write
 
315
            else
 
316
              result:=operand_read;
 
317
          A_STR,A_STRB,A_STRBT,A_STRD,
 
318
          A_STRH,A_STRT,A_STF,A_SFM:
 
319
            { important is what happens with the involved registers }
 
320
            if opnr=0 then
 
321
              result := operand_read
 
322
            else
 
323
              { check for pre/post indexed }
 
324
              result := operand_read;
 
325
          else
 
326
            internalerror(200403151);
 
327
        end;
 
328
      end;
 
329
 
 
330
 
 
331
    procedure InitAsm;
 
332
      begin
 
333
      end;
 
334
 
 
335
 
 
336
    procedure DoneAsm;
 
337
      begin
 
338
      end;
 
339
 
 
340
end.
 
341
{
 
342
  $Log: aasmcpu.pas,v $
 
343
  Revision 1.3  2005/03/24 13:30:17  florian
 
344
    * small compilation fix
 
345
 
 
346
  Revision 1.2  2005/02/14 17:13:10  peter
 
347
    * truncate log
 
348
 
 
349
  Revision 1.1  2005/02/13 18:56:44  florian
 
350
    + basic mips stuff
 
351
}