From c61f30a6274c43041949e44ff1a6b9a7749c45cb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 9 Dec 2016 12:48:10 +0100 Subject: [PATCH] - got rid of clearbuf. This was used in only 4 places, 3 of which could easily be replaced with a memset, and the fourth, in the Strife status bar, suffering from a pointless performance optimization, rendering the code unreadable - the code spent here per frame is utterly insignificant so clarity should win here. (cherry picked from commit 12a99c3f3cc75fa3b241d89a8ebe43c8d3c07809) --- src/basicinlines.h | 9 --------- src/g_strife/strife_sbar.cpp | 10 +++------- src/gccinlines.h | 13 ------------- src/mscinlines.h | 9 --------- src/p_maputl.cpp | 2 +- src/r_data/sprites.cpp | 4 ++-- 6 files changed, 6 insertions(+), 41 deletions(-) diff --git a/src/basicinlines.h b/src/basicinlines.h index 2f81a6c64..488cdf552 100644 --- a/src/basicinlines.h +++ b/src/basicinlines.h @@ -177,15 +177,6 @@ static inline SDWORD DivScale30 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD) static inline SDWORD DivScale31 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 31) / b); } static inline SDWORD DivScale32 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 32) / b); } -static __forceinline void clearbuf (void *buff, unsigned int count, SDWORD clear) -{ - SDWORD *b2 = (SDWORD *)buff; - for (unsigned int i = 0; i != count; ++i) - { - b2[i] = clear; - } -} - static __forceinline void clearbufshort (void *buff, unsigned int count, WORD clear) { SWORD *b2 = (SWORD *)buff; diff --git a/src/g_strife/strife_sbar.cpp b/src/g_strife/strife_sbar.cpp index 355910616..ccf17f8f1 100644 --- a/src/g_strife/strife_sbar.cpp +++ b/src/g_strife/strife_sbar.cpp @@ -169,14 +169,10 @@ void FHealthBar::MakeTexture () void FHealthBar::FillBar (int min, int max, BYTE light, BYTE dark) { -#ifdef __BIG_ENDIAN__ - SDWORD fill = (light << 24) | (dark << 16) | (light << 8) | dark; -#else - SDWORD fill = light | (dark << 8) | (light << 16) | (dark << 24); -#endif - if (max > min) + for (int i = min*2; i < max*2; i++) { - clearbuf (&Pixels[min*4], max - min, fill); + Pixels[i * 2] = light; + Pixels[i * 2 + 1] = dark; } } diff --git a/src/gccinlines.h b/src/gccinlines.h index 7311e9695..54a2448c7 100644 --- a/src/gccinlines.h +++ b/src/gccinlines.h @@ -291,19 +291,6 @@ static inline SDWORD DivScale32 (SDWORD a, SDWORD b) return result; } -static inline void clearbuf (void *buff, int count, SDWORD clear) -{ - int dummy1, dummy2; - asm volatile - ("rep stosl" - :"=D" (dummy1), - "=c" (dummy2) - : "D" (buff), - "c" (count), - "a" (clear) - ); -} - static inline void clearbufshort (void *buff, unsigned int count, WORD clear) { asm volatile diff --git a/src/mscinlines.h b/src/mscinlines.h index 7befe5395..1aded4e7b 100644 --- a/src/mscinlines.h +++ b/src/mscinlines.h @@ -321,15 +321,6 @@ __forceinline SDWORD DivScale32 (SDWORD a, SDWORD b) __asm idiv b } -__forceinline void clearbuf (void *buff, unsigned int count, SDWORD clear) -{ - SDWORD *b2 = (SDWORD *)buff; - for (unsigned int i = 0; i != count; ++i) - { - b2[i] = clear; - } -} - __forceinline void clearbufshort (void *buff, unsigned int count, WORD clear) { SWORD *b2 = (SWORD *)buff; diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 31b412598..fdf66e969 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -925,7 +925,7 @@ void FBlockThingsIterator::init(const FBoundingBox &box) void FBlockThingsIterator::ClearHash() { - clearbuf(Buckets, countof(Buckets), -1); + memset(Buckets, -1, sizeof(Buckets)); NumFixedHash = 0; DynHash.Clear(); } diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index 3e0cb80cc..b384211fc 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -270,7 +270,7 @@ void R_InitSpriteDefs () // Create a hash table to speed up the process smax = TexMan.NumTextures(); hashes = new Hasher[smax]; - clearbuf(hashes, sizeof(Hasher)*smax/4, -1); + memset(hashes, -1, sizeof(Hasher)*smax); for (i = 0; i < smax; ++i) { FTexture *tex = TexMan.ByIndex(i); @@ -285,7 +285,7 @@ void R_InitSpriteDefs () // Repeat, for voxels vmax = Wads.GetNumLumps(); vhashes = new VHasher[vmax]; - clearbuf(vhashes, sizeof(VHasher)*vmax/4, -1); + memset(vhashes, -1, sizeof(VHasher)*vmax); for (i = 0; i < vmax; ++i) { if (Wads.GetLumpNamespace(i) == ns_voxels)