Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
inlines.h
Go to the documentation of this file.
1#ifndef NW4HBM_UT_INLINE_FUNCTIONS_H
2#define NW4HBM_UT_INLINE_FUNCTIONS_H
3
4#include <revolution/types.h>
5
6namespace nw4hbm {
7 namespace ut {
8
9 class NonCopyable {
10 protected:
13
14 private:
17 };
18
19 template <typename T>
20 inline T Min(T a, T b) {
21 return (a > b) ? b : a;
22 }
23 template <typename T>
24 inline T Max(T a, T b) {
25 return (a < b) ? b : a;
26 }
27 template <typename T>
28 inline T Clamp(T x, T low, T high) {
29 return (x > high) ? high : ((x < low) ? low : x);
30 }
31
32 template <typename T>
33 inline T Abs(T x) {
34 // Static cast needed to break abs optimization
35 return x < 0 ? static_cast<T>(-x) : static_cast<T>(x);
36 }
37
38 template <typename T>
39 inline T BitExtract(T bits, int pos, int len) {
40 T mask = (1 << len) - 1;
41 return (bits >> pos) & mask;
42 }
43
44 inline u32 GetIntPtr(const void* pPtr) {
45 return reinterpret_cast<u32>(pPtr);
46 }
47
48 template <typename T>
49 inline const void* AddOffsetToPtr(const void* base, T offset) {
50 return reinterpret_cast<const void*>(GetIntPtr(base) + offset);
51 }
52 template <typename T>
53 inline void* AddOffsetToPtr(void* base, T offset) {
54 return reinterpret_cast<void*>(GetIntPtr(base) + offset);
55 }
56
57 inline s32 GetOffsetFromPtr(const void* start, const void* end) {
58 return static_cast<s32>(GetIntPtr(end) - GetIntPtr(start));
59 }
60
61 inline int ComparePtr(const void* pPtr1, const void* pPtr2) {
62 return static_cast<int>(GetIntPtr(pPtr1) - GetIntPtr(pPtr2));
63 }
64
65 template <typename T>
66 inline T RoundUp(T t, u32 alignment) {
67 return (alignment + t - 1) & ~(alignment - 1);
68 }
69
70 template <typename T>
71 inline void* RoundUp(T* pPtr, u32 alignment) {
72 u32 value = reinterpret_cast<u32>(pPtr);
73 u32 rounded = (alignment + value - 1) & ~(alignment - 1);
74 return reinterpret_cast<void*>(rounded);
75 }
76
77 template <typename T>
78 inline T RoundDown(T t, u32 alignment) {
79 return t & ~(alignment - 1);
80 }
81
82 template <typename T>
83 inline void* RoundDown(T* pPtr, u32 alignment) {
84 u32 value = reinterpret_cast<u32>(pPtr);
85 u32 rounded = value & ~(alignment - 1);
86 return reinterpret_cast<void*>(rounded);
87 }
88
89 } // namespace ut
90} // namespace nw4hbm
91
92#endif
static u8 base[0x2A]
Definition WPADEncrypt.c:10
static s32 offset
Definition WUD.c:1669
Definition inlines.h:9
NonCopyable()
Definition inlines.h:11
~NonCopyable()
Definition inlines.h:12
NonCopyable(const NonCopyable &)
const NonCopyable & operator=(const NonCopyable &)
static void end(b_oh_class *i_this)
Definition d_a_b_oh.cpp:343
t
Definition e_asin.c:100
double x double x
Definition e_atan2.c:58
unsigned long u32
Definition types.h:12
signed long s32
Definition types.h:11
a
Definition k_cos.c:89
int ComparePtr(const void *pPtr1, const void *pPtr2)
Definition inlines.h:61
T Abs(T x)
Definition inlines.h:33
T RoundUp(T t, u32 alignment)
Definition inlines.h:66
s32 GetOffsetFromPtr(const void *start, const void *end)
Definition inlines.h:57
const void * AddOffsetToPtr(const void *base, T offset)
Definition inlines.h:49
u32 GetIntPtr(const void *pPtr)
Definition inlines.h:44
T Min(T a, T b)
Definition inlines.h:20
T Clamp(T x, T low, T high)
Definition inlines.h:28
T BitExtract(T bits, int pos, int len)
Definition inlines.h:39
T RoundDown(T t, u32 alignment)
Definition inlines.h:78
T Max(T a, T b)
Definition inlines.h:24
Definition HBMAnmController.h:6
@ start
Definition strtold.c:23