diff options
| author | 2020-07-07 16:39:23 -0500 | |
|---|---|---|
| committer | 2020-07-11 18:39:00 +0200 | |
| commit | a4306b9e5662fca74f65f0b657e7002fda7f1829 (patch) | |
| tree | cbd176cf7b3dd85cde0b8fb65f8df38727d1c9a5 /src/common/alignment.h | |
| parent | Merge pull request #4203 from VolcaEM/services (diff) | |
| download | yuzu-a4306b9e5662fca74f65f0b657e7002fda7f1829.tar.gz yuzu-a4306b9e5662fca74f65f0b657e7002fda7f1829.tar.xz yuzu-a4306b9e5662fca74f65f0b657e7002fda7f1829.zip | |
Common: remove a mod from AlignUp (#5441)
In cases where the size is not a known constant when inlining, AlignUp<std::size_t> currently generates two 64-bit div instructions.
This generates one div and a cmov which is significantly cheaper.
Diffstat (limited to 'src/common/alignment.h')
| -rw-r--r-- | src/common/alignment.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h index f8c49e079..516bb26c1 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h | |||
| @@ -11,7 +11,9 @@ namespace Common { | |||
| 11 | template <typename T> | 11 | template <typename T> |
| 12 | constexpr T AlignUp(T value, std::size_t size) { | 12 | constexpr T AlignUp(T value, std::size_t size) { |
| 13 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); | 13 | static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); |
| 14 | return static_cast<T>(value + (size - value % size) % size); | 14 | auto mod{value % size}; |
| 15 | value -= mod; | ||
| 16 | return static_cast<T>(mod == T{0} ? value : value + size); | ||
| 15 | } | 17 | } |
| 16 | 18 | ||
| 17 | template <typename T> | 19 | template <typename T> |