Skip to content

Commit

Permalink
Merge pull request #1039 from devnexen/purify_this
Browse files Browse the repository at this point in the history
Apply GCC/Clang pure attribute on a few functions
  • Loading branch information
yvt authored Aug 17, 2022
2 parents 2620393 + 1b8a72d commit e3aa033
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Sources/Core/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,18 @@ namespace spades {

#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__((deprecated))
#define PURE __attribute__((pure))
#define LIKELY(cond) __builtin_expect(!!(cond), true)
#define UNLIKELY(cond) __builtin_expect(!!(cond), false)
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#define LIKELY(cond) (cond)
#define UNLIKELY(cond) (cond)
#define PURE
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#define PURE
#pragma message("WARNING: You need to implement LIKELY/UNLIKELY for this compiler")
#define LIKELY(cond) (cond)
#define UNLIKELY(cond) (cond)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Draw/SWFeatureLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ namespace spades {
return tmp;
}
#else
static inline float fastDiv(float a, float b) { return a / b; }
static inline float fastRcp(float b) { return 1.f / b; }
static inline float fastRSqrt(float b) { return 1.f / sqrtf(b); }
static inline PURE float fastDiv(float a, float b) { return a / b; }
static inline PURE float fastRcp(float b) { return 1.f / b; }
static inline PURE float fastRSqrt(float b) { return 1.f / sqrtf(b); }
#endif
static inline float fastSqrt(float s) {
if (s == 0.f)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Draw/SWUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ namespace spades {
}
}

static inline int ToFixed8(float v) {
static inline PURE int ToFixed8(float v) {
int i = static_cast<int>(v * 255.f + .5f);
return std::max(std::min(i, 255), 0);
}

static inline int ToFixedFactor8(float v) {
static inline PURE int ToFixedFactor8(float v) {
int i = static_cast<int>(v * 256.f + .5f);
return std::max(std::min(i, 256), 0);
}
Expand Down

0 comments on commit e3aa033

Please sign in to comment.