From: notaz Date: Tue, 22 Oct 2024 20:53:38 +0000 (+0300) Subject: mdec: compiler-friendlier clamp X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c3a80b2408d5a98521746c26502cd7addf3b365;p=pcsx_rearmed.git mdec: compiler-friendlier clamp that whole thing begs to be rewritten but ohwell --- diff --git a/libpcsxcore/mdec.c b/libpcsxcore/mdec.c index 38b03e1b..d02a419a 100644 --- a/libpcsxcore/mdec.c +++ b/libpcsxcore/mdec.c @@ -323,11 +323,22 @@ static const unsigned short *rl2blk(int *blk, const unsigned short *mdec_rl) { #define SCALE8(c) SCALER(c, 20) #define SCALE5(c) SCALER(c, 23) -#define CLAMP5(c) ( ((c) < -16) ? 0 : (((c) > (31 - 16)) ? 31 : ((c) + 16)) ) -#define CLAMP8(c) ( ((c) < -128) ? 0 : (((c) > (255 - 128)) ? 255 : ((c) + 128)) ) +static inline int clamp5(int v) +{ + v += 16; + v = v < 0 ? 0 : (v > 31 ? 31 : v); + return v; +} + +static inline int clamp8(int v) +{ + v += 128; + v = v < 0 ? 0 : (v > 255 ? 255 : v); + return v; +} -#define CLAMP_SCALE8(a) (CLAMP8(SCALE8(a))) -#define CLAMP_SCALE5(a) (CLAMP5(SCALE5(a))) +#define CLAMP_SCALE8(a) (clamp8(SCALE8(a))) +#define CLAMP_SCALE5(a) (clamp5(SCALE5(a))) static inline void putlinebw15(u16 *image, int *Yblk) { int i; @@ -336,7 +347,7 @@ static inline void putlinebw15(u16 *image, int *Yblk) { for (i = 0; i < 8; i++, Yblk++) { int Y = *Yblk; // missing rounding - image[i] = SWAP16((CLAMP5(Y >> 3) * 0x421) | A); + image[i] = SWAP16((clamp5(Y >> 3) * 0x421) | A); } } @@ -385,7 +396,7 @@ static inline void putlinebw24(u8 * image, int *Yblk) { int i; unsigned char Y; for (i = 0; i < 8 * 3; i += 3, Yblk++) { - Y = CLAMP8(*Yblk); + Y = clamp8(*Yblk); image[i + 0] = Y; image[i + 1] = Y; image[i + 2] = Y;