diff --git a/src/basicinlines.h b/src/basicinlines.h index 488cdf5526..8492572818 100644 --- a/src/basicinlines.h +++ b/src/basicinlines.h @@ -177,12 +177,3 @@ 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 clearbufshort (void *buff, unsigned int count, WORD clear) -{ - SWORD *b2 = (SWORD *)buff; - for (unsigned int i = 0; i != count; ++i) - { - b2[i] = clear; - } -} - diff --git a/src/g_shared/a_lightning.cpp b/src/g_shared/a_lightning.cpp index 3f44f2fddd..bbc6638123 100644 --- a/src/g_shared/a_lightning.cpp +++ b/src/g_shared/a_lightning.cpp @@ -23,7 +23,7 @@ DLightningThinker::DLightningThinker () NextLightningFlash = ((pr_lightning()&15)+5)*35; // don't flash at level start LightningLightLevels.Resize(numsectors); - clearbufshort(&LightningLightLevels[0], numsectors, SHRT_MAX); + fillshort(&LightningLightLevels[0], numsectors, SHRT_MAX); } DLightningThinker::~DLightningThinker () @@ -87,7 +87,7 @@ void DLightningThinker::LightningFlash () tempSec->SetLightLevel(LightningLightLevels[j]); } } - clearbufshort(&LightningLightLevels[0], numsectors, SHRT_MAX); + fillshort(&LightningLightLevels[0], numsectors, SHRT_MAX); level.flags &= ~LEVEL_SWAPSKIES; } return; diff --git a/src/gccinlines.h b/src/gccinlines.h index 54a2448c70..eac1f3e6fb 100644 --- a/src/gccinlines.h +++ b/src/gccinlines.h @@ -290,16 +290,3 @@ static inline SDWORD DivScale32 (SDWORD a, SDWORD b) : "cc"); return result; } - -static inline void clearbufshort (void *buff, unsigned int count, WORD clear) -{ - asm volatile - ("shr $1,%%ecx\n\t" - "rep stosl\n\t" - "adc %%ecx,%%ecx\n\t" - "rep stosw" - :"=D" (buff), "=c" (count) - :"D" (buff), "c" (count), "a" (clear|(clear<<16)) - :"cc"); -} - diff --git a/src/m_fixed.h b/src/m_fixed.h index 4719ac4680..33d339608a 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -1,11 +1,3 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file is based on pragmas.h from Ken Silverman's original Build -// source code release and contains routines that were originally -// inline assembly but are not now. - #ifndef __M_FIXED__ #define __M_FIXED__ @@ -20,64 +12,25 @@ #include "basicinlines.h" #endif -#include "xs_Float.h" - -#define MAKESAFEDIVSCALE(x) \ - inline SDWORD SafeDivScale##x (SDWORD a, SDWORD b) \ - { \ - if ((DWORD)abs(a) >> (31-x) >= (DWORD)abs (b)) \ - return (a^b)<0 ? FIXED_MIN : FIXED_MAX; \ - return DivScale##x (a, b); \ - } - -MAKESAFEDIVSCALE(1) -MAKESAFEDIVSCALE(2) -MAKESAFEDIVSCALE(3) -MAKESAFEDIVSCALE(4) -MAKESAFEDIVSCALE(5) -MAKESAFEDIVSCALE(6) -MAKESAFEDIVSCALE(7) -MAKESAFEDIVSCALE(8) -MAKESAFEDIVSCALE(9) -MAKESAFEDIVSCALE(10) -MAKESAFEDIVSCALE(11) -MAKESAFEDIVSCALE(12) -MAKESAFEDIVSCALE(13) -MAKESAFEDIVSCALE(14) -MAKESAFEDIVSCALE(15) -MAKESAFEDIVSCALE(16) -MAKESAFEDIVSCALE(17) -MAKESAFEDIVSCALE(18) -MAKESAFEDIVSCALE(19) -MAKESAFEDIVSCALE(20) -MAKESAFEDIVSCALE(21) -MAKESAFEDIVSCALE(22) -MAKESAFEDIVSCALE(23) -MAKESAFEDIVSCALE(24) -MAKESAFEDIVSCALE(25) -MAKESAFEDIVSCALE(26) -MAKESAFEDIVSCALE(27) -MAKESAFEDIVSCALE(28) -MAKESAFEDIVSCALE(29) -MAKESAFEDIVSCALE(30) -#undef MAKESAFEDIVSCALE - -inline SDWORD SafeDivScale31 (SDWORD a, SDWORD b) +__forceinline void fillshort(void *buff, unsigned int count, WORD clear) { - if ((DWORD)abs(a) >= (DWORD)abs (b)) - return (a^b)<0 ? FIXED_MIN : FIXED_MAX; - return DivScale31 (a, b); + SWORD *b2 = (SWORD *)buff; + for (unsigned int i = 0; i != count; ++i) + { + b2[i] = clear; + } } -inline SDWORD SafeDivScale32 (SDWORD a, SDWORD b) -{ - if ((DWORD)abs(a) >= (DWORD)abs (b) >> 1) - return (a^b)<0 ? FIXED_MIN : FIXED_MAX; - return DivScale32 (a, b); +#include "xs_Float.h" + +inline SDWORD FixedDiv (SDWORD a, SDWORD b) +{ + if ((DWORD)abs(a) >> (31-16) >= (DWORD)abs (b)) + return (a^b)<0 ? FIXED_MIN : FIXED_MAX; + return DivScale16 (a, b); } #define FixedMul MulScale16 -#define FixedDiv SafeDivScale16 inline fixed_t FloatToFixed(double f) { diff --git a/src/mscinlines.h b/src/mscinlines.h index 1aded4e7b7..6af2da1de7 100644 --- a/src/mscinlines.h +++ b/src/mscinlines.h @@ -321,13 +321,4 @@ __forceinline SDWORD DivScale32 (SDWORD a, SDWORD b) __asm idiv b } -__forceinline void clearbufshort (void *buff, unsigned int count, WORD clear) -{ - SWORD *b2 = (SWORD *)buff; - for (unsigned int i = 0; i != count; ++i) - { - b2[i] = clear; - } -} - #pragma warning (default: 4035) diff --git a/src/p_effect.cpp b/src/p_effect.cpp index 42e82d7405..827a457ee2 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -198,7 +198,7 @@ void P_FindParticleSubsectors () ParticlesInSubsec.Reserve (numsubsectors - ParticlesInSubsec.Size()); } - clearbufshort (&ParticlesInSubsec[0], numsubsectors, NO_PARTICLE); + fillshort (&ParticlesInSubsec[0], numsubsectors, NO_PARTICLE); if (!r_particles) { diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index bb076d72f5..230e16dccf 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -740,8 +740,8 @@ void R_AddLine (seg_t *line) if (line->linedef->special == Line_Horizon) { // Be aware: Line_Horizon does not work properly with sloped planes - clearbufshort (walltop+WallC.sx1, WallC.sx2 - WallC.sx1, centery); - clearbufshort (wallbottom+WallC.sx1, WallC.sx2 - WallC.sx1, centery); + fillshort (walltop+WallC.sx1, WallC.sx2 - WallC.sx1, centery); + fillshort (wallbottom+WallC.sx1, WallC.sx2 - WallC.sx1, centery); } else { diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 766ad8d7aa..b23bf40818 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -1641,7 +1641,7 @@ namespace swrenderer if (b2 > t2) { - clearbufshort(spanend + t2, b2 - t2, x); + fillshort(spanend + t2, b2 - t2, x); } R_SetColorMapLight(basecolormap, (float)light, wallshade); @@ -1668,7 +1668,7 @@ namespace swrenderer if (b1 > b2) b2 = b1; if (t2 < b2) { - clearbufshort(spanend + t2, b2 - t2, x); + fillshort(spanend + t2, b2 - t2, x); } rcolormap = lcolormap; R_SetColorMapLight(basecolormap, (float)light, wallshade); diff --git a/src/r_main.cpp b/src/r_main.cpp index 543b7cd59a..e79800e49f 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -377,7 +377,7 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, pspritexiscale = 1 / pspritexscale; // thing clipping - clearbufshort (screenheightarray, viewwidth, (short)viewheight); + fillshort (screenheightarray, viewwidth, (short)viewheight); R_InitTextureMapping (); @@ -400,7 +400,7 @@ void R_InitRenderer() { atterm(R_ShutdownRenderer); // viewwidth / viewheight are set by the defaults - clearbufshort (zeroarray, MAXWIDTH, 0); + fillshort (zeroarray, MAXWIDTH, 0); R_InitPlanes (); R_InitShadeMaps(); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 3769dda061..f8893dcd75 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -328,9 +328,9 @@ void R_ClearPlanes (bool fullclear) } // opening / clipping determination - clearbufshort (floorclip, viewwidth, viewheight); + fillshort (floorclip, viewwidth, viewheight); // [RH] clip ceiling to console bottom - clearbufshort (ceilingclip, viewwidth, + fillshort (ceilingclip, viewwidth, !screen->Accel2D && ConBottom > viewwindowy && !bRenderingToCanvas ? (ConBottom - viewwindowy) : 0); @@ -503,7 +503,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl check->MirrorFlags = MirrorFlags; check->CurrentSkybox = CurrentSkybox; - clearbufshort (check->top, viewwidth, 0x7fff); + fillshort (check->top, viewwidth, 0x7fff); return check; } @@ -588,7 +588,7 @@ visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop) pl = new_pl; pl->left = start; pl->right = stop; - clearbufshort (pl->top, viewwidth, 0x7fff); + fillshort (pl->top, viewwidth, 0x7fff); } return pl; } @@ -1816,7 +1816,7 @@ void R_MapVisPlane (visplane_t *pl, void (*mapfunc)(int y, int x1)) if (b2 > t2) { - clearbufshort (spanend+t2, b2-t2, x); + fillshort (spanend+t2, b2-t2, x); } for (--x; x >= pl->left; --x) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index efc894fc29..c24e7f7190 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -531,7 +531,7 @@ clearfog: } else { - clearbufshort(openings + ds->sprtopclip - ds->x1 + x1, x2 - x1, viewheight); + fillshort(openings + ds->sprtopclip - ds->x1 + x1, x2 - x1, viewheight); } } return; @@ -1881,8 +1881,8 @@ void R_RenderSegLoop () call_wallscan(x1, x2, walltop, wallbottom, swall, lwall, yscale, false); } } - clearbufshort (ceilingclip+x1, x2-x1, viewheight); - clearbufshort (floorclip+x1, x2-x1, 0xffff); + fillshort (ceilingclip+x1, x2-x1, viewheight); + fillshort (floorclip+x1, x2-x1, 0xffff); } else { // two sided line @@ -2405,7 +2405,7 @@ void R_StoreWallRange (int start, int stop) { ds_p->sprtopclip = R_NewOpening (stop - start); ds_p->sprbottomclip = R_NewOpening (stop - start); - clearbufshort (openings + ds_p->sprtopclip, stop-start, viewheight); + fillshort (openings + ds_p->sprtopclip, stop-start, viewheight); memset (openings + ds_p->sprbottomclip, -1, (stop-start)*sizeof(short)); ds_p->silhouette = SIL_BOTH; } @@ -2445,7 +2445,7 @@ void R_StoreWallRange (int start, int stop) if (doorclosed || (rw_backfz1 >= rw_frontcz1 && rw_backfz2 >= rw_frontcz2)) { // killough 1/17/98, 2/8/98 ds_p->sprtopclip = R_NewOpening (stop - start); - clearbufshort (openings + ds_p->sprtopclip, stop - start, viewheight); + fillshort (openings + ds_p->sprtopclip, stop - start, viewheight); ds_p->silhouette |= SIL_TOP; } } @@ -2666,7 +2666,7 @@ int WallMostAny(short *mostbuf, double z1, double z2, const FWallCoords *wallc) } else if (y1 > viewheight && y2 > viewheight) // entire line is below screen { - clearbufshort(&mostbuf[wallc->sx1], wallc->sx2 - wallc->sx1, viewheight); + fillshort(&mostbuf[wallc->sx1], wallc->sx2 - wallc->sx1, viewheight); return 12; } diff --git a/src/r_things.cpp b/src/r_things.cpp index f5c75f012d..0a9d74c204 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2481,11 +2481,11 @@ void R_DrawSprite (vissprite_t *spr) // for R_DrawVisVoxel(). if (x1 > 0) { - clearbufshort(cliptop, x1, viewheight); + fillshort(cliptop, x1, viewheight); } if (x2 < viewwidth - 1) { - clearbufshort(cliptop + x2, viewwidth - x2, viewheight); + fillshort(cliptop + x2, viewwidth - x2, viewheight); } int minvoxely = spr->gzt <= hzt ? 0 : xs_RoundToInt((spr->gzt - hzt) / spr->yscale); int maxvoxely = spr->gzb > hzb ? INT_MAX : xs_RoundToInt((spr->gzt - hzb) / spr->yscale); diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 5c10406bf4..a56c63998a 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -236,13 +236,13 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) if (bottomclipper[0] != parms.dclip) { - clearbufshort(bottomclipper, screen->GetWidth(), (short)parms.dclip); + fillshort(bottomclipper, screen->GetWidth(), (short)parms.dclip); } if (parms.uclip != 0) { if (topclipper[0] != parms.uclip) { - clearbufshort(topclipper, screen->GetWidth(), (short)parms.uclip); + fillshort(topclipper, screen->GetWidth(), (short)parms.uclip); } mceilingclip = topclipper; }