diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/common/hex_util.h | 10 | ||||
| -rw-r--r-- | src/common/math_util.h | 8 | ||||
| -rw-r--r-- | src/common/vector_math.h | 75 | ||||
| -rw-r--r-- | src/common/wall_clock.cpp | 2 | ||||
| -rw-r--r-- | src/common/wall_clock.h | 2 | ||||
| -rw-r--r-- | src/common/x64/native_clock.h | 2 |
7 files changed, 85 insertions, 21 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5d54516eb..0fb5d9708 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -192,4 +192,9 @@ create_target_directory_groups(common) | |||
| 192 | find_package(Boost 1.71 COMPONENTS context headers REQUIRED) | 192 | find_package(Boost 1.71 COMPONENTS context headers REQUIRED) |
| 193 | 193 | ||
| 194 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) | 194 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) |
| 195 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd xbyak) | 195 | target_link_libraries(common PRIVATE lz4::lz4 xbyak) |
| 196 | if (MSVC) | ||
| 197 | target_link_libraries(common PRIVATE zstd::zstd) | ||
| 198 | else() | ||
| 199 | target_link_libraries(common PRIVATE zstd) | ||
| 200 | endif() | ||
diff --git a/src/common/hex_util.h b/src/common/hex_util.h index 120f1a5e6..a8d414fb8 100644 --- a/src/common/hex_util.h +++ b/src/common/hex_util.h | |||
| @@ -16,14 +16,14 @@ namespace Common { | |||
| 16 | 16 | ||
| 17 | [[nodiscard]] constexpr u8 ToHexNibble(char c) { | 17 | [[nodiscard]] constexpr u8 ToHexNibble(char c) { |
| 18 | if (c >= 65 && c <= 70) { | 18 | if (c >= 65 && c <= 70) { |
| 19 | return c - 55; | 19 | return static_cast<u8>(c - 55); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | if (c >= 97 && c <= 102) { | 22 | if (c >= 97 && c <= 102) { |
| 23 | return c - 87; | 23 | return static_cast<u8>(c - 87); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | return c - 48; | 26 | return static_cast<u8>(c - 48); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | [[nodiscard]] std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); | 29 | [[nodiscard]] std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); |
| @@ -33,11 +33,11 @@ template <std::size_t Size, bool le = false> | |||
| 33 | std::array<u8, Size> out{}; | 33 | std::array<u8, Size> out{}; |
| 34 | if constexpr (le) { | 34 | if constexpr (le) { |
| 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { | 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { |
| 36 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 36 | out[i / 2] = static_cast<u8>((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); |
| 37 | } | 37 | } |
| 38 | } else { | 38 | } else { |
| 39 | for (std::size_t i = 0; i < 2 * Size; i += 2) { | 39 | for (std::size_t i = 0; i < 2 * Size; i += 2) { |
| 40 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 40 | out[i / 2] = static_cast<u8>((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | return out; | 43 | return out; |
diff --git a/src/common/math_util.h b/src/common/math_util.h index b35ad8507..4c38d8040 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -20,14 +20,14 @@ struct Rectangle { | |||
| 20 | 20 | ||
| 21 | constexpr Rectangle() = default; | 21 | constexpr Rectangle() = default; |
| 22 | 22 | ||
| 23 | constexpr Rectangle(T left, T top, T right, T bottom) | 23 | constexpr Rectangle(T left_, T top_, T right_, T bottom_) |
| 24 | : left(left), top(top), right(right), bottom(bottom) {} | 24 | : left(left_), top(top_), right(right_), bottom(bottom_) {} |
| 25 | 25 | ||
| 26 | [[nodiscard]] T GetWidth() const { | 26 | [[nodiscard]] T GetWidth() const { |
| 27 | if constexpr (std::is_floating_point_v<T>) { | 27 | if constexpr (std::is_floating_point_v<T>) { |
| 28 | return std::abs(right - left); | 28 | return std::abs(right - left); |
| 29 | } else { | 29 | } else { |
| 30 | return std::abs(static_cast<std::make_signed_t<T>>(right - left)); | 30 | return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(right - left))); |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| @@ -35,7 +35,7 @@ struct Rectangle { | |||
| 35 | if constexpr (std::is_floating_point_v<T>) { | 35 | if constexpr (std::is_floating_point_v<T>) { |
| 36 | return std::abs(bottom - top); | 36 | return std::abs(bottom - top); |
| 37 | } else { | 37 | } else { |
| 38 | return std::abs(static_cast<std::make_signed_t<T>>(bottom - top)); | 38 | return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(bottom - top))); |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | 41 | ||
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 2a0fcf541..22dba3c2d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -87,7 +87,13 @@ public: | |||
| 87 | 87 | ||
| 88 | template <typename V> | 88 | template <typename V> |
| 89 | [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { | 89 | [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { |
| 90 | return {x * f, y * f}; | 90 | using TV = decltype(T{} * V{}); |
| 91 | using C = std::common_type_t<T, V>; | ||
| 92 | |||
| 93 | return { | ||
| 94 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 95 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 96 | }; | ||
| 91 | } | 97 | } |
| 92 | 98 | ||
| 93 | template <typename V> | 99 | template <typename V> |
| @@ -98,7 +104,13 @@ public: | |||
| 98 | 104 | ||
| 99 | template <typename V> | 105 | template <typename V> |
| 100 | [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { | 106 | [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { |
| 101 | return {x / f, y / f}; | 107 | using TV = decltype(T{} / V{}); |
| 108 | using C = std::common_type_t<T, V>; | ||
| 109 | |||
| 110 | return { | ||
| 111 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 112 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 113 | }; | ||
| 102 | } | 114 | } |
| 103 | 115 | ||
| 104 | template <typename V> | 116 | template <typename V> |
| @@ -168,7 +180,10 @@ public: | |||
| 168 | 180 | ||
| 169 | template <typename T, typename V> | 181 | template <typename T, typename V> |
| 170 | [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { | 182 | [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { |
| 171 | return Vec2<T>(f * vec.x, f * vec.y); | 183 | using C = std::common_type_t<T, V>; |
| 184 | |||
| 185 | return Vec2<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 186 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y))); | ||
| 172 | } | 187 | } |
| 173 | 188 | ||
| 174 | using Vec2f = Vec2<float>; | 189 | using Vec2f = Vec2<float>; |
| @@ -237,7 +252,14 @@ public: | |||
| 237 | 252 | ||
| 238 | template <typename V> | 253 | template <typename V> |
| 239 | [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { | 254 | [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { |
| 240 | return {x * f, y * f, z * f}; | 255 | using TV = decltype(T{} * V{}); |
| 256 | using C = std::common_type_t<T, V>; | ||
| 257 | |||
| 258 | return { | ||
| 259 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 260 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 261 | static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), | ||
| 262 | }; | ||
| 241 | } | 263 | } |
| 242 | 264 | ||
| 243 | template <typename V> | 265 | template <typename V> |
| @@ -247,7 +269,14 @@ public: | |||
| 247 | } | 269 | } |
| 248 | template <typename V> | 270 | template <typename V> |
| 249 | [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { | 271 | [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { |
| 250 | return {x / f, y / f, z / f}; | 272 | using TV = decltype(T{} / V{}); |
| 273 | using C = std::common_type_t<T, V>; | ||
| 274 | |||
| 275 | return { | ||
| 276 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 277 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 278 | static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), | ||
| 279 | }; | ||
| 251 | } | 280 | } |
| 252 | 281 | ||
| 253 | template <typename V> | 282 | template <typename V> |
| @@ -367,7 +396,11 @@ public: | |||
| 367 | 396 | ||
| 368 | template <typename T, typename V> | 397 | template <typename T, typename V> |
| 369 | [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { | 398 | [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { |
| 370 | return Vec3<T>(f * vec.x, f * vec.y, f * vec.z); | 399 | using C = std::common_type_t<T, V>; |
| 400 | |||
| 401 | return Vec3<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 402 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)), | ||
| 403 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.z))); | ||
| 371 | } | 404 | } |
| 372 | 405 | ||
| 373 | template <> | 406 | template <> |
| @@ -446,7 +479,15 @@ public: | |||
| 446 | 479 | ||
| 447 | template <typename V> | 480 | template <typename V> |
| 448 | [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { | 481 | [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { |
| 449 | return {x * f, y * f, z * f, w * f}; | 482 | using TV = decltype(T{} * V{}); |
| 483 | using C = std::common_type_t<T, V>; | ||
| 484 | |||
| 485 | return { | ||
| 486 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 487 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 488 | static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), | ||
| 489 | static_cast<TV>(static_cast<C>(w) * static_cast<C>(f)), | ||
| 490 | }; | ||
| 450 | } | 491 | } |
| 451 | 492 | ||
| 452 | template <typename V> | 493 | template <typename V> |
| @@ -457,7 +498,15 @@ public: | |||
| 457 | 498 | ||
| 458 | template <typename V> | 499 | template <typename V> |
| 459 | [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { | 500 | [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { |
| 460 | return {x / f, y / f, z / f, w / f}; | 501 | using TV = decltype(T{} / V{}); |
| 502 | using C = std::common_type_t<T, V>; | ||
| 503 | |||
| 504 | return { | ||
| 505 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 506 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 507 | static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), | ||
| 508 | static_cast<TV>(static_cast<C>(w) / static_cast<C>(f)), | ||
| 509 | }; | ||
| 461 | } | 510 | } |
| 462 | 511 | ||
| 463 | template <typename V> | 512 | template <typename V> |
| @@ -582,7 +631,15 @@ public: | |||
| 582 | 631 | ||
| 583 | template <typename T, typename V> | 632 | template <typename T, typename V> |
| 584 | [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { | 633 | [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { |
| 585 | return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; | 634 | using TV = decltype(V{} * T{}); |
| 635 | using C = std::common_type_t<T, V>; | ||
| 636 | |||
| 637 | return { | ||
| 638 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 639 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.y)), | ||
| 640 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.z)), | ||
| 641 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.w)), | ||
| 642 | }; | ||
| 586 | } | 643 | } |
| 587 | 644 | ||
| 588 | using Vec4f = Vec4<float>; | 645 | using Vec4f = Vec4<float>; |
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp index 3afbdb898..7a20e95b7 100644 --- a/src/common/wall_clock.cpp +++ b/src/common/wall_clock.cpp | |||
| @@ -15,7 +15,7 @@ namespace Common { | |||
| 15 | using base_timer = std::chrono::steady_clock; | 15 | using base_timer = std::chrono::steady_clock; |
| 16 | using base_time_point = std::chrono::time_point<base_timer>; | 16 | using base_time_point = std::chrono::time_point<base_timer>; |
| 17 | 17 | ||
| 18 | class StandardWallClock : public WallClock { | 18 | class StandardWallClock final : public WallClock { |
| 19 | public: | 19 | public: |
| 20 | StandardWallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency) | 20 | StandardWallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency) |
| 21 | : WallClock(emulated_cpu_frequency, emulated_clock_frequency, false) { | 21 | : WallClock(emulated_cpu_frequency, emulated_clock_frequency, false) { |
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h index 5db30083d..bc7adfbf8 100644 --- a/src/common/wall_clock.h +++ b/src/common/wall_clock.h | |||
| @@ -13,6 +13,8 @@ namespace Common { | |||
| 13 | 13 | ||
| 14 | class WallClock { | 14 | class WallClock { |
| 15 | public: | 15 | public: |
| 16 | virtual ~WallClock() = default; | ||
| 17 | |||
| 16 | /// Returns current wall time in nanoseconds | 18 | /// Returns current wall time in nanoseconds |
| 17 | [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0; | 19 | [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0; |
| 18 | 20 | ||
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h index 891a3bbfd..7c503df26 100644 --- a/src/common/x64/native_clock.h +++ b/src/common/x64/native_clock.h | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | namespace Common { | 12 | namespace Common { |
| 13 | 13 | ||
| 14 | namespace X64 { | 14 | namespace X64 { |
| 15 | class NativeClock : public WallClock { | 15 | class NativeClock final : public WallClock { |
| 16 | public: | 16 | public: |
| 17 | NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, u64 rtsc_frequency); | 17 | NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, u64 rtsc_frequency); |
| 18 | 18 | ||