From 9012193413a736e06e75b4d26b407541ed3a4f26 Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 28 Dec 2023 16:08:54 -0600 Subject: [PATCH] Add fast cast inlines --- include/dolphin/os/OSFastCast.h | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/dolphin/os/OSFastCast.h b/include/dolphin/os/OSFastCast.h index b6ca50d1..5022cbb4 100644 --- a/include/dolphin/os/OSFastCast.h +++ b/include/dolphin/os/OSFastCast.h @@ -41,6 +41,40 @@ static inline void OSInitFastCast(void) { } // clang-format off +static inline s16 __OSf32tos16(register f32 inF) +{ + register s16 out; + u32 tmp; + register u32* tmpPtr = &tmp; + // clang-format off + asm { + psq_st inF, 0(tmpPtr), 0x1, OS_FASTCAST_S16 + lha out, 0(tmpPtr) + } + // clang-format on + + return out; +} + +static inline void OSf32tos16(f32 *f, s16 *out) { *out = __OSf32tos16(*f); } + +static inline u8 __OSf32tou8(register f32 inF) +{ + register u8 out; + u32 tmp; + register u32 *tmpPtr = &tmp; + // clang-format off + asm { + psq_st inF, 0(tmpPtr), 0x1, OS_FASTCAST_U8 + lbz out, 0(tmpPtr) + } + // clang-format on + + return out; +} + +static inline void OSf32tou8(f32 *f, u8 *out) { *out = __OSf32tou8(*f); } + #ifdef __cplusplus } #endif