Reverted GX FIFO breakage.
[libogc.git] / gc / ogc / cast.h
blob49016dc3b4dbf6fcb708d3fa3df3e5159078e9e3
1 #ifndef __CAST_H__
2 #define __CAST_H__
4 #include <gctypes.h>
6 #define GQR2 914
7 #define GQR3 915
8 #define GQR4 916
9 #define GQR5 917
10 #define GQR6 918
11 #define GQR7 919
13 #define GQR_TYPE_F32 0
14 #define GQR_TYPE_U8 4
15 #define GQR_TYPE_U16 5
16 #define GQR_TYPE_S8 6
17 #define GQR_TYPE_S16 7
19 #define GQR_CAST_U8 2
20 #define GQR_CAST_U16 3
21 #define GQR_CAST_S8 4
22 #define GQR_CAST_S16 5
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 #ifdef GEKKO
30 #define __set_gqr(_reg,_val) asm volatile("mtspr %0,%1" : : "i"(_reg), "b"(_val))
32 // does a default init
33 static inline void CAST_Init()
35 __asm__ __volatile__ (
36 "li 3,0x0004\n\
37 oris 3,3,0x0004\n\
38 mtspr 914,3\n\
39 li 3,0x0005\n\
40 oris 3,3,0x0005\n\
41 mtspr 915,3\n\
42 li 3,0x0006\n\
43 oris 3,3,0x0006\n\
44 mtspr 916,3\n\
45 li 3,0x0007\n\
46 oris 3,3,0x0007\n\
47 mtspr 917,3\n"
48 : : : "r3"
52 static inline void CAST_SetGQR2(u32 type,u32 scale)
54 register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
55 __set_gqr(GQR2,val);
58 static inline void CAST_SetGQR3(u32 type,u32 scale)
60 register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
61 __set_gqr(GQR3,val);
64 static inline void CAST_SetGQR4(u32 type,u32 scale)
66 register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
67 __set_gqr(GQR4,val);
70 static inline void CAST_SetGQR5(u32 type,u32 scale)
72 register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
73 __set_gqr(GQR5,val);
76 static inline void CAST_SetGQR6(u32 type,u32 scale)
78 register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
79 __set_gqr(GQR6,val);
82 static inline void CAST_SetGQR7(u32 type,u32 scale)
84 register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
85 __set_gqr(GQR7,val);
89 /******************************************************************/
90 /* */
91 /* cast from int to float */
92 /* */
93 /******************************************************************/
95 static inline f32 __castu8f32(register u8 *in)
97 register f32 rval;
98 __asm__ __volatile__ (
99 "psq_l %[rval],0(%[in]),1,2" : [rval]"=f"(rval) : [in]"r"(in)
101 return rval;
104 static inline f32 __castu16f32(register u16 *in)
106 register f32 rval;
107 __asm__ __volatile__ (
108 "psq_l %[rval],0(%[in]),1,3" : [rval]"=f"(rval) : [in]"r"(in)
110 return rval;
113 static inline f32 __casts8f32(register s8 *in)
115 register f32 rval;
116 __asm__ __volatile__ (
117 "psq_l %[rval],0(%[in]),1,4" : [rval]"=f"(rval) : [in]"r"(in)
119 return rval;
122 static inline f32 __casts16f32(register s16 *in)
124 register f32 rval;
125 __asm__ __volatile__ (
126 "psq_l %[rval],0(%[in]),1,5" : [rval]"=f"(rval) : [in]"r"(in)
128 return rval;
131 static inline void castu8f32(register u8 *in,register volatile f32 *out)
133 *out = __castu8f32(in);
136 static inline void castu16f32(register u16 *in,register volatile f32 *out)
138 *out = __castu16f32(in);
141 static inline void casts8f32(register s8 *in,register volatile f32 *out)
143 *out = __casts8f32(in);
146 static inline void casts16f32(register s16 *in,register volatile f32 *out)
148 *out = __casts16f32(in);
151 /******************************************************************/
152 /* */
153 /* cast from float to int */
154 /* */
155 /******************************************************************/
157 static inline u8 __castf32u8(register f32 in)
159 f32 a;
160 register u8 rval;
161 register f32 *ptr = &a;
163 __asm__ __volatile__ (
164 "psq_st %[in],0(%[ptr]),1,2\n"
165 "lbz %[out],0(%[ptr])\n"
166 : [out]"=r"(rval), [ptr]"+r"(ptr) : [in]"f"(in)
168 return rval;
171 static inline u16 __castf32u16(register f32 in)
173 f32 a;
174 register u16 rval;
175 register f32 *ptr = &a;
177 __asm__ __volatile__ (
178 "psq_st %[in],0(%[ptr]),1,3\n"
179 "lhz %[out],0(%[ptr])\n"
180 : [out]"=r"(rval), [ptr]"+r"(ptr) : [in]"f"(in)
182 return rval;
185 static inline s8 __castf32s8(register f32 in)
187 f32 a;
188 register s8 rval;
189 register f32 *ptr = &a;
191 __asm__ __volatile__ (
192 "psq_st %[in],0(%[ptr]),1,4\n"
193 "lbz %[out],0(%[ptr])\n"
194 : [out]"=r"(rval), [ptr]"+r"(ptr) : [in]"f"(in)
196 return rval;
199 static inline s16 __castf32s16(register f32 in)
201 f32 a;
202 register s16 rval;
203 register f32 *ptr = &a;
205 __asm__ __volatile__ (
206 "psq_st %[in],0(%[ptr]),1,5\n"
207 "lha %[out],0(%[ptr])\n"
208 : [out]"=r"(rval), [ptr]"+r"(ptr) : [in]"f"(in)
210 return rval;
213 static inline void castf32u8(register f32 *in,register vu8 *out)
215 *out = __castf32u8(*in);
218 static inline void castf32u16(register f32 *in,register vu16 *out)
220 *out = __castf32u16(*in);
223 static inline void castf32s8(register f32 *in,register vs8 *out)
225 *out = __castf32s8(*in);
228 static inline void castf32s16(register f32 *in,register vs16 *out)
230 *out = __castf32s16(*in);
233 #endif //GEKKO
235 #ifdef __cplusplus
237 #endif
239 #endif