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-10-09 05:37:23 +00:00
|
|
|
inline uchar ToUint8(register float in) {
|
|
|
|
uchar a;
|
|
|
|
register uchar* ptr = &a;
|
|
|
|
register uchar r;
|
2022-08-13 12:57:38 +00:00
|
|
|
|
|
|
|
asm {
|
|
|
|
psq_st in, 0(ptr), 1, OS_FASTCAST_U8
|
|
|
|
lbz r, 0(ptr)
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
inline float ToReal32(register const uchar& in) {
|
|
|
|
register float r;
|
2022-08-13 12:57:38 +00:00
|
|
|
asm {
|
|
|
|
psq_l r, 0(in), 1, 2
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2022-09-05 04:00:04 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
inline short FtoS(register float in) {
|
|
|
|
short a;
|
|
|
|
register short* ptr = &a;
|
2022-09-05 04:00:04 +00:00
|
|
|
|
|
|
|
asm {
|
|
|
|
psq_st in, 0(ptr), 1, OS_FASTCAST_S16
|
|
|
|
}
|
|
|
|
return *ptr;
|
|
|
|
}
|
2022-08-26 03:46:24 +00:00
|
|
|
#else
|
2022-10-09 05:37:23 +00:00
|
|
|
inline uchar ToUint8(float in) { return static_cast< uchar >(in); }
|
|
|
|
inline float ToReal32(uchar in) { return static_cast< float >(in); }
|
|
|
|
inline short FtoS(float in) { return static_cast< short >(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
|