From dc00af88294104f99e673451482b7b633f034f72 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sun, 23 Apr 2017 19:08:29 +0200 Subject: [PATCH] psx|spu2x|gsdx: shift negative value is undefined in C standard Instead does the negation after the shift v2: assert shift <= 15 in clamp_mix --- pcsx2/IopGte.cpp | 6 +++--- plugins/GSdx/GSRendererSW.cpp | 2 +- plugins/spu2-x/src/Mixer.cpp | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pcsx2/IopGte.cpp b/pcsx2/IopGte.cpp index 4a425569bc..410409a098 100644 --- a/pcsx2/IopGte.cpp +++ b/pcsx2/IopGte.cpp @@ -468,9 +468,9 @@ __inline double limG2(double x) { return (x); } -__inline s32 F12limA1S(s64 x) { _LIMX(-32768 << 12, 32767 << 12, 24); } -__inline s32 F12limA2S(s64 x) { _LIMX(-32768 << 12, 32767 << 12, 23); } -__inline s32 F12limA3S(s64 x) { _LIMX(-32768 << 12, 32767 << 12, 22); } +__inline s32 F12limA1S(s64 x) { _LIMX(-(32768 << 12), 32767 << 12, 24); } +__inline s32 F12limA2S(s64 x) { _LIMX(-(32768 << 12), 32767 << 12, 23); } +__inline s32 F12limA3S(s64 x) { _LIMX(-(32768 << 12), 32767 << 12, 22); } __inline s32 F12limA1U(s64 x) { _LIMX(0, 32767 << 12, 24); } __inline s32 F12limA2U(s64 x) { _LIMX(0, 32767 << 12, 23); } __inline s32 F12limA3U(s64 x) { _LIMX(0, 32767 << 12, 22); } diff --git a/plugins/GSdx/GSRendererSW.cpp b/plugins/GSdx/GSRendererSW.cpp index fd273ee1d6..4a39ac1e3f 100644 --- a/plugins/GSdx/GSRendererSW.cpp +++ b/plugins/GSdx/GSRendererSW.cpp @@ -1140,7 +1140,7 @@ bool GSRendererSW::GetScanlineGlobalData(SharedData* data) else { gd.mxl = GSVector4((float)mxl); - gd.l = GSVector4((float)(-0x10000 << context->TEX1.L)); + gd.l = GSVector4((float)(-(0x10000 << context->TEX1.L))); gd.k = GSVector4((float)k); } diff --git a/plugins/spu2-x/src/Mixer.cpp b/plugins/spu2-x/src/Mixer.cpp index bdbdf216c9..2c75c4cc9c 100644 --- a/plugins/spu2-x/src/Mixer.cpp +++ b/plugins/spu2-x/src/Mixer.cpp @@ -53,7 +53,8 @@ static __forceinline s32 MulShr32(s32 srcval, s32 mulval) __forceinline s32 clamp_mix(s32 x, u8 bitshift) { - return GetClamped(x, -0x8000 << bitshift, 0x7fff << bitshift); + assert(bitshift <= 15); + return GetClamped(x, -(0x8000 << bitshift), 0x7fff << bitshift); } #if _MSC_VER @@ -72,8 +73,8 @@ __forceinline // modules or sound drivers could (will :p) overshoot with that. So giving it a small safety. return StereoOut32( - GetClamped(sample.Left, -0x7f00 << bitshift, 0x7f00 << bitshift), - GetClamped(sample.Right, -0x7f00 << bitshift, 0x7f00 << bitshift)); + GetClamped(sample.Left, -(0x7f00 << bitshift), 0x7f00 << bitshift), + GetClamped(sample.Right, -(0x7f00 << bitshift), 0x7f00 << bitshift)); } static void __forceinline XA_decode_block(s16 *buffer, const s16 *block, s32 &prev1, s32 &prev2)