Replace TARGET_ARM_MODE pragma with ARM_MODE function attributes

This commit is contained in:
Madeline Busig 2024-08-03 17:28:27 -06:00
parent eb4412847e
commit 589676854c
2 changed files with 16 additions and 9 deletions

View File

@ -5,8 +5,6 @@
#include "mtl/target.hpp" #include "mtl/target.hpp"
TARGET_ARM_MODE
namespace mtl { namespace mtl {
/** /**
* \brief 32-bit Fixed point number * \brief 32-bit Fixed point number
@ -44,9 +42,11 @@ private:
* DO NOT use to set the fixed number to an integer value, use * DO NOT use to set the fixed number to an integer value, use
* the public constructor instead. * the public constructor instead.
*/ */
ARM_MODE
constexpr fixed(int32_t _x, bool) noexcept : x(_x) {} constexpr fixed(int32_t _x, bool) noexcept : x(_x) {}
public: public:
ARM_MODE
constexpr fixed() noexcept : x(0) {} constexpr fixed() noexcept : x(0) {}
/** /**
* \brief Integer constructor * \brief Integer constructor
@ -56,6 +56,7 @@ public:
* the class description for more detail. * the class description for more detail.
*/ */
template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true> template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
ARM_MODE
constexpr fixed(T _i) noexcept : x(_i * 64) {} constexpr fixed(T _i) noexcept : x(_i * 64) {}
/** /**
* \brief Floating point constructor * \brief Floating point constructor
@ -69,6 +70,7 @@ public:
* float. * float.
*/ */
template <typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true> template <typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
ARM_MODE
constexpr fixed(T _f) noexcept constexpr fixed(T _f) noexcept
// 0.5 offset accounts for truncating to integer, round instead // 0.5 offset accounts for truncating to integer, round instead
: x((_f * 64) + 0.5f) {} : x((_f * 64) + 0.5f) {}
@ -82,6 +84,7 @@ public:
* *
* Should not be used unless absolutely needed. * Should not be used unless absolutely needed.
*/ */
ARM_MODE
static constexpr fixed from_raw(int32_t x) noexcept { static constexpr fixed from_raw(int32_t x) noexcept {
return fixed(x, true); return fixed(x, true);
} }
@ -92,6 +95,7 @@ public:
* Gets the raw value of the fixed point number. i.e. The fixed point * Gets the raw value of the fixed point number. i.e. The fixed point
* number multiplied by 64. * number multiplied by 64.
*/ */
ARM_MODE
constexpr int32_t raw() const noexcept { constexpr int32_t raw() const noexcept {
return x; return x;
} }
@ -102,9 +106,11 @@ public:
* Addition with fixed point numbers is the same as with a 32-bit * Addition with fixed point numbers is the same as with a 32-bit
* integer, so should be extremely quick. * integer, so should be extremely quick.
*/ */
ARM_MODE
constexpr fixed operator+(fixed rhs) const noexcept { constexpr fixed operator+(fixed rhs) const noexcept {
return from_raw(x + rhs.x); return from_raw(x + rhs.x);
} }
ARM_MODE
constexpr fixed& operator+=(fixed rhs) noexcept { constexpr fixed& operator+=(fixed rhs) noexcept {
x += rhs.x; x += rhs.x;
return *this; return *this;
@ -112,13 +118,16 @@ public:
/** /**
* \brief Fixed point subtraction * \brief Fixed point subtraction
*/ */
ARM_MODE
constexpr fixed operator-(fixed rhs) const noexcept { constexpr fixed operator-(fixed rhs) const noexcept {
return from_raw(x - rhs.x); return from_raw(x - rhs.x);
} }
ARM_MODE
constexpr fixed& operator-=(fixed rhs) noexcept { constexpr fixed& operator-=(fixed rhs) noexcept {
x -= rhs.x; x -= rhs.x;
return *this; return *this;
} }
ARM_MODE
constexpr fixed operator-() const noexcept { constexpr fixed operator-() const noexcept {
return from_raw(-x); return from_raw(-x);
} }
@ -126,9 +135,11 @@ public:
/** /**
* \brief Fixed point multiplication * \brief Fixed point multiplication
*/ */
ARM_MODE
constexpr fixed operator*(fixed rhs) const noexcept { constexpr fixed operator*(fixed rhs) const noexcept {
return from_raw(((int64_t)x * rhs.x) >> 6); return from_raw(((int64_t)x * rhs.x) >> 6);
} }
ARM_MODE
constexpr fixed& operator*=(fixed rhs) noexcept { constexpr fixed& operator*=(fixed rhs) noexcept {
*this = *this * rhs; *this = *this * rhs;
return *this; return *this;
@ -149,7 +160,9 @@ public:
* *
* Placed in IWRAM * 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 { fixed& operator/=(fixed rhs) noexcept {
*this = *this / rhs; *this = *this / rhs;
return *this; return *this;
@ -158,5 +171,3 @@ public:
} // namespace mtl } // namespace mtl
TARGET_END_MODE

View File

@ -2,8 +2,6 @@
#include "mtl/fixed.hpp" #include "mtl/fixed.hpp"
TARGET_ARM_MODE
namespace mtl { namespace mtl {
fixed fixed::operator/(fixed rhs) const noexcept { fixed fixed::operator/(fixed rhs) const noexcept {
@ -56,5 +54,3 @@ fixed fixed::operator/(fixed rhs) const noexcept {
} // namespace mtl } // namespace mtl
TARGET_END_MODE