From 7807f67ef5f7520d73845bb00dc9dfef8d25c85c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 08:25:34 +0200 Subject: [PATCH] "restrict" macro for c++ since it does not have it, use __restrict instead --- src/doomdef.h | 8 ++++++++ src/m_emotes.cpp | 1 - src/r_draw_column.cpp | 16 ++++++++-------- src/r_draw_span.cpp | 24 ++++++++++++------------ src/r_main.h | 2 +- src/r_plane.cpp | 10 +++++----- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index abc96951f..c28a76a97 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -555,6 +555,14 @@ UINT32 quickncasehash (const char *p, size_t n) #define UNLIKELY(x) (x) #endif +#ifdef __cplusplus +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + #define restrict __restrict +#else + #define restrict +#endif +#endif + // An assert-type mechanism. #ifdef PARANOIA #define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__)) diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index 9cfb1b953..90c7e22f3 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -11,7 +11,6 @@ extern "C" { #include "hu_stuff.h" // Goddammit -#define restrict #include "v_video.h" } diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index bc91ef0d3..dcc1a5b90 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -31,7 +31,7 @@ enum DrawColumnType }; template -static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * __restrict colormap) +static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) { if constexpr (Type & DrawColumnType::DC_COLORMAP) { @@ -42,7 +42,7 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co } template -static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT8 col, const UINT8 * __restrict colormap) +static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * restrict dest, UINT8 col, const UINT8 * restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); @@ -57,7 +57,7 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __re } template -static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT32 bit, const __restrict UINT8 *source, const __restrict UINT8 *colormap) +static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const restrict UINT8 *source, const restrict UINT8 *colormap) { UINT8 col = source[bit]; @@ -189,11 +189,11 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) const INT32 npow2max = dc->sourcelength; const INT32 stride = vid.width; - const UINT8 * __restrict source = dc->source; - const lighttable_t * __restrict colormap = dc->colormap; + const UINT8 * restrict source = dc->source; + const lighttable_t * restrict colormap = dc->colormap; // Framebuffer destination address. - UINT8 * __restrict dest = R_Address(dc->x, dc->yl); + UINT8 * restrict dest = R_Address(dc->x, dc->yl); count++; @@ -325,7 +325,7 @@ DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_HOLES|DC_TRANSMAP) void R_DrawFogColumn(drawcolumndata_t* dc) { INT32 count; - UINT8 * __restrict dest; + UINT8 * restrict dest; count = dc->yh - dc->yl; @@ -344,7 +344,7 @@ void R_DrawFogColumn(drawcolumndata_t* dc) dest = R_Address(dc->x, dc->yl); const INT32 stride = vid.width; - const lighttable_t * __restrict colormap = dc->colormap; + const lighttable_t * restrict colormap = dc->colormap; // Determine scaling, which is the only mapping to be done. do diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 8ea30a80a..eeda8b431 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -76,10 +76,10 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) UINT32 xstep, ystep; UINT32 bit; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); - UINT8 * __restrict dsrc; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); + UINT8 * restrict dsrc; - const UINT8 * __restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; + const UINT8 * restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; if (dest+8 > deststop) { @@ -92,8 +92,8 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) xposition = ds->xfrac; yposition = ds->yfrac; xstep = ds->xstep; ystep = ds->ystep; - const UINT8 * __restrict source = ds->source; - const UINT8 * __restrict colormap = ds->colormap; + const UINT8 * restrict source = ds->source; + const UINT8 * restrict colormap = ds->colormap; if constexpr (Type & DS_RIPPLE) { @@ -190,8 +190,8 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) UINT32 u, v; int i; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); - UINT8 * __restrict dsrc; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); + UINT8 * restrict dsrc; float startz, startu, startv; float izstep, uzstep, vzstep; @@ -204,7 +204,7 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) const INT32 nflatyshift = ds->nflatyshift; const INT32 nflatmask = ds->nflatmask; const INT32 stride = vid.width; - INT32 * __restrict tiltlighting = tiltlight.get(); + INT32 * restrict tiltlighting = tiltlight.get(); iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); @@ -362,8 +362,8 @@ DEFINE_SPAN_COMBO(R_DrawTranslucentWaterSpan, DS_TRANSMAP|DS_RIPPLE) */ void R_DrawFogSpan(drawspandata_t* ds) { - const UINT8 * __restrict colormap = ds->colormap; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); + const UINT8 * restrict colormap = ds->colormap; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); intptr_t count = ds->x2 - ds->x1 + 1; @@ -389,11 +389,11 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) { int width = ds->x2 - ds->x1; float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); - UINT8 * __restrict dest; + UINT8 * restrict dest; dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; - INT32 * __restrict tiltlighting = tiltlight.get(); + INT32 * restrict tiltlighting = tiltlight.get(); // Lighting is simple. It's just linear interpolation from start to end { diff --git a/src/r_main.h b/src/r_main.h index 409570c77..f6d03fddf 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -88,7 +88,7 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // // killough 5/2/98: reformatted // -FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * __restrict node) +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * restrict node) { if (!node->dx) return x <= node->x ? node->dy > 0 : node->dy < 0; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 54a0f04da..c52771bc4 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -100,7 +100,7 @@ static void R_ReallocPlaneBounds(visplane_t *pl) { pl->top_memory = static_cast(Z_Realloc(pl->top_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL)); pl->bottom_memory = static_cast(Z_Realloc(pl->bottom_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL)); - pl->top = pl->top_memory + 1; + pl->top = pl->top_memory + 1; pl->bottom = pl->bottom_memory + 1; } @@ -203,14 +203,14 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 if (!R_CheckMapPlane(__func__, y, x1, x2)) return; - angle = (ds->currentplane->viewangle + ds->currentplane->plangle)>>ANGLETOFINESHIFT; + angle = (ds->currentplane->viewangle + ds->currentplane->plangle)>>ANGLETOFINESHIFT; planecos = FINECOSINE(angle); planesin = FINESINE(angle); // [RH] Notice that I dumped the caching scheme used by Doom. // It did not offer any appreciable speedup. distance = FixedMul(ds->planeheight, yslope[y]); - span = abs(centery - y); + span = abs(centery - y); if (span) // don't divide by zero { @@ -259,7 +259,7 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 if (ds->currentplane->extra_colormap) ds->colormap = ds->currentplane->extra_colormap->colormap + (ds->colormap - colormaps); - ds->y = y; + ds->y = y; ds->x1 = x1; ds->x2 = x2; @@ -301,7 +301,7 @@ static void R_MapTiltedPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, ds->colormap += COLORMAP_REMAPOFFSET; } - ds->y = y; + ds->y = y; ds->x1 = x1; ds->x2 = x2;