summaryrefslogtreecommitdiff
path: root/compiler/arm/narmcon.pas
blob: e87a38b639b8811b0c1391b589975c17ba38c027 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
    Copyright (c) 2005 by Florian Klaempfl

    Code generation for const nodes on the ARM

    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 narmcon;

{$i fpcdefs.inc}

interface

    uses
      node,ncgcon,cpubase;

    type
      tarmrealconstnode = class(tcgrealconstnode)
        function pass_1 : tnode;override;
        procedure pass_generate_code;override;
      end;

  implementation

    uses
      verbose,
      globtype,globals,
      cpuinfo,
      aasmbase,aasmtai,aasmdata,aasmcpu,
      symdef,
      defutil,
      cgbase,cgutils,cgobj,
      procinfo,
      ncon;

{*****************************************************************************
                           TARMREALCONSTNODE
*****************************************************************************}

    function tarmrealconstnode.pass_1 : tnode;
      begin
        result:=nil;
        if (FPUARM_HAS_VMOV_CONST in fpu_capabilities[current_settings.fputype]) and
           IsVFPFloatImmediate(tfloatdef(resultdef).floattype,value_real) and
           ((tfloatdef(resultdef).floattype=s32real) or
            (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[init_settings.fputype])) then
           expectloc:=LOC_MMREGISTER
         else
           expectloc:=LOC_CREFERENCE;
      end;


    procedure tarmrealconstnode.pass_generate_code;
      { I suppose the parser/pass_1 must make sure the generated real  }
      { constants are actually supported by the target processor? (JM) }
      const
        floattype2ait:array[tfloattype] of tairealconsttype=
          (aitrealconst_s32bit,aitrealconst_s64bit,aitrealconst_s80bit,aitrealconst_s80bit,aitrealconst_s64comp,aitrealconst_s64comp,aitrealconst_s128bit);
      var
         lastlabel : tasmlabel;
         realait : tairealconsttype;
         hiloswapped : boolean;
         pf : TOpPostfix;

      begin
        if (FPUARM_HAS_VMOV_CONST in fpu_capabilities[current_settings.fputype]) and
          IsVFPFloatImmediate(tfloatdef(resultdef).floattype,value_real) and
           ((tfloatdef(resultdef).floattype=s32real) or
            (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[init_settings.fputype])) then
          begin
            location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
            location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
            if tfloatdef(resultdef).floattype=s32real then
              pf:=PF_F32
            else
              pf:=PF_F64;
            current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_realconst(A_VMOV,
               location.register,value_real),pf));
          end
        else
          begin
            location_reset_ref(location,LOC_CREFERENCE,def_cgsize(resultdef),4,[]);
            lastlabel:=nil;
            realait:=floattype2ait[tfloatdef(resultdef).floattype];
            hiloswapped:=is_double_hilo_swapped;
            { const already used ? }
            if not assigned(lab_real) then
              begin
                current_asmdata.getjumplabel(lastlabel);
                lab_real:=lastlabel;
                current_procinfo.aktlocaldata.concat(Tai_label.Create(lastlabel));
                location.reference.symboldata:=current_procinfo.aktlocaldata.last;
                case realait of
                  aitrealconst_s32bit :
                    begin
                      current_procinfo.aktlocaldata.concat(tai_realconst.create_s32real(ts32real(value_real)));
                      { range checking? }
                      if floating_point_range_check_error and
                        (tai_realconst(current_procinfo.aktlocaldata.last).value.s32val=MathInf.Value) then
                        Message(parser_e_range_check_error);
                    end;

                  aitrealconst_s64bit :
                    begin
                      if hiloswapped then
                        current_procinfo.aktlocaldata.concat(tai_realconst.create_s64real_hiloswapped(ts64real(value_real)))
                      else
                        current_procinfo.aktlocaldata.concat(tai_realconst.create_s64real(ts64real(value_real)));

                      { range checking? }
                      if floating_point_range_check_error and
                        (tai_realconst(current_procinfo.aktlocaldata.last).value.s64val=MathInf.Value) then
                        Message(parser_e_range_check_error);
                   end;

                  aitrealconst_s80bit :
                    begin
                      current_procinfo.aktlocaldata.concat(tai_realconst.create_s80real(value_real,tfloatdef(resultdef).size));

                      { range checking? }
                      if floating_point_range_check_error and
                        (tai_realconst(current_procinfo.aktlocaldata.last).value.s80val=MathInf.Value) then
                        Message(parser_e_range_check_error);
                    end;
{$ifdef cpufloat128}
                  aitrealconst_s128bit :
                    begin
                      current_procinfo.aktlocaldata.concat(tai_realconst.create_s128real(value_real));

                      { range checking? }
                      if floating_point_range_check_error and
                        (tai_realconst(current_procinfo.aktlocaldata.last).value.s128val=MathInf.Value) then
                        Message(parser_e_range_check_error);
                    end;
{$endif cpufloat128}

                  { the round is necessary for native compilers where comp isn't a float }
                  aitrealconst_s64comp :
                    if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
                      message(parser_e_range_check_error)
                    else
                      current_procinfo.aktlocaldata.concat(tai_realconst.create_s64compreal(round(value_real)));
                else
                  internalerror(2005092401);
                end;
              end;
            location.reference.symbol:=lab_real;
            location.reference.base:=NR_R15;
          end;
      end;

begin
  crealconstnode:=tarmrealconstnode;
end.