1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - FX -
3 File: fx_cp.h
4
5 Copyright 2003-2008 Nintendo. 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 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_FX_CP_H_
19 #define NITRO_FX_CP_H_
20
21 #include <nitro/fx/fx.h>
22 #include <nitro/fx/fx_const.h>
23 #include <nitro/cp/divider.h>
24 #include <nitro/cp/sqrt.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 //----------------------------------------------------------------------------
31 // Type definition
32 //----------------------------------------------------------------------------
33
34 //----------------------------------------------------------------------------
35 // Declaration of function
36 //----------------------------------------------------------------------------
37
38 fx32 FX_Div(fx32 numer, fx32 denom);
39 fx64c FX_DivFx64c(fx32 numer, fx32 denom);
40 SDK_DECL_INLINE fx32 FX_Mod(fx32 numer, fx32 denom);
41 fx32 FX_Sqrt(fx32 x);
42 fx32 FX_Inv(fx32 denom);
43 fx64c FX_InvFx64c(fx32 denom);
44 fx32 FX_InvSqrt(fx32 x);
45
46 void FX_DivAsync(fx32 numer, fx32 denom);
47 SDK_DECL_INLINE void FX_DivAsyncImm(fx32 numer, fx32 denom);
48 fx64c FX_GetDivResultFx64c(void);
49 fx32 FX_GetDivResult(void);
50 fx64c FX_GetDivRemainderFx64c(void);
51 fx32 FX_GetDivRemainder(void);
52
53 void FX_InvAsync(fx32 denom);
54 SDK_DECL_INLINE void FX_InvAsyncImm(fx32 denom);
55 SDK_DECL_INLINE fx64c FX_GetInvResultFx64c(void);
56 SDK_DECL_INLINE fx32 FX_GetInvResult(void);
57
58 void FX_SqrtAsync(fx32 x);
59 void FX_SqrtAsyncImm(fx32 x);
60 fx32 FX_GetSqrtResult(void);
61
62 s32 FX_DivS32(s32 a, s32 b);
63 s32 FX_ModS32(s32 a, s32 b);
64
65 #define FX_DIVISION_BY_ZERO(a, b) \
66 SDK_WARNING(b != 0, "Division by zero(%d / %d)", a, b)
67
68 //----------------------------------------------------------------------------
69 // Implementation of inline function
70 //----------------------------------------------------------------------------
71
72 // Inv
73 /*---------------------------------------------------------------------------*
74 Name: FX_InvAsyncImm
75
76 Description: Just the same as FX_DivAsyncImm(FX32_ONE, denom).
77 This function sets numer and denom onto the divider.
78 It assumes that the divider is in DIVMODE 01(64/32).
79
80 Arguments: denom in fx32 format
81
82 Returns: none
83 *---------------------------------------------------------------------------*/
FX_InvAsyncImm(fx32 denom)84 SDK_INLINE void FX_InvAsyncImm(fx32 denom)
85 {
86 SDK_ASSERT(!CP_IsDivBusy());
87 FX_DIVISION_BY_ZERO(FX32_ONE, denom);
88
89 CP_SetDivImm64_32((u64)FX32_ONE << 32, (u32)denom);
90 }
91
92
93 /*---------------------------------------------------------------------------*
94 Name: FX_GetInvResultFx64c
95
96 Description: Just the same as FX_GetDivResultFx64c().
97
98 Arguments: none
99
100 Returns: a reciprocal in fx64c format
101 *---------------------------------------------------------------------------*/
FX_GetInvResultFx64c(void)102 SDK_INLINE fx64c FX_GetInvResultFx64c(void)
103 {
104 return FX_GetDivResultFx64c();
105 }
106
107 /*---------------------------------------------------------------------------*
108 Name: FX_GetInvResult
109
110 Description: Just the same as FX_GetDivResult().
111
112 Arguments: none
113
114 Returns: a reciprocal in fx32 format
115 *---------------------------------------------------------------------------*/
FX_GetInvResult(void)116 SDK_INLINE fx32 FX_GetInvResult(void)
117 {
118 return FX_GetDivResult();
119 }
120
121 /*---------------------------------------------------------------------------*
122 Name: FX_DivAsyncImm
123
124 Description: Use a divider asynchronously.
125 This function sets numer and denom onto the divider.
126 It assumes that the divider is in DIVMODE 01(64/32).
127
128 Arguments: numer in fx32 format
129 denom in fx32 format
130
131 Returns: none
132 *---------------------------------------------------------------------------*/
FX_DivAsyncImm(fx32 numer,fx32 denom)133 SDK_INLINE void FX_DivAsyncImm(fx32 numer, fx32 denom)
134 {
135 SDK_ASSERT(!CP_IsDivBusy());
136 FX_DIVISION_BY_ZERO(numer, denom);
137
138 CP_SetDivImm64_32((u64)numer << 32, (u32)denom);
139 }
140
141 /*---------------------------------------------------------------------------*
142 Name: FX_Mod
143
144 Description: Divides 'numer' by 'denom', and returns the remainder in fx32
145 format. This uses the divider.
146
147 Arguments: numer a value in fx32 format
148 denom a value in fx32 format
149
150 Returns: result in fx32 format
151 *---------------------------------------------------------------------------*/
FX_Mod(fx32 numer,fx32 denom)152 SDK_INLINE fx32 FX_Mod(fx32 numer, fx32 denom)
153 {
154 return (fx32)FX_ModS32(numer, denom);
155 }
156
157 #ifdef __cplusplus
158 }/* extern "C" */
159 #endif
160
161 #endif
162