~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to compiler/i386/n386add.pas

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{
2
 
    $Id: n386add.pas,v 1.96 2004/05/19 23:30:18 peter Exp $
3
 
    Copyright (c) 2000-2002 by Florian Klaempfl
4
 
 
5
 
    Code generation for add nodes on the i386
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 n386add;
24
 
 
25
 
{$i fpcdefs.inc}
26
 
 
27
 
interface
28
 
 
29
 
    uses
30
 
       node,nadd,cpubase,nx86add;
31
 
 
32
 
    type
33
 
       ti386addnode = class(tx86addnode)
34
 
{$ifdef SUPPORT_MMX}
35
 
          procedure second_addmmxset;override;
36
 
          procedure second_addmmx;override;
37
 
{$endif SUPPORT_MMX}
38
 
          procedure second_add64bit;override;
39
 
          procedure second_cmp64bit;override;
40
 
          procedure second_mul;override;
41
 
       end;
42
 
 
43
 
  implementation
44
 
 
45
 
    uses
46
 
      globtype,systems,
47
 
      cutils,verbose,globals,
48
 
      cpuinfo,
49
 
      symconst,symdef,paramgr,
50
 
      aasmbase,aasmtai,aasmcpu,
51
 
      cgbase,
52
 
      ncon,nset,
53
 
      cga,ncgutil,cgobj,cg64f32;
54
 
 
55
 
{*****************************************************************************
56
 
                                   addmmxset
57
 
*****************************************************************************}
58
 
 
59
 
{$ifdef SUPPORT_MMX}
60
 
    procedure ti386addnode.second_addmmxset;
61
 
 
62
 
    var opsize : TCGSize;
63
 
        op     : TAsmOp;
64
 
        cmpop,
65
 
        pushedfpu,
66
 
        noswap : boolean;
67
 
    begin
68
 
      pass_left_and_right(pushedfpu);
69
 
 
70
 
      cmpop:=false;
71
 
      noswap:=false;
72
 
      opsize:=OS_32;
73
 
      case nodetype of
74
 
        addn:
75
 
          begin
76
 
            { are we adding set elements ? }
77
 
            if right.nodetype=setelementn then
78
 
              begin
79
 
                { adding elements is not commutative }
80
 
{                if nf_swaped in flags then
81
 
                  swapleftright;}
82
 
                { bts requires both elements to be registers }
83
 
{                location_force_reg(exprasmlist,left.location,opsize_2_cgsize[opsize],false);
84
 
                location_force_reg(exprasmlist,right.location,opsize_2_cgsize[opsize],true);
85
 
                op:=A_BTS;
86
 
                noswap:=true;}
87
 
              end
88
 
            else
89
 
              op:=A_POR;
90
 
          end;
91
 
        symdifn :
92
 
          op:=A_PXOR;
93
 
        muln:
94
 
          op:=A_PAND;
95
 
        subn:
96
 
          op:=A_PANDN;
97
 
        equaln,
98
 
        unequaln :
99
 
          begin
100
 
            op:=A_PCMPEQD;
101
 
            cmpop:=true;
102
 
          end;
103
 
        lten,gten:
104
 
          begin
105
 
            if (not(nf_swaped in flags) and (nodetype = lten)) or
106
 
               ((nf_swaped in flags) and (nodetype = gten)) then
107
 
              swapleftright;
108
 
            location_force_reg(exprasmlist,left.location,opsize,true);
109
 
            emit_op_right_left(A_AND,TCGSize2Opsize[opsize]);
110
 
            op:=A_PCMPEQD;
111
 
            cmpop:=true;
112
 
            { warning: ugly hack, we need a JE so change the node to equaln }
113
 
            nodetype:=equaln;
114
 
          end;
115
 
          xorn :
116
 
            op:=A_PXOR;
117
 
          orn :
118
 
            op:=A_POR;
119
 
          andn :
120
 
            op:=A_PAND;
121
 
          else
122
 
            internalerror(2003042215);
123
 
        end;
124
 
        { left must be a register }
125
 
        left_must_be_reg(opsize,noswap);
126
 
{        emit_generic_code(op,opsize,true,extra_not,false);}
127
 
        location_freetemp(exprasmlist,right.location);
128
 
        location_release(exprasmlist,right.location);
129
 
        if cmpop then
130
 
         begin
131
 
           location_freetemp(exprasmlist,left.location);
132
 
           location_release(exprasmlist,left.location);
133
 
         end;
134
 
        set_result_location(cmpop,true);
135
 
      end;
136
 
{$endif SUPPORT_MMX}
137
 
 
138
 
 
139
 
{*****************************************************************************
140
 
                                Add64bit
141
 
*****************************************************************************}
142
 
 
143
 
    procedure ti386addnode.second_add64bit;
144
 
      var
145
 
        op         : TOpCG;
146
 
        op1,op2    : TAsmOp;
147
 
        opsize     : TOpSize;
148
 
        hregister,
149
 
        hregister2 : tregister;
150
 
        hl4        : tasmlabel;
151
 
        mboverflow,
152
 
        unsigned:boolean;
153
 
        r:Tregister;
154
 
      begin
155
 
        firstcomplex(self);
156
 
        pass_left_right;
157
 
 
158
 
        op1:=A_NONE;
159
 
        op2:=A_NONE;
160
 
        mboverflow:=false;
161
 
        opsize:=S_L;
162
 
        unsigned:=((left.resulttype.def.deftype=orddef) and
163
 
                   (torddef(left.resulttype.def).typ=u64bit)) or
164
 
                  ((right.resulttype.def.deftype=orddef) and
165
 
                   (torddef(right.resulttype.def).typ=u64bit));
166
 
        case nodetype of
167
 
          addn :
168
 
            begin
169
 
              op:=OP_ADD;
170
 
              mboverflow:=true;
171
 
            end;
172
 
          subn :
173
 
            begin
174
 
              op:=OP_SUB;
175
 
              op1:=A_SUB;
176
 
              op2:=A_SBB;
177
 
              mboverflow:=true;
178
 
            end;
179
 
          xorn:
180
 
            op:=OP_XOR;
181
 
          orn:
182
 
            op:=OP_OR;
183
 
          andn:
184
 
            op:=OP_AND;
185
 
          else
186
 
            begin
187
 
              { everything should be handled in pass_1 (JM) }
188
 
              internalerror(200109051);
189
 
            end;
190
 
        end;
191
 
 
192
 
        { left and right no register?  }
193
 
        { then one must be demanded    }
194
 
        if (left.location.loc<>LOC_REGISTER) then
195
 
         begin
196
 
           if (right.location.loc<>LOC_REGISTER) then
197
 
            begin
198
 
              hregister:=cg.getintregister(exprasmlist,OS_INT);
199
 
              hregister2:=cg.getintregister(exprasmlist,OS_INT);
200
 
              cg64.a_load64_loc_reg(exprasmlist,left.location,joinreg64(hregister,hregister2));
201
 
              location_reset(left.location,LOC_REGISTER,OS_64);
202
 
              left.location.registerlow:=hregister;
203
 
              left.location.registerhigh:=hregister2;
204
 
            end
205
 
           else
206
 
            begin
207
 
              location_swap(left.location,right.location);
208
 
              toggleflag(nf_swaped);
209
 
            end;
210
 
         end;
211
 
 
212
 
        { at this point, left.location.loc should be LOC_REGISTER }
213
 
        if right.location.loc=LOC_REGISTER then
214
 
         begin
215
 
           { when swapped another result register }
216
 
           if (nodetype=subn) and (nf_swaped in flags) then
217
 
            begin
218
 
              cg64.a_op64_reg_reg(exprasmlist,op,
219
 
                left.location.register64,
220
 
                right.location.register64);
221
 
              location_swap(left.location,right.location);
222
 
              toggleflag(nf_swaped);
223
 
            end
224
 
           else
225
 
            begin
226
 
              cg64.a_op64_reg_reg(exprasmlist,op,
227
 
                right.location.register64,
228
 
                left.location.register64);
229
 
            end;
230
 
           location_release(exprasmlist,right.location);
231
 
         end
232
 
        else
233
 
         begin
234
 
           { right.location<>LOC_REGISTER }
235
 
           if (nodetype=subn) and (nf_swaped in flags) then
236
 
            begin
237
 
              r:=cg.getintregister(exprasmlist,OS_INT);
238
 
              cg64.a_load64low_loc_reg(exprasmlist,right.location,r);
239
 
              emit_reg_reg(op1,opsize,left.location.registerlow,r);
240
 
              emit_reg_reg(A_MOV,opsize,r,left.location.registerlow);
241
 
              cg64.a_load64high_loc_reg(exprasmlist,right.location,r);
242
 
              { the carry flag is still ok }
243
 
              emit_reg_reg(op2,opsize,left.location.registerhigh,r);
244
 
              emit_reg_reg(A_MOV,opsize,r,left.location.registerhigh);
245
 
              cg.ungetregister(exprasmlist,r);
246
 
              if right.location.loc<>LOC_CREGISTER then
247
 
               begin
248
 
                 location_freetemp(exprasmlist,right.location);
249
 
                 location_release(exprasmlist,right.location);
250
 
               end;
251
 
            end
252
 
           else
253
 
            begin
254
 
              cg64.a_op64_loc_reg(exprasmlist,op,right.location,
255
 
                left.location.register64);
256
 
              if (right.location.loc<>LOC_CREGISTER) then
257
 
               begin
258
 
                 location_freetemp(exprasmlist,right.location);
259
 
                 location_release(exprasmlist,right.location);
260
 
               end;
261
 
            end;
262
 
         end;
263
 
 
264
 
        { only in case of overflow operations }
265
 
        { produce overflow code }
266
 
        { we must put it here directly, because sign of operation }
267
 
        { is in unsigned VAR!!                              }
268
 
        if mboverflow then
269
 
         begin
270
 
           if cs_check_overflow in aktlocalswitches  then
271
 
            begin
272
 
              objectlibrary.getlabel(hl4);
273
 
              if unsigned then
274
 
                cg.a_jmp_flags(exprasmlist,F_AE,hl4)
275
 
              else
276
 
                cg.a_jmp_flags(exprasmlist,F_NO,hl4);
277
 
              cg.a_call_name(exprasmlist,'FPC_OVERFLOW');
278
 
              cg.a_label(exprasmlist,hl4);
279
 
            end;
280
 
         end;
281
 
 
282
 
        location_copy(location,left.location);
283
 
      end;
284
 
 
285
 
 
286
 
    procedure ti386addnode.second_cmp64bit;
287
 
      var
288
 
        hregister,
289
 
        hregister2 : tregister;
290
 
        href       : treference;
291
 
        unsigned   : boolean;
292
 
 
293
 
      procedure firstjmp64bitcmp;
294
 
 
295
 
        var
296
 
           oldnodetype : tnodetype;
297
 
 
298
 
        begin
299
 
{$ifdef OLDREGVARS}
300
 
           load_all_regvars(exprasmlist);
301
 
{$endif OLDREGVARS}
302
 
           { the jump the sequence is a little bit hairy }
303
 
           case nodetype of
304
 
              ltn,gtn:
305
 
                begin
306
 
                   cg.a_jmp_flags(exprasmlist,getresflags(unsigned),truelabel);
307
 
                   { cheat a little bit for the negative test }
308
 
                   toggleflag(nf_swaped);
309
 
                   cg.a_jmp_flags(exprasmlist,getresflags(unsigned),falselabel);
310
 
                   toggleflag(nf_swaped);
311
 
                end;
312
 
              lten,gten:
313
 
                begin
314
 
                   oldnodetype:=nodetype;
315
 
                   if nodetype=lten then
316
 
                     nodetype:=ltn
317
 
                   else
318
 
                     nodetype:=gtn;
319
 
                   cg.a_jmp_flags(exprasmlist,getresflags(unsigned),truelabel);
320
 
                   { cheat for the negative test }
321
 
                   if nodetype=ltn then
322
 
                     nodetype:=gtn
323
 
                   else
324
 
                     nodetype:=ltn;
325
 
                   cg.a_jmp_flags(exprasmlist,getresflags(unsigned),falselabel);
326
 
                   nodetype:=oldnodetype;
327
 
                end;
328
 
              equaln:
329
 
                cg.a_jmp_flags(exprasmlist,F_NE,falselabel);
330
 
              unequaln:
331
 
                cg.a_jmp_flags(exprasmlist,F_NE,truelabel);
332
 
           end;
333
 
        end;
334
 
 
335
 
      procedure secondjmp64bitcmp;
336
 
 
337
 
        begin
338
 
           { the jump the sequence is a little bit hairy }
339
 
           case nodetype of
340
 
              ltn,gtn,lten,gten:
341
 
                begin
342
 
                   { the comparisaion of the low dword have to be }
343
 
                   {  always unsigned!                            }
344
 
                   cg.a_jmp_flags(exprasmlist,getresflags(true),truelabel);
345
 
                   cg.a_jmp_always(exprasmlist,falselabel);
346
 
                end;
347
 
              equaln:
348
 
                begin
349
 
                   cg.a_jmp_flags(exprasmlist,F_NE,falselabel);
350
 
                   cg.a_jmp_always(exprasmlist,truelabel);
351
 
                end;
352
 
              unequaln:
353
 
                begin
354
 
                   cg.a_jmp_flags(exprasmlist,F_NE,truelabel);
355
 
                   cg.a_jmp_always(exprasmlist,falselabel);
356
 
                end;
357
 
           end;
358
 
        end;
359
 
 
360
 
      begin
361
 
        firstcomplex(self);
362
 
 
363
 
        pass_left_right;
364
 
 
365
 
        unsigned:=((left.resulttype.def.deftype=orddef) and
366
 
                   (torddef(left.resulttype.def).typ=u64bit)) or
367
 
                  ((right.resulttype.def.deftype=orddef) and
368
 
                   (torddef(right.resulttype.def).typ=u64bit));
369
 
 
370
 
        { left and right no register?  }
371
 
        { then one must be demanded    }
372
 
        if (left.location.loc<>LOC_REGISTER) then
373
 
         begin
374
 
           if (right.location.loc<>LOC_REGISTER) then
375
 
            begin
376
 
              { we can reuse a CREGISTER for comparison }
377
 
              if (left.location.loc<>LOC_CREGISTER) then
378
 
               begin
379
 
                 hregister:=cg.getintregister(exprasmlist,OS_INT);
380
 
                 hregister2:=cg.getintregister(exprasmlist,OS_INT);
381
 
                 cg64.a_load64_loc_reg(exprasmlist,left.location,joinreg64(hregister,hregister2));
382
 
                 location_reset(left.location,LOC_REGISTER,OS_64);
383
 
                 left.location.registerlow:=hregister;
384
 
                 left.location.registerhigh:=hregister2;
385
 
               end;
386
 
            end
387
 
           else
388
 
            begin
389
 
              location_swap(left.location,right.location);
390
 
              toggleflag(nf_swaped);
391
 
            end;
392
 
         end;
393
 
 
394
 
        { at this point, left.location.loc should be LOC_REGISTER }
395
 
        if right.location.loc=LOC_REGISTER then
396
 
         begin
397
 
           emit_reg_reg(A_CMP,S_L,right.location.registerhigh,left.location.registerhigh);
398
 
           firstjmp64bitcmp;
399
 
           emit_reg_reg(A_CMP,S_L,right.location.registerlow,left.location.registerlow);
400
 
           secondjmp64bitcmp;
401
 
           location_release(exprasmlist,right.location);
402
 
         end
403
 
        else
404
 
         begin
405
 
           case right.location.loc of
406
 
             LOC_CREGISTER :
407
 
               begin
408
 
                 emit_reg_reg(A_CMP,S_L,right.location.registerhigh,left.location.registerhigh);
409
 
                 firstjmp64bitcmp;
410
 
                 emit_reg_reg(A_CMP,S_L,right.location.registerlow,left.location.registerlow);
411
 
                 secondjmp64bitcmp;
412
 
               end;
413
 
             LOC_CREFERENCE,
414
 
             LOC_REFERENCE :
415
 
               begin
416
 
                 href:=right.location.reference;
417
 
                 inc(href.offset,4);
418
 
                 emit_ref_reg(A_CMP,S_L,href,left.location.registerhigh);
419
 
                 firstjmp64bitcmp;
420
 
                 emit_ref_reg(A_CMP,S_L,right.location.reference,left.location.registerlow);
421
 
                 secondjmp64bitcmp;
422
 
                 cg.a_jmp_always(exprasmlist,falselabel);
423
 
                 location_freetemp(exprasmlist,right.location);
424
 
                 location_release(exprasmlist,right.location);
425
 
               end;
426
 
             LOC_CONSTANT :
427
 
               begin
428
 
                 exprasmlist.concat(taicpu.op_const_reg(A_CMP,S_L,aword(hi(right.location.valueqword)),left.location.registerhigh));
429
 
                 firstjmp64bitcmp;
430
 
                 exprasmlist.concat(taicpu.op_const_reg(A_CMP,S_L,aword(lo(right.location.valueqword)),left.location.registerlow));
431
 
                 secondjmp64bitcmp;
432
 
               end;
433
 
             else
434
 
               internalerror(200203282);
435
 
           end;
436
 
         end;
437
 
 
438
 
        if (left.location.loc<>LOC_CREGISTER) then
439
 
         begin
440
 
           location_freetemp(exprasmlist,left.location);
441
 
           location_release(exprasmlist,left.location);
442
 
         end;
443
 
 
444
 
        { we have LOC_JUMP as result }
445
 
        location_reset(location,LOC_JUMP,OS_NO)
446
 
      end;
447
 
 
448
 
 
449
 
{*****************************************************************************
450
 
                                AddMMX
451
 
*****************************************************************************}
452
 
 
453
 
{$ifdef SUPPORT_MMX}
454
 
    procedure ti386addnode.second_addmmx;
455
 
      var
456
 
        op         : TAsmOp;
457
 
        pushedfpu,
458
 
        cmpop      : boolean;
459
 
        mmxbase    : tmmxtype;
460
 
        hreg,
461
 
        hregister  : tregister;
462
 
      begin
463
 
        pass_left_and_right(pushedfpu);
464
 
 
465
 
        cmpop:=false;
466
 
        mmxbase:=mmx_type(left.resulttype.def);
467
 
        case nodetype of
468
 
          addn :
469
 
            begin
470
 
              if (cs_mmx_saturation in aktlocalswitches) then
471
 
                begin
472
 
                   case mmxbase of
473
 
                      mmxs8bit:
474
 
                        op:=A_PADDSB;
475
 
                      mmxu8bit:
476
 
                        op:=A_PADDUSB;
477
 
                      mmxs16bit,mmxfixed16:
478
 
                        op:=A_PADDSB;
479
 
                      mmxu16bit:
480
 
                        op:=A_PADDUSW;
481
 
                   end;
482
 
                end
483
 
              else
484
 
                begin
485
 
                   case mmxbase of
486
 
                      mmxs8bit,mmxu8bit:
487
 
                        op:=A_PADDB;
488
 
                      mmxs16bit,mmxu16bit,mmxfixed16:
489
 
                        op:=A_PADDW;
490
 
                      mmxs32bit,mmxu32bit:
491
 
                        op:=A_PADDD;
492
 
                   end;
493
 
                end;
494
 
            end;
495
 
          muln :
496
 
            begin
497
 
               case mmxbase of
498
 
                  mmxs16bit,mmxu16bit:
499
 
                    op:=A_PMULLW;
500
 
                  mmxfixed16:
501
 
                    op:=A_PMULHW;
502
 
               end;
503
 
            end;
504
 
          subn :
505
 
            begin
506
 
              if (cs_mmx_saturation in aktlocalswitches) then
507
 
                begin
508
 
                   case mmxbase of
509
 
                      mmxs8bit:
510
 
                        op:=A_PSUBSB;
511
 
                      mmxu8bit:
512
 
                        op:=A_PSUBUSB;
513
 
                      mmxs16bit,mmxfixed16:
514
 
                        op:=A_PSUBSB;
515
 
                      mmxu16bit:
516
 
                        op:=A_PSUBUSW;
517
 
                   end;
518
 
                end
519
 
              else
520
 
                begin
521
 
                   case mmxbase of
522
 
                      mmxs8bit,mmxu8bit:
523
 
                        op:=A_PSUBB;
524
 
                      mmxs16bit,mmxu16bit,mmxfixed16:
525
 
                        op:=A_PSUBW;
526
 
                      mmxs32bit,mmxu32bit:
527
 
                        op:=A_PSUBD;
528
 
                   end;
529
 
                end;
530
 
            end;
531
 
          xorn:
532
 
            op:=A_PXOR;
533
 
          orn:
534
 
            op:=A_POR;
535
 
          andn:
536
 
            op:=A_PAND;
537
 
          else
538
 
            internalerror(2003042214);
539
 
        end;
540
 
 
541
 
        { left and right no register?  }
542
 
        { then one must be demanded    }
543
 
        if (left.location.loc<>LOC_MMXREGISTER) then
544
 
         begin
545
 
           if (right.location.loc=LOC_MMXREGISTER) then
546
 
            begin
547
 
              location_swap(left.location,right.location);
548
 
              toggleflag(nf_swaped);
549
 
            end
550
 
           else
551
 
            begin
552
 
              { register variable ? }
553
 
              if (left.location.loc=LOC_CMMXREGISTER) then
554
 
               begin
555
 
                 hregister:=cg.getmmxregister(exprasmlist,OS_M64);
556
 
                 emit_reg_reg(A_MOVQ,S_NO,left.location.register,hregister);
557
 
               end
558
 
              else
559
 
               begin
560
 
                 if not(left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
561
 
                  internalerror(200203245);
562
 
 
563
 
                 location_release(exprasmlist,left.location);
564
 
 
565
 
                 hregister:=cg.getmmxregister(exprasmlist,OS_M64);
566
 
                 emit_ref_reg(A_MOVQ,S_NO,left.location.reference,hregister);
567
 
               end;
568
 
 
569
 
              location_reset(left.location,LOC_MMXREGISTER,OS_NO);
570
 
              left.location.register:=hregister;
571
 
            end;
572
 
         end;
573
 
 
574
 
        { at this point, left.location.loc should be LOC_MMXREGISTER }
575
 
        if right.location.loc<>LOC_MMXREGISTER then
576
 
         begin
577
 
           if (nodetype=subn) and (nf_swaped in flags) then
578
 
            begin
579
 
              if right.location.loc=LOC_CMMXREGISTER then
580
 
               begin
581
 
                 hreg:=cg.getmmxregister(exprasmlist,OS_M64);
582
 
                 emit_reg_reg(A_MOVQ,S_NO,right.location.register,hreg);
583
 
                 emit_reg_reg(op,S_NO,left.location.register,hreg);
584
 
                 cg.ungetregister(exprasmlist,hreg);
585
 
                 emit_reg_reg(A_MOVQ,S_NO,hreg,left.location.register);
586
 
               end
587
 
              else
588
 
               begin
589
 
                 if not(left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
590
 
                  internalerror(200203247);
591
 
                 location_release(exprasmlist,right.location);
592
 
                 hreg:=cg.getmmxregister(exprasmlist,OS_M64);
593
 
                 emit_ref_reg(A_MOVQ,S_NO,right.location.reference,hreg);
594
 
                 emit_reg_reg(op,S_NO,left.location.register,hreg);
595
 
                 cg.ungetregister(exprasmlist,hreg);
596
 
                 emit_reg_reg(A_MOVQ,S_NO,hreg,left.location.register);
597
 
               end;
598
 
            end
599
 
           else
600
 
            begin
601
 
              if (right.location.loc=LOC_CMMXREGISTER) then
602
 
                emit_reg_reg(op,S_NO,right.location.register,left.location.register)
603
 
              else
604
 
               begin
605
 
                 if not(right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
606
 
                  internalerror(200203246);
607
 
                 emit_ref_reg(op,S_NO,right.location.reference,left.location.register);
608
 
                 location_release(exprasmlist,right.location);
609
 
               end;
610
 
            end;
611
 
          end
612
 
        else
613
 
          begin
614
 
            { right.location=LOC_MMXREGISTER }
615
 
            if (nodetype=subn) and (nf_swaped in flags) then
616
 
             begin
617
 
               emit_reg_reg(op,S_NO,left.location.register,right.location.register);
618
 
               location_swap(left.location,right.location);
619
 
               toggleflag(nf_swaped);
620
 
             end
621
 
            else
622
 
             begin
623
 
               emit_reg_reg(op,S_NO,right.location.register,left.location.register);
624
 
             end;
625
 
          end;
626
 
 
627
 
        location_freetemp(exprasmlist,right.location);
628
 
        location_release(exprasmlist,right.location);
629
 
        if cmpop then
630
 
         begin
631
 
           location_freetemp(exprasmlist,left.location);
632
 
           location_release(exprasmlist,left.location);
633
 
         end;
634
 
        set_result_location(cmpop,true);
635
 
      end;
636
 
{$endif SUPPORT_MMX}
637
 
 
638
 
 
639
 
{*****************************************************************************
640
 
                                x86 MUL
641
 
*****************************************************************************}
642
 
 
643
 
    procedure ti386addnode.second_mul;
644
 
 
645
 
    var r:Tregister;
646
 
        hl4 : tasmlabel;
647
 
 
648
 
    begin
649
 
      {The location.register will be filled in later (JM)}
650
 
      location_reset(location,LOC_REGISTER,OS_INT);
651
 
      {Get a temp register and load the left value into it
652
 
       and free the location.}
653
 
      r:=cg.getintregister(exprasmlist,OS_INT);
654
 
      cg.a_load_loc_reg(exprasmlist,OS_INT,left.location,r);
655
 
      location_release(exprasmlist,left.location);
656
 
      {Allocate EAX.}
657
 
      cg.getexplicitregister(exprasmlist,NR_EAX);
658
 
      {Load the right value.}
659
 
      cg.a_load_loc_reg(exprasmlist,OS_INT,right.location,NR_EAX);
660
 
      location_release(exprasmlist,right.location);
661
 
      {The mul instruction frees register r.}
662
 
      cg.ungetregister(exprasmlist,r);
663
 
      {Also allocate EDX, since it is also modified by a mul (JM).}
664
 
      cg.getexplicitregister(exprasmlist,NR_EDX);
665
 
      emit_reg(A_MUL,S_L,r);
666
 
      if cs_check_overflow in aktlocalswitches  then
667
 
       begin
668
 
         objectlibrary.getlabel(hl4);
669
 
         cg.a_jmp_flags(exprasmlist,F_AE,hl4);
670
 
         cg.a_call_name(exprasmlist,'FPC_OVERFLOW');
671
 
         cg.a_label(exprasmlist,hl4);
672
 
       end;
673
 
      {Free EDX}
674
 
      cg.ungetregister(exprasmlist,NR_EDX);
675
 
      {Free EAX}
676
 
      cg.ungetregister(exprasmlist,NR_EAX);
677
 
      {Allocate a new register and store the result in EAX in it.}
678
 
      location.register:=cg.getintregister(exprasmlist,OS_INT);
679
 
      emit_reg_reg(A_MOV,S_L,NR_EAX,location.register);
680
 
      location_freetemp(exprasmlist,left.location);
681
 
      location_freetemp(exprasmlist,right.location);
682
 
    end;
683
 
 
684
 
 
685
 
begin
686
 
   caddnode:=ti386addnode;
687
 
end.
688
 
{
689
 
  $Log: n386add.pas,v $
690
 
  Revision 1.96  2004/05/19 23:30:18  peter
691
 
    * extra typecast to prevent range check
692
 
 
693
 
  Revision 1.95  2004/02/04 19:22:27  peter
694
 
  *** empty log message ***
695
 
 
696
 
  Revision 1.94  2004/01/20 12:59:37  florian
697
 
    * common addnode code for x86-64 and i386
698
 
 
699
 
  Revision 1.93  2004/01/14 17:19:04  peter
700
 
    * disable addmmxset
701
 
}