From 0a371c2c4a1097bbbe888ed00d5f2d1d1fafa1f5 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 30 Jul 2022 01:07:21 +0300 Subject: [PATCH] dfxvideo: patch up some unsafe macros (old?)-ARM version of GETLE32() was causing wrong shifting due to implicit signed int promotion. libretro/pcsx_rearmed#676 --- plugins/dfxvideo/gpu.h | 18 +++++++++--------- plugins/dfxvideo/gpulib_if.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/dfxvideo/gpu.h b/plugins/dfxvideo/gpu.h index 7b5aaef0..74556928 100644 --- a/plugins/dfxvideo/gpu.h +++ b/plugins/dfxvideo/gpu.h @@ -64,6 +64,7 @@ #include #include #include +#include "../../include/arm_features.h" ///////////////////////////////////////////////////////////////////////////// @@ -100,16 +101,15 @@ #endif -#define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)X)) -#define GETLEs32(X) ((int16_t)GETLE32((uint16_t *)X)) +#define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)(X))) -#define GETLE16(X) LE2HOST16(*(uint16_t *)X) -#define GETLE32_(X) LE2HOST32(*(uint32_t *)X) -#define GETLE16D(X) ({uint32_t val = GETLE32(X); (val<<16 | val >> 16);}) -#define PUTLE16(X, Y) do{*((uint16_t *)X)=HOST2LE16((uint16_t)Y);}while(0) -#define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE32((uint32_t)Y);}while(0) -#ifdef __arm__ -#define GETLE32(X) (*(uint16_t *)(X)|(((uint16_t *)(X))[1]<<16)) +#define GETLE16(X) LE2HOST16(*(uint16_t *)(X)) +#define GETLE32_(X) LE2HOST32(*(uint32_t *)(X)) +#define PUTLE16(X, Y) do{*((uint16_t *)(X))=HOST2LE16((uint16_t)(Y));}while(0) +#define PUTLE32_(X, Y) do{*((uint32_t *)(X))=HOST2LE32((uint32_t)(Y));}while(0) +#if defined(__arm__) && !defined(HAVE_ARMV6) +// for (very) old ARMs with no unaligned loads? +#define GETLE32(X) (*(uint16_t *)(X)|((uint32_t)((uint16_t *)(X))[1]<<16)) #define PUTLE32(X, Y) do{uint16_t *p_=(uint16_t *)(X);uint32_t y_=Y;p_[0]=y_;p_[1]=y_>>16;}while(0) #else #define GETLE32 GETLE32_ diff --git a/plugins/dfxvideo/gpulib_if.c b/plugins/dfxvideo/gpulib_if.c index c4e4cfea..47cccedf 100644 --- a/plugins/dfxvideo/gpulib_if.c +++ b/plugins/dfxvideo/gpulib_if.c @@ -16,6 +16,7 @@ #include #include #include "../gpulib/gpu.h" +#include "../../include/arm_features.h" #define u32 uint32_t @@ -68,16 +69,15 @@ #endif -#define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)X)) -#define GETLEs32(X) ((int16_t)GETLE32((uint16_t *)X)) +#define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)(X))) -#define GETLE16(X) LE2HOST16(*(uint16_t *)X) -#define GETLE32_(X) LE2HOST32(*(uint32_t *)X) -#define GETLE16D(X) ({uint32_t val = GETLE32(X); (val<<16 | val >> 16);}) -#define PUTLE16(X, Y) do{*((uint16_t *)X)=HOST2LE16((uint16_t)Y);}while(0) -#define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE32((uint32_t)Y);}while(0) -#ifdef __arm__ -#define GETLE32(X) (*(uint16_t *)(X)|(((uint16_t *)(X))[1]<<16)) +#define GETLE16(X) LE2HOST16(*(uint16_t *)(X)) +#define GETLE32_(X) LE2HOST32(*(uint32_t *)(X)) +#define PUTLE16(X, Y) do{*((uint16_t *)(X))=HOST2LE16((uint16_t)(Y));}while(0) +#define PUTLE32_(X, Y) do{*((uint32_t *)(X))=HOST2LE32((uint32_t)(Y));}while(0) +#if defined(__arm__) && !defined(HAVE_ARMV6) +// for (very) old ARMs with no unaligned loads? +#define GETLE32(X) (*(uint16_t *)(X)|((uint32_t)((uint16_t *)(X))[1]<<16)) #define PUTLE32(X, Y) do{uint16_t *p_=(uint16_t *)(X);uint32_t y_=Y;p_[0]=y_;p_[1]=y_>>16;}while(0) #else #define GETLE32 GETLE32_ -- 2.39.5