1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     math_Arithmetic.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 17112 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_MATH_ARMV6_MATH_ARITHMETIC_H_
17 #define NN_MATH_ARMV6_MATH_ARITHMETIC_H_
18 
19 #include <nn/assert.h>
20 #include <nn/math/math_Config.h>
21 #include <nn/math/math_Constant.h>
22 
23 #include <cmath>
24 
25 namespace nn {
26 namespace math {
27 namespace ARMv6 {
28 
29 /* =======================================================================
30         Arithmetic functions related to floating-point numbers
31    ======================================================================== */
32 
33 /* Please see man pages for details
34 
35 
36 */
37 
38 //
39 f32 HermiteAsm(f32 v0, f32 t0, f32 v1, f32 t1, f32 s);
40 f32 HermiteAsm(f32 v0, f32 t0, f32 v1, f32 t1, f32 p, f32 d);
41 
42 /*
43 
44 
45 
46 
47 
48 
49 
50 
51 
52  */
53 inline f32
HermiteC(f32 v0,f32 t0,f32 v1,f32 t1,f32 s)54 HermiteC(f32 v0, f32 t0, f32 v1, f32 t1, f32 s)
55 {
56     f32 SS   = s * s;
57     f32 SS_S = s * s - s;
58     f32 b1 = SS_S * s - SS_S;
59     f32 b2 = SS_S * s;
60     f32 a2 = SS - 2.f * b2;
61 
62     return v0 - a2 * v0 + a2 * v1 + b1 * t0 + b2 * t1;
63 }
64 inline f32
HermiteC_FAST(f32 v0,f32 t0,f32 v1,f32 t1,f32 s)65 HermiteC_FAST(f32 v0, f32 t0, f32 v1, f32 t1, f32 s)
66 {
67     f32 SS;
68     f32 SS_S;
69     f32 b1;
70     f32 b2;
71     f32 a2;
72 
73     SS   = s * s;
74     SS_S = s * s - s;
75     b2 = SS_S * s;
76     b1 = b2 - SS_S;
77     a2 = SS - 2.f * b2;
78 
79     return v0 - a2 * v0 + a2 * v1 + b1 * t0 + b2 * t1;
80 }
81 
82 
83 /*
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94  */
95 inline f32
HermiteC(f32 v0,f32 t0,f32 v1,f32 t1,f32 p,f32 d)96 HermiteC(f32 v0, f32 t0, f32 v1, f32 t1, f32 p, f32 d)
97 {
98     f32 inv_d = 1 / d;
99     f32 s = p * inv_d;
100     f32 s_1 = s - 1;
101     return v0 + (v0 - v1) * (2 * s - 3) * s * s + p * s_1 * (s_1 * t0 + s * t1);
102 }
103 
104 inline f32
HermiteC_FAST(f32 v0,f32 t0,f32 v1,f32 t1,f32 p,f32 d)105 HermiteC_FAST(f32 v0, f32 t0, f32 v1, f32 t1, f32 p, f32 d)
106 {
107 
108     f32 s = p / d;
109     f32 s_1 = s - 1;
110     f32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, ret;
111 
112     tmp1 = (v0 - v1);
113     tmp2 = (2 * s - 3);
114     tmp3 = s * s;
115     tmp4 = p * s_1;
116     tmp5 = s_1 * t0;
117     tmp6 = s * t1;
118 
119     ret = v0 + tmp1 * tmp2 * tmp3 + tmp4 * (tmp5 + tmp6);
120     return ret;
121 }
122 
123 /*
124 
125 */
126 
127 
128 }}}  // nn::math::ARMv6
129 
130 /* NN_MATH_ARMV6_MATH_ARITHMETIC_H_ */
131 #endif
132