OSDN Git Service

Add arm vfp support for the Jit
[android-x86/dalvik.git] / vm / compiler / codegen / armv5te / FpCodegen-armv5te-vfp.c
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "Dalvik.h"
18 #include "Armv5teLIR.h"
19 #include "Codegen.h"
20
21 bool dvmCompilerGenArithOpFloat(CompilationUnit *cUnit, MIR *mir, int vDest,
22                                 int vSrc1, int vSrc2)
23 {
24     TemplateOpCode opCode;
25
26     switch (mir->dalvikInsn.opCode) {
27         case OP_ADD_FLOAT_2ADDR:
28         case OP_ADD_FLOAT:
29             opCode = TEMPLATE_ADD_FLOAT_VFP;
30             break;
31         case OP_SUB_FLOAT_2ADDR:
32         case OP_SUB_FLOAT:
33             opCode = TEMPLATE_SUB_FLOAT_VFP;
34         case OP_DIV_FLOAT_2ADDR:
35         case OP_DIV_FLOAT:
36             opCode = TEMPLATE_DIV_FLOAT_VFP;
37             break;
38         case OP_MUL_FLOAT_2ADDR:
39         case OP_MUL_FLOAT:
40             opCode = TEMPLATE_MUL_FLOAT_VFP;
41             break;
42         case OP_REM_FLOAT_2ADDR:
43         case OP_REM_FLOAT:
44         case OP_NEG_FLOAT: {
45             return dvmCompilerGenArithOpFloatPortable(cUnit, mir, vDest,
46                                                       vSrc1, vSrc2);
47         }
48         default:
49             return true;
50     }
51     dvmCompilerLoadValueAddress(cUnit, vDest, r0);
52     dvmCompilerLoadValueAddress(cUnit, vSrc1, r1);
53     dvmCompilerLoadValueAddress(cUnit, vSrc2, r2);
54     dvmCompilerGenDispatchToHandler(cUnit, opCode);
55     return false;
56 }
57
58 bool dvmCompilerGenArithOpDouble(CompilationUnit *cUnit, MIR *mir, int vDest,
59                                  int vSrc1, int vSrc2)
60 {
61     TemplateOpCode opCode;
62
63     switch (mir->dalvikInsn.opCode) {
64         case OP_ADD_DOUBLE_2ADDR:
65         case OP_ADD_DOUBLE:
66             opCode = TEMPLATE_ADD_DOUBLE_VFP;
67             break;
68         case OP_SUB_DOUBLE_2ADDR:
69         case OP_SUB_DOUBLE:
70             opCode = TEMPLATE_SUB_DOUBLE_VFP;
71             break;
72         case OP_DIV_DOUBLE_2ADDR:
73         case OP_DIV_DOUBLE:
74             opCode = TEMPLATE_DIV_DOUBLE_VFP;
75             break;
76         case OP_MUL_DOUBLE_2ADDR:
77         case OP_MUL_DOUBLE:
78             opCode = TEMPLATE_MUL_DOUBLE_VFP;
79             break;
80         case OP_REM_DOUBLE_2ADDR:
81         case OP_REM_DOUBLE:
82         case OP_NEG_DOUBLE: {
83             return dvmCompilerGenArithOpDoublePortable(cUnit, mir, vDest,
84                                                        vSrc1, vSrc2);
85         }
86         default:
87             return true;
88     }
89     dvmCompilerLoadValueAddress(cUnit, vDest, r0);
90     dvmCompilerLoadValueAddress(cUnit, vSrc1, r1);
91     dvmCompilerLoadValueAddress(cUnit, vSrc2, r2);
92     dvmCompilerGenDispatchToHandler(cUnit, opCode);
93     return false;
94 }
95
96 bool dvmCompilerGenConversion(CompilationUnit *cUnit, MIR *mir)
97 {
98     OpCode opCode = mir->dalvikInsn.opCode;
99     int vSrc1Dest = mir->dalvikInsn.vA;
100     int vSrc2 = mir->dalvikInsn.vB;
101     TemplateOpCode template;
102
103     switch (opCode) {
104         case OP_INT_TO_FLOAT:
105             template = TEMPLATE_INT_TO_FLOAT_VFP;
106             break;
107         case OP_FLOAT_TO_INT:
108             template = TEMPLATE_FLOAT_TO_INT_VFP;
109             break;
110         case OP_DOUBLE_TO_FLOAT:
111             template = TEMPLATE_DOUBLE_TO_FLOAT_VFP;
112             break;
113         case OP_FLOAT_TO_DOUBLE:
114             template = TEMPLATE_FLOAT_TO_DOUBLE_VFP;
115             break;
116         case OP_INT_TO_DOUBLE:
117             template = TEMPLATE_INT_TO_DOUBLE_VFP;
118             break;
119         case OP_DOUBLE_TO_INT:
120             template = TEMPLATE_DOUBLE_TO_INT_VFP;
121             break;
122         case OP_FLOAT_TO_LONG:
123         case OP_LONG_TO_FLOAT:
124         case OP_DOUBLE_TO_LONG:
125         case OP_LONG_TO_DOUBLE:
126             return dvmCompilerGenConversionPortable(cUnit, mir);
127         default:
128             return true;
129     }
130     dvmCompilerLoadValueAddress(cUnit, vSrc1Dest, r0);
131     dvmCompilerLoadValueAddress(cUnit, vSrc2, r1);
132     dvmCompilerGenDispatchToHandler(cUnit, template);
133     return false;
134 }
135
136 bool dvmCompilerGenCmpX(CompilationUnit *cUnit, MIR *mir, int vDest,
137                                 int vSrc1, int vSrc2)
138 {
139     TemplateOpCode template;
140     switch(mir->dalvikInsn.opCode) {
141         case OP_CMPL_FLOAT:
142             template = TEMPLATE_CMPL_FLOAT_VFP;
143             break;
144         case OP_CMPG_FLOAT:
145             template = TEMPLATE_CMPG_FLOAT_VFP;
146             break;
147         case OP_CMPL_DOUBLE:
148             template = TEMPLATE_CMPL_DOUBLE_VFP;
149             break;
150         case OP_CMPG_DOUBLE:
151             template = TEMPLATE_CMPG_DOUBLE_VFP;
152             break;
153         default:
154             return true;
155     }
156     dvmCompilerLoadValueAddress(cUnit, vSrc1, r0);
157     dvmCompilerLoadValueAddress(cUnit, vSrc2, r1);
158     dvmCompilerGenDispatchToHandler(cUnit, template);
159     dvmCompilerStoreValue(cUnit, r0, vDest, r1);
160     return false;
161 }