1 /*
2  * Copyright (C) 2014 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 #ifndef ART_RUNTIME_ARCH_MIPS_QUICK_METHOD_FRAME_INFO_MIPS_H_
18 #define ART_RUNTIME_ARCH_MIPS_QUICK_METHOD_FRAME_INFO_MIPS_H_
19 
20 #include "arch/instruction_set.h"
21 #include "base/bit_utils.h"
22 #include "base/callee_save_type.h"
23 #include "base/enums.h"
24 #include "quick/quick_method_frame_info.h"
25 #include "registers_mips.h"
26 
27 namespace art {
28 namespace mips {
29 
30 static constexpr uint32_t kMipsCalleeSaveAlwaysSpills =
31     (1u << art::mips::RA);
32 static constexpr uint32_t kMipsCalleeSaveRefSpills =
33     (1 << art::mips::S2) | (1 << art::mips::S3) | (1 << art::mips::S4) | (1 << art::mips::S5) |
34     (1 << art::mips::S6) | (1 << art::mips::S7) | (1 << art::mips::GP) | (1 << art::mips::FP);
35 static constexpr uint32_t kMipsCalleeSaveArgSpills =
36     (1 << art::mips::A1) | (1 << art::mips::A2) | (1 << art::mips::A3) | (1 << art::mips::T0) |
37     (1 << art::mips::T1);
38 // We want to save all floating point register pairs at addresses
39 // which are multiples of 8 so that we can eliminate use of the
40 // SDu/LDu macros by using sdc1/ldc1 to store/load floating
41 // register values using a single instruction. Because integer
42 // registers are stored at the top of the frame, to achieve having
43 // the floating point register pairs aligned on multiples of 8 the
44 // number of integer registers saved must be even. Previously, the
45 // only case in which we saved floating point registers beneath an
46 // odd number of integer registers was when "type" is
47 // CalleeSaveType::kSaveAllCalleeSaves. (There are other cases in
48 // which an odd number of integer registers are saved but those
49 // cases don't save any floating point registers. If no floating
50 // point registers are saved we don't care if the number of integer
51 // registers saved is odd or even). To save an even number of
52 // integer registers in this particular case we add the ZERO
53 // register to the list of registers which get saved.
54 static constexpr uint32_t kMipsCalleeSaveAllSpills =
55     (1 << art::mips::ZERO) | (1 << art::mips::S0) | (1 << art::mips::S1);
56 static constexpr uint32_t kMipsCalleeSaveEverythingSpills =
57     (1 << art::mips::AT) | (1 << art::mips::V0) | (1 << art::mips::V1) |
58     (1 << art::mips::A0) | (1 << art::mips::A1) | (1 << art::mips::A2) | (1 << art::mips::A3) |
59     (1 << art::mips::T0) | (1 << art::mips::T1) | (1 << art::mips::T2) | (1 << art::mips::T3) |
60     (1 << art::mips::T4) | (1 << art::mips::T5) | (1 << art::mips::T6) | (1 << art::mips::T7) |
61     (1 << art::mips::S0) | (1 << art::mips::S1) | (1 << art::mips::T8) | (1 << art::mips::T9);
62 
63 static constexpr uint32_t kMipsCalleeSaveFpAlwaysSpills = 0;
64 static constexpr uint32_t kMipsCalleeSaveFpRefSpills = 0;
65 static constexpr uint32_t kMipsCalleeSaveFpArgSpills =
66     (1 << art::mips::F8) | (1 << art::mips::F9) | (1 << art::mips::F10) | (1 << art::mips::F11) |
67     (1 << art::mips::F12) | (1 << art::mips::F13) | (1 << art::mips::F14) | (1 << art::mips::F15) |
68     (1 << art::mips::F16) | (1 << art::mips::F17) | (1 << art::mips::F18) | (1 << art::mips::F19);
69 static constexpr uint32_t kMipsCalleeSaveAllFPSpills =
70     (1 << art::mips::F20) | (1 << art::mips::F21) | (1 << art::mips::F22) | (1 << art::mips::F23) |
71     (1 << art::mips::F24) | (1 << art::mips::F25) | (1 << art::mips::F26) | (1 << art::mips::F27) |
72     (1 << art::mips::F28) | (1 << art::mips::F29) | (1 << art::mips::F30) | (1u << art::mips::F31);
73 static constexpr uint32_t kMipsCalleeSaveFpEverythingSpills =
74     (1 << art::mips::F0) | (1 << art::mips::F1) | (1 << art::mips::F2) | (1 << art::mips::F3) |
75     (1 << art::mips::F4) | (1 << art::mips::F5) | (1 << art::mips::F6) | (1 << art::mips::F7) |
76     (1 << art::mips::F8) | (1 << art::mips::F9) | (1 << art::mips::F10) | (1 << art::mips::F11) |
77     (1 << art::mips::F12) | (1 << art::mips::F13) | (1 << art::mips::F14) | (1 << art::mips::F15) |
78     (1 << art::mips::F16) | (1 << art::mips::F17) | (1 << art::mips::F18) | (1 << art::mips::F19) |
79     (1 << art::mips::F20) | (1 << art::mips::F21) | (1 << art::mips::F22) | (1 << art::mips::F23) |
80     (1 << art::mips::F24) | (1 << art::mips::F25) | (1 << art::mips::F26) | (1 << art::mips::F27) |
81     (1 << art::mips::F28) | (1 << art::mips::F29) | (1 << art::mips::F30) | (1u << art::mips::F31);
82 
MipsCalleeSaveCoreSpills(CalleeSaveType type)83 constexpr uint32_t MipsCalleeSaveCoreSpills(CalleeSaveType type) {
84   type = GetCanonicalCalleeSaveType(type);
85   return kMipsCalleeSaveAlwaysSpills | kMipsCalleeSaveRefSpills |
86       (type == CalleeSaveType::kSaveRefsAndArgs ? kMipsCalleeSaveArgSpills : 0) |
87       (type == CalleeSaveType::kSaveAllCalleeSaves ? kMipsCalleeSaveAllSpills : 0) |
88       (type == CalleeSaveType::kSaveEverything ? kMipsCalleeSaveEverythingSpills : 0);
89 }
90 
MipsCalleeSaveFPSpills(CalleeSaveType type)91 constexpr uint32_t MipsCalleeSaveFPSpills(CalleeSaveType type) {
92   type = GetCanonicalCalleeSaveType(type);
93   return kMipsCalleeSaveFpAlwaysSpills | kMipsCalleeSaveFpRefSpills |
94       (type == CalleeSaveType::kSaveRefsAndArgs ? kMipsCalleeSaveFpArgSpills : 0) |
95       (type == CalleeSaveType::kSaveAllCalleeSaves ? kMipsCalleeSaveAllFPSpills : 0) |
96       (type == CalleeSaveType::kSaveEverything ? kMipsCalleeSaveFpEverythingSpills : 0);
97 }
98 
MipsCalleeSaveFrameSize(CalleeSaveType type)99 constexpr uint32_t MipsCalleeSaveFrameSize(CalleeSaveType type) {
100   type = GetCanonicalCalleeSaveType(type);
101   return RoundUp((POPCOUNT(MipsCalleeSaveCoreSpills(type)) /* gprs */ +
102                   POPCOUNT(MipsCalleeSaveFPSpills(type))   /* fprs */ +
103                   1 /* Method* */) * static_cast<size_t>(kMipsPointerSize), kStackAlignment);
104 }
105 
MipsCalleeSaveMethodFrameInfo(CalleeSaveType type)106 constexpr QuickMethodFrameInfo MipsCalleeSaveMethodFrameInfo(CalleeSaveType type) {
107   type = GetCanonicalCalleeSaveType(type);
108   return QuickMethodFrameInfo(MipsCalleeSaveFrameSize(type),
109                               MipsCalleeSaveCoreSpills(type),
110                               MipsCalleeSaveFPSpills(type));
111 }
112 
113 }  // namespace mips
114 }  // namespace art
115 
116 #endif  // ART_RUNTIME_ARCH_MIPS_QUICK_METHOD_FRAME_INFO_MIPS_H_
117