13 #define GQR_TYPE_F32 0
15 #define GQR_TYPE_U16 5
17 #define GQR_TYPE_S16 7
20 #define GQR_CAST_U16 3
22 #define GQR_CAST_S16 5
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__ (
52 static inline void CAST_SetGQR2(u32 type
,u32 scale
)
54 register u32 val
= (((((scale
)<<8)|(type
))<<16)|(((scale
)<<8)|(type
)));
58 static inline void CAST_SetGQR3(u32 type
,u32 scale
)
60 register u32 val
= (((((scale
)<<8)|(type
))<<16)|(((scale
)<<8)|(type
)));
64 static inline void CAST_SetGQR4(u32 type
,u32 scale
)
66 register u32 val
= (((((scale
)<<8)|(type
))<<16)|(((scale
)<<8)|(type
)));
70 static inline void CAST_SetGQR5(u32 type
,u32 scale
)
72 register u32 val
= (((((scale
)<<8)|(type
))<<16)|(((scale
)<<8)|(type
)));
76 static inline void CAST_SetGQR6(u32 type
,u32 scale
)
78 register u32 val
= (((((scale
)<<8)|(type
))<<16)|(((scale
)<<8)|(type
)));
82 static inline void CAST_SetGQR7(u32 type
,u32 scale
)
84 register u32 val
= (((((scale
)<<8)|(type
))<<16)|(((scale
)<<8)|(type
)));
89 /******************************************************************/
91 /* cast from int to float */
93 /******************************************************************/
95 static inline f32
__castu8f32(register u8
*in
)
98 __asm__
__volatile__ (
99 "psq_l %[rval],0(%[in]),1,2" : [rval
]"=f"(rval
) : [in
]"r"(in
)
104 static inline f32
__castu16f32(register u16
*in
)
107 __asm__
__volatile__ (
108 "psq_l %[rval],0(%[in]),1,3" : [rval
]"=f"(rval
) : [in
]"r"(in
)
113 static inline f32
__casts8f32(register s8
*in
)
116 __asm__
__volatile__ (
117 "psq_l %[rval],0(%[in]),1,4" : [rval
]"=f"(rval
) : [in
]"r"(in
)
122 static inline f32
__casts16f32(register s16
*in
)
125 __asm__
__volatile__ (
126 "psq_l %[rval],0(%[in]),1,5" : [rval
]"=f"(rval
) : [in
]"r"(in
)
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 /******************************************************************/
153 /* cast from float to int */
155 /******************************************************************/
157 static inline u8
__castf32u8(register f32 in
)
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
)
171 static inline u16
__castf32u16(register f32 in
)
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
)
185 static inline s8
__castf32s8(register f32 in
)
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
)
199 static inline s16
__castf32s16(register f32 in
)
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
)
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
);