Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
arithmetic.h
Go to the documentation of this file.
1#ifndef NW4HBM_MATH_ARITHMETIC_H
2#define NW4HBM_MATH_ARITHMETIC_H
3
4#include <cmath>
5#include <cmath>
6
7#include <revolution/os.h>
8#include <revolution/types.h>
9
10
11namespace nw4hbm {
12 namespace math {
14
15 f32 Hermite(f32 p1, f32 t1, f32 p2, f32 t2, f32 s);
16 f32 Bezier(f32 p1, f32 p2, f32 p3, f32 p4, f32 s);
17 f32 CatmullRom(f32 p0, f32 p1, f32 p2, f32 p3, f32 s);
18
20 u32 CntBit1(u32 const* first, u32 const* last);
21 u32 DistBit(u32 const* first1, u32 const* last1, u32 const* first2);
23
24 int IExp(int x, u32 n);
26
27 inline u32 F32AsU32(f32 x) {
28 return *reinterpret_cast<u32*>(&x);
29 }
30
31 inline f32 U32AsF32(u32 x) {
32 return *reinterpret_cast<f32*>(&x);
33 }
34
35 inline s32 FGetExpPart(f32 f) {
36 s32 s = (F32AsU32(f) >> 23) & 0xff;
37
38 return s - 127;
39 }
40
42 u32 u = (F32AsU32(f) & 0x807fffff) | 0x3f800000;
43
44 return U32AsF32(u);
45 }
46
47 inline f32 FSelect(register f32 cond, register f32 ifPos, register f32 ifNeg) {
48 register f32 ret;
49
50#if defined(__MWERKS__)
51 asm { fsel ret, cond, ifPos, ifNeg }
52 ;
53#else
54#pragma unused(cond, ifPos, ifNeg)
55 ret = 0;
56#endif
57
58 return ret;
59 }
60
61 inline f32 FAbs(register f32 x) {
62 register f32 ret;
63
64#if defined(__MWERKS__)
65 asm { fabs ret, x }
66#else
67#pragma unused(x)
68 ret = 0;
69#endif
70
71 return ret;
72 }
73
74 inline f32 FNAbs(register f32 x) {
75 register f32 ret;
76
77#if defined(__MWERKS__)
78 asm { fnabs ret, x }
79#else
80#pragma unused(x)
81 ret = 0;
82#endif
83
84 return ret;
85 }
86
87 inline f32 AcosRad(f32 x) {
88 return std::acos(x);
89 }
90
92 f32 pos = FAbs(abs);
93 f32 neg = FNAbs(abs);
94
95 return FSelect(sign, pos, neg);
96 }
97
98 inline s16 F32ToS16(f32 x) {
99 s16 rval;
100
101 OSf32tos16(&x, &rval);
102
103 return rval;
104 }
105
106 inline u16 F32ToU16(f32 x) {
107 u16 rval;
108
109 OSf32tou16(&x, &rval);
110
111 return rval;
112 }
113
114 inline f32 U16ToF32(u16 x) {
115 f32 rval;
116
117 OSu16tof32(&x, &rval);
118
119 return rval;
120 }
121
122 inline f32 S16ToF32(s16 x) {
123 f32 rval;
124
125 OSs16tof32(&x, &rval);
126
127 return rval;
128 }
129
130 inline f32 FSqrt(f32 x) {
131 return x <= 0.0f ? 0.0f : x * FrSqrt(x);
132 }
133
134 inline f32 FCbrt(f32 x) {
135 return std::pow(x, 1.0f / 3.0f);
136 }
137
138 inline u32 CntLz(register u32 x) {
139 register u32 result;
140
141#if defined(__MWERKS__)
142 asm { cntlzw result, x }
143#else
144#pragma unused(x)
145 result = 0;
146#endif
147
148 return result;
149 }
150
151 inline u32 DistBit(u32 x, u32 y) {
152 return CntBit1(x ^ y);
153 }
154
155 namespace detail {
158
160 } // namespace detail
161 } // namespace math
162} // namespace nw4hbm
163
164#endif // NW4HBM_MATH_ARITHMETIC_H
int abs(int n)
Definition arith.c:3
static s16 neg[7]
Definition d_a_obj_gm.cpp:55
static u32 t1
Definition dsp_task.c:8
static u32 t2
Definition dsp_task.c:8
void OSf32tos16(f32 *f, s16 *out)
Definition os.h:307
float fabs(float x)
Definition sdk_math.h:35
s
Definition e_acos.c:99
double x double x
Definition e_atan2.c:58
double x double y
Definition e_atan2.c:58
n
Definition e_fmod.c:115
f
Definition e_log.c:119
double u
Definition e_pow.c:114
int sign
Definition e_sqrt.c:99
unsigned long u32
Definition types.h:12
signed short int s16
Definition types.h:9
float f32
Definition types.h:25
unsigned short int u16
Definition types.h:10
signed long s32
Definition types.h:11
f32 FrSqrt(f32 x)
f32 U32AsF32(u32 x)
Definition arithmetic.h:31
u32 ILog10(u32 x)
int IExp(int x, u32 n)
f32 FGetMantPart(f32 f)
Definition arithmetic.h:41
f32 FAbs(register f32 x)
Definition arithmetic.h:61
u32 CntLz(register u32 x)
Definition arithmetic.h:138
s32 FGetExpPart(f32 f)
Definition arithmetic.h:35
u16 F32ToU16(f32 x)
Definition arithmetic.h:106
f32 AcosRad(f32 x)
Definition arithmetic.h:87
f32 Hermite(f32 p1, f32 t1, f32 p2, f32 t2, f32 s)
f32 FNAbs(register f32 x)
Definition arithmetic.h:74
f32 U16ToF32(u16 x)
Definition arithmetic.h:114
f32 S16ToF32(s16 x)
Definition arithmetic.h:122
u32 RevBit(u32 x)
f32 Bezier(f32 p1, f32 p2, f32 p3, f32 p4, f32 s)
u32 CntBit1(u32 x)
u32 F32AsU32(f32 x)
Definition arithmetic.h:27
s16 F32ToS16(f32 x)
Definition arithmetic.h:98
u32 DistBit(u32 const *first1, u32 const *last1, u32 const *first2)
f32 CatmullRom(f32 p0, f32 p1, f32 p2, f32 p3, f32 s)
f32 FSelect(register f32 cond, register f32 ifPos, register f32 ifNeg)
Definition arithmetic.h:47
f32 FSqrt(f32 x)
Definition arithmetic.h:130
f32 FCopySign(f32 abs, f32 sign)
Definition arithmetic.h:91
f32 FCbrt(f32 x)
Definition arithmetic.h:134
Definition HBMAnmController.h:6
static void OSu16tof32(u16 const *in, f32 *out)
Definition os.h:415
static void OSs16tof32(s16 const *in, f32 *out)
Definition os.h:411
static void OSf32tou16(f32 const *in, u16 *out)
Definition os.h:403