summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar MerryMage2020-06-15 19:04:29 +0100
committerGravatar MerryMage2020-06-15 19:07:11 +0100
commit7c6203dc5ed9a8b5ae9154602d27717569851571 (patch)
tree2449353ff029cdbc72f25372e04ccadd893a23d1
parentxbyak_abi: Register indexes should be unsigned (diff)
downloadyuzu-7c6203dc5ed9a8b5ae9154602d27717569851571.tar.gz
yuzu-7c6203dc5ed9a8b5ae9154602d27717569851571.tar.xz
yuzu-7c6203dc5ed9a8b5ae9154602d27717569851571.zip
xbyak_abi: Prefer returning a struct to using out parameters in ABI_CalculateFrameSize
Diffstat (limited to '')
-rw-r--r--src/common/x64/xbyak_abi.h36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h
index 33a96d6cb..a5f5d4fc1 100644
--- a/src/common/x64/xbyak_abi.h
+++ b/src/common/x64/xbyak_abi.h
@@ -151,9 +151,13 @@ constexpr size_t ABI_SHADOW_SPACE = 0;
151 151
152#endif 152#endif
153 153
154inline void ABI_CalculateFrameSize(std::bitset<32> regs, size_t rsp_alignment, 154struct ABIFrameInfo {
155 size_t needed_frame_size, s32* out_subtraction, 155 s32 subtraction;
156 s32* out_xmm_offset) { 156 s32 xmm_offset;
157};
158
159inline ABIFrameInfo ABI_CalculateFrameSize(std::bitset<32> regs, size_t rsp_alignment,
160 size_t needed_frame_size) {
157 const auto count = (regs & ABI_ALL_GPRS).count(); 161 const auto count = (regs & ABI_ALL_GPRS).count();
158 rsp_alignment -= count * 8; 162 rsp_alignment -= count * 8;
159 size_t subtraction = 0; 163 size_t subtraction = 0;
@@ -170,14 +174,13 @@ inline void ABI_CalculateFrameSize(std::bitset<32> regs, size_t rsp_alignment,
170 rsp_alignment -= subtraction; 174 rsp_alignment -= subtraction;
171 subtraction += rsp_alignment & 0xF; 175 subtraction += rsp_alignment & 0xF;
172 176
173 *out_subtraction = (s32)subtraction; 177 return ABIFrameInfo{static_cast<s32>(subtraction),
174 *out_xmm_offset = (s32)(subtraction - xmm_base_subtraction); 178 static_cast<s32>(subtraction - xmm_base_subtraction)};
175} 179}
176 180
177inline size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, std::bitset<32> regs, 181inline size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, std::bitset<32> regs,
178 size_t rsp_alignment, size_t needed_frame_size = 0) { 182 size_t rsp_alignment, size_t needed_frame_size = 0) {
179 s32 subtraction, xmm_offset; 183 auto frame_info = ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size);
180 ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset);
181 184
182 for (std::size_t i = 0; i < regs.size(); ++i) { 185 for (std::size_t i = 0; i < regs.size(); ++i) {
183 if (regs[i] && ABI_ALL_GPRS[i]) { 186 if (regs[i] && ABI_ALL_GPRS[i]) {
@@ -185,14 +188,14 @@ inline size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, std::b
185 } 188 }
186 } 189 }
187 190
188 if (subtraction != 0) { 191 if (frame_info.subtraction != 0) {
189 code.sub(code.rsp, subtraction); 192 code.sub(code.rsp, frame_info.subtraction);
190 } 193 }
191 194
192 for (std::size_t i = 0; i < regs.size(); ++i) { 195 for (std::size_t i = 0; i < regs.size(); ++i) {
193 if (regs[i] && ABI_ALL_XMMS[i]) { 196 if (regs[i] && ABI_ALL_XMMS[i]) {
194 code.movaps(code.xword[code.rsp + xmm_offset], IndexToXmm(i)); 197 code.movaps(code.xword[code.rsp + frame_info.xmm_offset], IndexToXmm(i));
195 xmm_offset += 0x10; 198 frame_info.xmm_offset += 0x10;
196 } 199 }
197 } 200 }
198 201
@@ -201,18 +204,17 @@ inline size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, std::b
201 204
202inline void ABI_PopRegistersAndAdjustStack(Xbyak::CodeGenerator& code, std::bitset<32> regs, 205inline void ABI_PopRegistersAndAdjustStack(Xbyak::CodeGenerator& code, std::bitset<32> regs,
203 size_t rsp_alignment, size_t needed_frame_size = 0) { 206 size_t rsp_alignment, size_t needed_frame_size = 0) {
204 s32 subtraction, xmm_offset; 207 auto frame_info = ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size);
205 ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset);
206 208
207 for (std::size_t i = 0; i < regs.size(); ++i) { 209 for (std::size_t i = 0; i < regs.size(); ++i) {
208 if (regs[i] && ABI_ALL_XMMS[i]) { 210 if (regs[i] && ABI_ALL_XMMS[i]) {
209 code.movaps(IndexToXmm(i), code.xword[code.rsp + xmm_offset]); 211 code.movaps(IndexToXmm(i), code.xword[code.rsp + frame_info.xmm_offset]);
210 xmm_offset += 0x10; 212 frame_info.xmm_offset += 0x10;
211 } 213 }
212 } 214 }
213 215
214 if (subtraction != 0) { 216 if (frame_info.subtraction != 0) {
215 code.add(code.rsp, subtraction); 217 code.add(code.rsp, frame_info.subtraction);
216 } 218 }
217 219
218 // GPRs need to be popped in reverse order 220 // GPRs need to be popped in reverse order