sead
Loading...
Searching...
No Matches
seadMathCalcCommonCafe.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifndef DISABLE_PS
4#include <ppc_ghs.h>
5#endif
6
7#include <basis/seadAssert.h>
8
9namespace sead {
10
11template <>
13{
14 SEAD_ASSERT_MSG(x >= 0.0f, "x[%f] is out of the domain.", x);
15
16 if (x <= 0.0f)
17 return 0.0f;
18
19 f32 v0;
20 f32 v1;
21 f32 v2;
22 const f32 HALF = 0.5f;
23 const f32 THREE = 3.0f;
24
25#ifdef SEAD_MATH_CAFE_RSQRT_USE_INTRINSICS
26 // The use of inline assembly in an inline function can be very dangerous,
27 // and sometimes triggers compiler bugs in GHS.
28 // Therefore, use intrinsics instead.
29 // (For use with custom applications)
30 v0 = __FRSQRTE(x);
31 v1 = v0 * v0;
32 v2 = v0 * HALF;
33 v1 = __FNMSUBS(v1, x, THREE);
34 v0 = v1 * v2;
35#else
36 asm ("frsqrte %[v0], %[x] \n\t"
37 "fmuls %[v1], %[v0], %[v0] \n\t"
38 "fmuls %[v2], %[v0], %[HALF] \n\t"
39 "fnmsubs %[v1], %[v1], %[x], %[THREE]\n\t"
40 "fmuls %[v0], %[v1], %[v2] "
41 : [v0] "=&f"(v0), [v1] "=&f"(v1), [ v2] "=&f"( v2)
42 : [x] "f"( x), [HALF] "f"(HALF), [THREE] "f"(THREE));
43#endif
44
45 return v0;
46}
47
48} // namespace sead
Definition seadAssert.h:44
#define SEAD_ASSERT_MSG(condition, format,...)
Definition seadAssert.h:33