gcc/clang attribute pure usage in few places.

This commit is contained in:
David Carlier 2022-08-14 08:22:27 +01:00
parent 2fca03cf7f
commit 1b8a72deae
3 changed files with 8 additions and 5 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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);
}