From d268779acec03a95be8bf4f97b44a2f1a3c3bdcb Mon Sep 17 00:00:00 2001 From: Myles Busig Date: Sat, 3 Aug 2024 17:28:27 -0600 Subject: [PATCH] Replace TARGET_ARM_MODE pragma with ARM_MODE function attributes --- include/mtl/fixed.hpp | 21 ++++++++++++++++----- src/gba/fixed.cpp | 4 ---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/mtl/fixed.hpp b/include/mtl/fixed.hpp index 8114ebb..432995c 100644 --- a/include/mtl/fixed.hpp +++ b/include/mtl/fixed.hpp @@ -5,8 +5,6 @@ #include "mtl/target.hpp" -TARGET_ARM_MODE - namespace mtl { /** * \brief 32-bit Fixed point number @@ -44,9 +42,11 @@ private: * DO NOT use to set the fixed number to an integer value, use * the public constructor instead. */ + ARM_MODE constexpr fixed(int32_t _x, bool) noexcept : x(_x) {} public: + ARM_MODE constexpr fixed() noexcept : x(0) {} /** * \brief Integer constructor @@ -56,6 +56,7 @@ public: * the class description for more detail. */ template , bool> = true> + ARM_MODE constexpr fixed(T _i) noexcept : x(_i * 64) {} /** * \brief Floating point constructor @@ -69,6 +70,7 @@ public: * float. */ template , bool> = true> + ARM_MODE constexpr fixed(T _f) noexcept // 0.5 offset accounts for truncating to integer, round instead : x((_f * 64) + 0.5f) {} @@ -82,6 +84,7 @@ public: * * Should not be used unless absolutely needed. */ + ARM_MODE static constexpr fixed from_raw(int32_t x) noexcept { return fixed(x, true); } @@ -92,6 +95,7 @@ public: * Gets the raw value of the fixed point number. i.e. The fixed point * number multiplied by 64. */ + ARM_MODE constexpr int32_t raw() const noexcept { return x; } @@ -102,9 +106,11 @@ public: * Addition with fixed point numbers is the same as with a 32-bit * integer, so should be extremely quick. */ + ARM_MODE constexpr fixed operator+(fixed rhs) const noexcept { return from_raw(x + rhs.x); } + ARM_MODE constexpr fixed& operator+=(fixed rhs) noexcept { x += rhs.x; return *this; @@ -112,13 +118,16 @@ public: /** * \brief Fixed point subtraction */ + ARM_MODE constexpr fixed operator-(fixed rhs) const noexcept { return from_raw(x - rhs.x); } + ARM_MODE constexpr fixed& operator-=(fixed rhs) noexcept { x -= rhs.x; return *this; } + ARM_MODE constexpr fixed operator-() const noexcept { return from_raw(-x); } @@ -126,9 +135,11 @@ public: /** * \brief Fixed point multiplication */ + ARM_MODE constexpr fixed operator*(fixed rhs) const noexcept { return from_raw(((int64_t)x * rhs.x) >> 6); } + ARM_MODE constexpr fixed& operator*=(fixed rhs) noexcept { *this = *this * rhs; return *this; @@ -149,7 +160,9 @@ public: * * Placed in IWRAM */ - GBA_IWRAM fixed operator/(fixed rhs) const noexcept; + ARM_MODE GBA_IWRAM + fixed operator/(fixed rhs) const noexcept; + ARM_MODE fixed& operator/=(fixed rhs) noexcept { *this = *this / rhs; return *this; @@ -158,5 +171,3 @@ public: } // namespace mtl -TARGET_END_MODE - diff --git a/src/gba/fixed.cpp b/src/gba/fixed.cpp index baf4ca4..a18d43b 100644 --- a/src/gba/fixed.cpp +++ b/src/gba/fixed.cpp @@ -2,8 +2,6 @@ #include "mtl/fixed.hpp" -TARGET_ARM_MODE - namespace mtl { fixed fixed::operator/(fixed rhs) const noexcept { @@ -56,5 +54,3 @@ fixed fixed::operator/(fixed rhs) const noexcept { } // namespace mtl -TARGET_END_MODE -