2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CCAST
|
|
|
|
#define _CCAST
|
2022-08-13 12:57:38 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
2022-09-13 04:26:54 +00:00
|
|
|
|
|
|
|
#include "dolphin/os/OSFastCast.h"
|
2022-08-13 12:57:38 +00:00
|
|
|
|
|
|
|
namespace CCast {
|
2022-08-26 03:46:24 +00:00
|
|
|
#ifdef __MWERKS__
|
2022-08-13 12:57:38 +00:00
|
|
|
inline u8 ToUint8(register f32 in) {
|
|
|
|
u8 a;
|
|
|
|
register u8* ptr = &a;
|
|
|
|
register u8 r;
|
|
|
|
|
|
|
|
asm {
|
|
|
|
psq_st in, 0(ptr), 1, OS_FASTCAST_U8
|
|
|
|
lbz r, 0(ptr)
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline f32 ToReal32(register const u8& in) {
|
|
|
|
register f32 r;
|
|
|
|
asm {
|
|
|
|
psq_l r, 0(in), 1, 2
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2022-09-05 04:00:04 +00:00
|
|
|
|
|
|
|
inline s16 FtoS(register f32 in) {
|
|
|
|
s16 a;
|
|
|
|
register s16* ptr = &a;
|
|
|
|
|
|
|
|
asm {
|
|
|
|
psq_st in, 0(ptr), 1, OS_FASTCAST_S16
|
|
|
|
}
|
|
|
|
return *ptr;
|
|
|
|
}
|
2022-08-26 03:46:24 +00:00
|
|
|
#else
|
2022-09-18 06:05:46 +00:00
|
|
|
inline u8 ToUint8(f32 in) { return static_cast< u8 >(in); }
|
|
|
|
inline f32 ToReal32(u8 in) { return static_cast< f32 >(in); }
|
|
|
|
inline s16 FtoS(f32 in) { return static_cast< s16 >(in); }
|
2022-08-26 03:46:24 +00:00
|
|
|
#endif
|
2022-08-13 12:57:38 +00:00
|
|
|
} // namespace CCast
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CCAST
|