summaryrefslogtreecommitdiff
path: root/compiler/i386/n386inl.pas
blob: 887f9e2b0287d86b70bb103113a2c83a29bd6aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{
    Copyright (c) 1998-2002 by Florian Klaempfl

    Generate i386 inline nodes

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************
}
unit n386inl;

{$i fpcdefs.inc}

interface

    uses
       node,nx86inl;

    type
       ti386inlinenode = class(tx86inlinenode)
       public
         function first_sar: tnode; override;
         procedure second_rox_sar; override;
       end;

implementation

  uses
    globtype,globals,
    defutil,
    aasmbase,aasmdata,
    cgbase,pass_2,
    cpuinfo,cpubase,
    cga,cgutils,cgx86,cgobj,hlcgobj,
    ninl,ncon,ncal;


  function ti386inlinenode.first_sar: tnode;
    begin
      if is_64bitint(resultdef) and (
        (inlinenumber=in_sar_x) or (
          (inlinenumber=in_sar_x_y) and
          (tcallparanode(left).left.nodetype=ordconstn)
      )) then
        begin
          result:=nil;
          expectloc:=LOC_REGISTER;
        end
      else
        result:=inherited first_sar;
    end;


  procedure ti386inlinenode.second_rox_sar;
    var
      op1: tnode;
      hreg64hi,hreg64lo: tregister;
      v: aint;
    begin
      if is_64bitint(resultdef) and (
        (inlinenumber=in_sar_x) or (
          (inlinenumber=in_sar_x_y) and
          (tcallparanode(left).left.nodetype=ordconstn)
      )) then
        begin
          { x sar constant }
          if (left.nodetype=callparan) and
             assigned(tcallparanode(left).right) then
            begin
              op1:=tcallparanode(tcallparanode(left).right).left;
              secondpass(tcallparanode(left).left);
              v:=Tordconstnode(tcallparanode(left).left).value.svalue and 63;
            end
          else
            begin
              op1:=left;
              v:=1;
            end;
          secondpass(op1);

          location_reset(location,LOC_REGISTER,def_cgsize(resultdef));

          { load left operator in a register }
          hlcg.location_force_reg(current_asmdata.CurrAsmList,op1.location,op1.resultdef,resultdef,false);
          hreg64hi:=op1.location.register64.reghi;
          hreg64lo:=op1.location.register64.reglo;

          if (v=63) then
            begin
              emit_const_reg(A_SAR,S_L,31,hreg64hi);
              cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,hreg64hi,hreg64lo);
            end
          else if (v>31) then
            begin
              cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,hreg64hi,hreg64lo);
              emit_const_reg(A_SAR,S_L,31,hreg64hi);
              emit_const_reg(A_SAR,S_L,v and 31,hreg64lo);
            end
          else
            begin
              emit_const_reg_reg(A_SHRD,S_L,v and 31,hreg64hi,hreg64lo);
              emit_const_reg(A_SAR,S_L,v and 31,hreg64hi);
            end;
          location.register64.reghi:=hreg64hi;
          location.register64.reglo:=hreg64lo;
        end
      else
        inherited second_rox_sar;
    end;


begin
   cinlinenode:=ti386inlinenode;
end.