Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #9566 from Sintendo/jit64divwx
Jit64: Optimize divwx
- Loading branch information
Showing
8 changed files
with
329 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright 2021 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #include <cstdlib> | ||
|
|
||
| #include "Core/PowerPC/JitCommon/DivUtils.h" | ||
|
|
||
| namespace JitCommon | ||
| { | ||
| Magic SignedDivisionConstants(s32 d) | ||
| { | ||
| const u32 two31 = 2147483648; | ||
|
|
||
| const u32 ad = std::abs(d); | ||
| const u32 t = two31 - (d < 0); | ||
| const u32 anc = t - 1 - t % ad; | ||
| u32 q1 = two31 / anc; | ||
| u32 r1 = two31 - q1 * anc; | ||
| u32 q2 = two31 / ad; | ||
| u32 r2 = two31 - q2 * ad; | ||
|
|
||
| s32 p = 31; | ||
| u32 delta; | ||
|
|
||
| do | ||
| { | ||
| p++; | ||
|
|
||
| q1 *= 2; | ||
| r1 *= 2; | ||
| if (r1 >= anc) | ||
| { | ||
| q1++; | ||
| r1 -= anc; | ||
| } | ||
|
|
||
| q2 *= 2; | ||
| r2 *= 2; | ||
| if (r2 >= ad) | ||
| { | ||
| q2++; | ||
| r2 -= ad; | ||
| } | ||
| delta = ad - r2; | ||
| } while (q1 < delta || (q1 == delta && r1 == 0)); | ||
|
|
||
| Magic mag; | ||
| mag.multiplier = q2 + 1; | ||
| if (d < 0) | ||
| mag.multiplier = -mag.multiplier; | ||
| mag.shift = p - 32; | ||
|
|
||
| return mag; | ||
| } | ||
|
|
||
| } // namespace JitCommon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright 2021 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "Common/CommonTypes.h" | ||
|
|
||
| namespace JitCommon | ||
| { | ||
| struct Magic | ||
| { | ||
| s32 multiplier; | ||
| u8 shift; | ||
| }; | ||
|
|
||
| // Calculate the constants required to optimize a signed 32-bit integer division. | ||
| // Taken from The PowerPC Compiler Writer's Guide and LLVM. | ||
| // Divisor must not be -1, 0, and 1. | ||
| Magic SignedDivisionConstants(s32 divisor); | ||
|
|
||
| } // namespace JitCommon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.