RetroArch
cast.h
Go to the documentation of this file.
1 #ifndef __CAST_H__
2 #define __CAST_H__
3 
4 #include <gctypes.h>
5 
6 #define GQR2 914
7 #define GQR3 915
8 #define GQR4 916
9 #define GQR5 917
10 #define GQR6 918
11 #define GQR7 919
12 
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
18 
19 #define GQR_CAST_U8 2
20 #define GQR_CAST_U16 3
21 #define GQR_CAST_S8 4
22 #define GQR_CAST_S16 5
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #ifdef GEKKO
29 
30 #define __set_gqr(_reg,_val) asm volatile("mtspr %0,%1" : : "i"(_reg), "b"(_val))
31 
32 // does a default init
33 static inline void CAST_Init()
34 {
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"
49  );
50 }
51 
52 static inline void CAST_SetGQR2(u32 type,u32 scale)
53 {
54  register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
55  __set_gqr(GQR2,val);
56 }
57 
58 static inline void CAST_SetGQR3(u32 type,u32 scale)
59 {
60  register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
61  __set_gqr(GQR3,val);
62 }
63 
64 static inline void CAST_SetGQR4(u32 type,u32 scale)
65 {
66  register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
67  __set_gqr(GQR4,val);
68 }
69 
70 static inline void CAST_SetGQR5(u32 type,u32 scale)
71 {
72  register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
73  __set_gqr(GQR5,val);
74 }
75 
76 static inline void CAST_SetGQR6(u32 type,u32 scale)
77 {
78  register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
79  __set_gqr(GQR6,val);
80 }
81 
82 static inline void CAST_SetGQR7(u32 type,u32 scale)
83 {
84  register u32 val = (((((scale)<<8)|(type))<<16)|(((scale)<<8)|(type)));
85  __set_gqr(GQR7,val);
86 }
87 
88 
89 /******************************************************************/
90 /* */
91 /* cast from int to float */
92 /* */
93 /******************************************************************/
94 
95 static inline f32 __castu8f32(register u8 *in)
96 {
97  register f32 rval;
98  __asm__ __volatile__ (
99  "psq_l %[rval],0(%[in]),1,2" : [rval]"=f"(rval) : [in]"r"(in)
100  );
101  return rval;
102 }
103 
104 static inline f32 __castu16f32(register u16 *in)
105 {
106  register f32 rval;
107  __asm__ __volatile__ (
108  "psq_l %[rval],0(%[in]),1,3" : [rval]"=f"(rval) : [in]"r"(in)
109  );
110  return rval;
111 }
112 
113 static inline f32 __casts8f32(register s8 *in)
114 {
115  register f32 rval;
116  __asm__ __volatile__ (
117  "psq_l %[rval],0(%[in]),1,4" : [rval]"=f"(rval) : [in]"r"(in)
118  );
119  return rval;
120 }
121 
122 static inline f32 __casts16f32(register s16 *in)
123 {
124  register f32 rval;
125  __asm__ __volatile__ (
126  "psq_l %[rval],0(%[in]),1,5" : [rval]"=f"(rval) : [in]"r"(in)
127  );
128  return rval;
129 }
130 
131 static inline void castu8f32(register u8 *in,register volatile f32 *out)
132 {
133  *out = __castu8f32(in);
134 }
135 
136 static inline void castu16f32(register u16 *in,register volatile f32 *out)
137 {
138  *out = __castu16f32(in);
139 }
140 
141 static inline void casts8f32(register s8 *in,register volatile f32 *out)
142 {
143  *out = __casts8f32(in);
144 }
145 
146 static inline void casts16f32(register s16 *in,register volatile f32 *out)
147 {
148  *out = __casts16f32(in);
149 }
150 
151 /******************************************************************/
152 /* */
153 /* cast from float to int */
154 /* */
155 /******************************************************************/
156 
157 static inline u8 __castf32u8(register f32 in)
158 {
159  f32 a;
160  register u8 rval;
161  register f32 *ptr = &a;
162 
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)
167  );
168  return rval;
169 }
170 
171 static inline u16 __castf32u16(register f32 in)
172 {
173  f32 a;
174  register u16 rval;
175  register f32 *ptr = &a;
176 
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)
181  );
182  return rval;
183 }
184 
185 static inline s8 __castf32s8(register f32 in)
186 {
187  f32 a;
188  register s8 rval;
189  register f32 *ptr = &a;
190 
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)
195  );
196  return rval;
197 }
198 
199 static inline s16 __castf32s16(register f32 in)
200 {
201  f32 a;
202  register s16 rval;
203  register f32 *ptr = &a;
204 
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)
209  );
210  return rval;
211 }
212 
213 static inline void castf32u8(register f32 *in,register vu8 *out)
214 {
215  *out = __castf32u8(*in);
216 }
217 
218 static inline void castf32u16(register f32 *in,register vu16 *out)
219 {
220  *out = __castf32u16(*in);
221 }
222 
223 static inline void castf32s8(register f32 *in,register vs8 *out)
224 {
225  *out = __castf32s8(*in);
226 }
227 
228 static inline void castf32s16(register f32 *in,register vs16 *out)
229 {
230  *out = __castf32s16(*in);
231 }
232 
233 #endif //GEKKO
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 #endif
#define GQR7
Definition: cast.h:11
const GLvoid * ptr
Definition: nx_glsym.h:242
#define GQR6
Definition: cast.h:10
GLuint GLfloat * val
Definition: glext.h:7847
volatile u8 vu8
8bit unsigned volatile integer
Definition: gctypes.h:27
__asm__(".arm\n" ".align 4\n" ".globl co_switch_arm\n" ".globl _co_switch_arm\n" "co_switch_arm:\n" "_co_switch_arm:\n" " stmia r1!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, lr}\n" " ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, pc}\n")
Data type definitions.
float f32
Definition: gctypes.h:43
volatile s8 vs8
8bit signed volatile integer
Definition: gctypes.h:32
int8_t s8
8bit signed integer
Definition: gctypes.h:22
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9939
struct passwd out
Definition: missing_libc_functions.c:51
GLenum type
Definition: glext.h:6233
uint16_t u16
16bit unsigned integer
Definition: gctypes.h:18
#define GQR5
Definition: cast.h:9
GLuint in
Definition: glext.h:10523
#define GQR4
Definition: cast.h:8
int16_t s16
16bit signed integer
Definition: gctypes.h:23
#define GQR2
Definition: cast.h:6
volatile s16 vs16
16bit signed volatile integer
Definition: gctypes.h:33
uint8_t u8
8bit unsigned integer
Definition: gctypes.h:17
uint32_t u32
32bit unsigned integer
Definition: gctypes.h:19
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
volatile u16 vu16
16bit unsigned volatile integer
Definition: gctypes.h:28
#define GQR3
Definition: cast.h:7