unai: Preserve MSB in light routines
authorPaul Cercueil <paul@crapouillou.net>
Thu, 2 Nov 2023 09:49:09 +0000 (10:49 +0100)
committernotaz <notasas@gmail.com>
Thu, 2 Nov 2023 16:08:34 +0000 (18:08 +0200)
Apply the "MSB_PRESERVED" speed hack to non-ARM architectures.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
plugins/gpu_unai/gpu_inner.h
plugins/gpu_unai/gpu_inner_light.h

index eb209ef..9f18735 100644 (file)
 #define gpuLightingRGB gpuLightingRGBARM
 #define gpuLightingTXT gpuLightingTXTARM
 #define gpuLightingTXTGouraud gpuLightingTXTGouraudARM
-// Non-dithering lighting and blending functions preserve uSrc
-// MSB. This saves a few operations and useless load/stores.
-#define MSB_PRESERVED (!CF_DITHER)
 #else
 #define gpuBlending gpuBlendingGeneric
 #define gpuLightingRGB gpuLightingRGBGeneric
 #define gpuLightingTXT gpuLightingTXTGeneric
 #define gpuLightingTXTGouraud gpuLightingTXTGouraudGeneric
-#define MSB_PRESERVED 0
 #endif
 
+// Non-dithering lighting and blending functions preserve uSrc
+// MSB. This saves a few operations and useless load/stores.
+#define MSB_PRESERVED (!CF_DITHER)
 
 // If defined, Gouraud colors are fixed-point 5.11, otherwise they are 8.16
 // This is only for debugging/verification of low-precision colors in C.
index f90e8ec..f4f685b 100644 (file)
@@ -172,7 +172,8 @@ GPU_INLINE uint_fast16_t gpuLightingTXTGeneric(uint_fast16_t uSrc, u8 r5, u8 g5,
 {
        return (gpu_unai.LightLUT[((uSrc&0x7C00)>>5) | b5] << 10) |
               (gpu_unai.LightLUT[ (uSrc&0x03E0)     | g5] <<  5) |
-              (gpu_unai.LightLUT[((uSrc&0x001F)<<5) | r5]      );
+              (gpu_unai.LightLUT[((uSrc&0x001F)<<5) | r5]      ) |
+              (uSrc & 0x8000);
 }
 
 
@@ -194,7 +195,8 @@ GPU_INLINE uint_fast16_t gpuLightingTXTGouraudGeneric(uint_fast16_t uSrc, u32 gC
 {
        return (gpu_unai.LightLUT[((uSrc&0x7C00)>>5) | ((gCol>> 5)&0x1F)]<<10) |
               (gpu_unai.LightLUT[ (uSrc&0x03E0)     | ((gCol>>16)&0x1F)]<< 5) |
-              (gpu_unai.LightLUT[((uSrc&0x001F)<<5) |  (gCol>>27)      ]    );
+              (gpu_unai.LightLUT[((uSrc&0x001F)<<5) |  (gCol>>27)      ]) |
+              (uSrc & 0x8000);
 }