Merge pull request #9087 from Morph1984/once

general: Add missing pragma once
This commit is contained in:
bunnei 2022-10-17 22:50:02 -07:00 committed by GitHub
commit 1deb997eba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 54 deletions

View file

@ -4,14 +4,7 @@
// From: https://github.com/eteran/cpp-utilities/blob/master/fixed/include/cpp-utilities/fixed.h // From: https://github.com/eteran/cpp-utilities/blob/master/fixed/include/cpp-utilities/fixed.h
// See also: http://stackoverflow.com/questions/79677/whats-the-best-way-to-do-fixed-point-math // See also: http://stackoverflow.com/questions/79677/whats-the-best-way-to-do-fixed-point-math
#ifndef FIXED_H_ #pragma once
#define FIXED_H_
#if __cplusplus >= 201402L
#define CONSTEXPR14 constexpr
#else
#define CONSTEXPR14
#endif
#include <cstddef> // for size_t #include <cstddef> // for size_t
#include <cstdint> #include <cstdint>
@ -106,7 +99,7 @@ constexpr B next_to_base(N rhs) {
struct divide_by_zero : std::exception {}; struct divide_by_zero : std::exception {};
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> divide( constexpr FixedPoint<I, F> divide(
FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder, FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder,
typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -126,7 +119,7 @@ CONSTEXPR14 FixedPoint<I, F> divide(
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> divide( constexpr FixedPoint<I, F> divide(
FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder, FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder,
typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -196,7 +189,7 @@ CONSTEXPR14 FixedPoint<I, F> divide(
// this is the usual implementation of multiplication // this is the usual implementation of multiplication
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> multiply( constexpr FixedPoint<I, F> multiply(
FixedPoint<I, F> lhs, FixedPoint<I, F> rhs, FixedPoint<I, F> lhs, FixedPoint<I, F> rhs,
typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -215,7 +208,7 @@ CONSTEXPR14 FixedPoint<I, F> multiply(
// it is slightly slower, but is more robust since it doesn't // it is slightly slower, but is more robust since it doesn't
// require and upgraded type // require and upgraded type
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> multiply( constexpr FixedPoint<I, F> multiply(
FixedPoint<I, F> lhs, FixedPoint<I, F> rhs, FixedPoint<I, F> lhs, FixedPoint<I, F> rhs,
typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -284,7 +277,7 @@ public: // constructors
public: // conversion public: // conversion
template <size_t I2, size_t F2> template <size_t I2, size_t F2>
CONSTEXPR14 explicit FixedPoint(FixedPoint<I2, F2> other) { constexpr explicit FixedPoint(FixedPoint<I2, F2> other) {
static_assert(I2 <= I && F2 <= F, "Scaling conversion can only upgrade types"); static_assert(I2 <= I && F2 <= F, "Scaling conversion can only upgrade types");
using T = FixedPoint<I2, F2>; using T = FixedPoint<I2, F2>;
@ -353,81 +346,81 @@ public: // unary operators
return FixedPoint::from_base(+data_); return FixedPoint::from_base(+data_);
} }
CONSTEXPR14 FixedPoint& operator++() { constexpr FixedPoint& operator++() {
data_ += one; data_ += one;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator--() { constexpr FixedPoint& operator--() {
data_ -= one; data_ -= one;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint operator++(int) { constexpr FixedPoint operator++(int) {
FixedPoint tmp(*this); FixedPoint tmp(*this);
data_ += one; data_ += one;
return tmp; return tmp;
} }
CONSTEXPR14 FixedPoint operator--(int) { constexpr FixedPoint operator--(int) {
FixedPoint tmp(*this); FixedPoint tmp(*this);
data_ -= one; data_ -= one;
return tmp; return tmp;
} }
public: // basic math operators public: // basic math operators
CONSTEXPR14 FixedPoint& operator+=(FixedPoint n) { constexpr FixedPoint& operator+=(FixedPoint n) {
data_ += n.data_; data_ += n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator-=(FixedPoint n) { constexpr FixedPoint& operator-=(FixedPoint n) {
data_ -= n.data_; data_ -= n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator*=(FixedPoint n) { constexpr FixedPoint& operator*=(FixedPoint n) {
return assign(detail::multiply(*this, n)); return assign(detail::multiply(*this, n));
} }
CONSTEXPR14 FixedPoint& operator/=(FixedPoint n) { constexpr FixedPoint& operator/=(FixedPoint n) {
FixedPoint temp; FixedPoint temp;
return assign(detail::divide(*this, n, temp)); return assign(detail::divide(*this, n, temp));
} }
private: private:
CONSTEXPR14 FixedPoint& assign(FixedPoint rhs) { constexpr FixedPoint& assign(FixedPoint rhs) {
data_ = rhs.data_; data_ = rhs.data_;
return *this; return *this;
} }
public: // binary math operators, effects underlying bit pattern since these public: // binary math operators, effects underlying bit pattern since these
// don't really typically make sense for non-integer values // don't really typically make sense for non-integer values
CONSTEXPR14 FixedPoint& operator&=(FixedPoint n) { constexpr FixedPoint& operator&=(FixedPoint n) {
data_ &= n.data_; data_ &= n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator|=(FixedPoint n) { constexpr FixedPoint& operator|=(FixedPoint n) {
data_ |= n.data_; data_ |= n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator^=(FixedPoint n) { constexpr FixedPoint& operator^=(FixedPoint n) {
data_ ^= n.data_; data_ ^= n.data_;
return *this; return *this;
} }
template <class Integer, template <class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint& operator>>=(Integer n) { constexpr FixedPoint& operator>>=(Integer n) {
data_ >>= n; data_ >>= n;
return *this; return *this;
} }
template <class Integer, template <class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint& operator<<=(Integer n) { constexpr FixedPoint& operator<<=(Integer n) {
data_ <<= n; data_ <<= n;
return *this; return *this;
} }
@ -485,7 +478,7 @@ public: // conversion to basic types
} }
public: public:
CONSTEXPR14 void swap(FixedPoint& rhs) { constexpr void swap(FixedPoint& rhs) {
using std::swap; using std::swap;
swap(data_, rhs.data_); swap(data_, rhs.data_);
} }
@ -497,8 +490,8 @@ public:
// if we have the same fractional portion, but differing integer portions, we trivially upgrade the // if we have the same fractional portion, but differing integer portions, we trivially upgrade the
// smaller type // smaller type
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator+(
operator+(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -508,8 +501,8 @@ operator+(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
} }
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator-(
operator-(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -519,8 +512,8 @@ operator-(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
} }
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator*(
operator*(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -530,8 +523,8 @@ operator*(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
} }
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator/(
operator/(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -548,75 +541,75 @@ std::ostream& operator<<(std::ostream& os, FixedPoint<I, F> f) {
// basic math operators // basic math operators
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs += rhs; lhs += rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs -= rhs; lhs -= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs *= rhs; lhs *= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs /= rhs; lhs /= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, Number rhs) {
lhs += FixedPoint<I, F>(rhs); lhs += FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, Number rhs) {
lhs -= FixedPoint<I, F>(rhs); lhs -= FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, Number rhs) {
lhs *= FixedPoint<I, F>(rhs); lhs *= FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, Number rhs) {
lhs /= FixedPoint<I, F>(rhs); lhs /= FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator+(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator+(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp += rhs; tmp += rhs;
return tmp; return tmp;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator-(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator-(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp -= rhs; tmp -= rhs;
return tmp; return tmp;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator*(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator*(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp *= rhs; tmp *= rhs;
return tmp; return tmp;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator/(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator/(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp /= rhs; tmp /= rhs;
return tmp; return tmp;
@ -625,13 +618,13 @@ CONSTEXPR14 FixedPoint<I, F> operator/(Number lhs, FixedPoint<I, F> rhs) {
// shift operators // shift operators
template <size_t I, size_t F, class Integer, template <size_t I, size_t F, class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator<<(FixedPoint<I, F> lhs, Integer rhs) { constexpr FixedPoint<I, F> operator<<(FixedPoint<I, F> lhs, Integer rhs) {
lhs <<= rhs; lhs <<= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F, class Integer, template <size_t I, size_t F, class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator>>(FixedPoint<I, F> lhs, Integer rhs) { constexpr FixedPoint<I, F> operator>>(FixedPoint<I, F> lhs, Integer rhs) {
lhs >>= rhs; lhs >>= rhs;
return lhs; return lhs;
} }
@ -700,7 +693,3 @@ constexpr bool operator!=(Number lhs, FixedPoint<I, F> rhs) {
} }
} // namespace Common } // namespace Common
#undef CONSTEXPR14
#endif

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "core/hle/result.h" #include "core/hle/result.h"
namespace Service::VI { namespace Service::VI {