do some more tiny optimizations

-those can all be declared with restrict
-our ternary clamp macro is slightly faster than std::clamp
This commit is contained in:
Alug committed 2025-06-26 12:46:53 +02:00
1 parent 7e2a9abfda
commit 05ed340e0e
2 files changed
+21 -21

No files matched your search

+11 -11
View File
@@ -31,7 +31,7 @@ enum DrawColumnType
};
template<DrawColumnType Type>
static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 *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<DrawColumnType Type>
static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 *dest, UINT8 col, const UINT8 *colormap)
static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT8 col, const UINT8 * __restrict colormap)
{
col = R_GetColumnTranslated<Type>(dc, col, colormap);
@@ -57,7 +57,7 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 *dest,
}
template<DrawColumnType Type>
static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 *dest, UINT32 bit, const UINT8 *source, const 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];
@@ -182,18 +182,18 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc)
//
// killough 2/1/98: more performance tuning
fixed_t frac;
intptr_t frac;
const intptr_t fracstep = dc->iscale;
const intptr_t heightmask = dc->sourcelength-1;
static const INT32 npow2min = -1;
constexpr INT32 npow2min = -1;
const INT32 npow2max = dc->sourcelength;
const INT32 stride = vid.width;
const UINT8 *source = dc->source;
const lighttable_t *colormap = dc->colormap;
const UINT8 * __restrict source = dc->source;
const lighttable_t * __restrict colormap = dc->colormap;
// Framebuffer destination address.
UINT8 *dest = R_Address(dc->x, dc->yl);
UINT8 * __restrict dest = R_Address(dc->x, dc->yl);
count++;
@@ -275,7 +275,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc)
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
*dest = R_DrawColumnPixel<Type>(dc, dest, std::clamp((frac >> FRACBITS), npow2min, npow2max), source, colormap);
*dest = R_DrawColumnPixel<Type>(dc, dest, CLAMP((frac >> FRACBITS), npow2min, npow2max), source, colormap);
dest += stride;
@@ -325,7 +325,7 @@ DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_HOLES|DC_TRANSMAP)
void R_DrawFogColumn(drawcolumndata_t* dc)
{
INT32 count;
UINT8 *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 *colormap = dc->colormap;
const lighttable_t * __restrict colormap = dc->colormap;
// Determine scaling, which is the only mapping to be done.
do
+10 -10
View File
@@ -76,10 +76,10 @@ static void R_DrawSpanTemplate(drawspandata_t* ds)
UINT32 xstep, ystep;
UINT32 bit;
UINT8 *dest = R_Address(ds->x1, ds->y);
UINT8 *dsrc;
UINT8 * __restrict dest = R_Address(ds->x1, ds->y);
UINT8 * __restrict dsrc;
const UINT8 *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 *source = ds->source;
const UINT8 *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 *dest = R_Address(ds->x1, ds->y);
UINT8 *dsrc;
UINT8 * __restrict dest = R_Address(ds->x1, ds->y);
UINT8 * __restrict dsrc;
float startz, startu, startv;
float izstep, uzstep, vzstep;
@@ -362,8 +362,8 @@ DEFINE_SPAN_COMBO(R_DrawTranslucentWaterSpan, DS_TRANSMAP|DS_RIPPLE)
*/
void R_DrawFogSpan(drawspandata_t* ds)
{
const UINT8 *colormap = ds->colormap;
UINT8 *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,7 +389,7 @@ 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 *dest;
UINT8 * __restrict dest;
dest = R_Address(ds->x1, ds->y);
const INT32 stride = vid.width;