From 0116b51b2d28484b472e83ba0668225e6f55611a Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 23 Jul 2018 02:55:46 +0000 Subject: [PATCH] softsurface: Perform a "divisor known at compile time" optimization git-svn-id: https://svn.eduke32.com/eduke32@6947 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/src/softsurface.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/build/src/softsurface.cpp b/source/build/src/softsurface.cpp index fdb96f73b..825f98967 100644 --- a/source/build/src/softsurface.cpp +++ b/source/build/src/softsurface.cpp @@ -24,7 +24,8 @@ static uint32_t pPal[256]; // lookup table to find the source position within a scanline static uint16_t* scanPosLookupTable; -static uint32_t roundUp(uint32_t num, uint32_t multiple) +template +static uint32_t roundUp(uint32_t num) { return (num+multiple-1)/multiple * multiple; } @@ -59,7 +60,7 @@ bool softsurface_initialize(vec2_t bufferResolution, // allocate one continuous block of memory large enough to hold the buffer, the palette, // and the scanPosLookupTable while maintaining alignment for each - uint32_t bufferSize = roundUp(bufferRes.x * bufferRes.y, 16); + uint32_t bufferSize = roundUp<16>(bufferRes.x * bufferRes.y); buffer = (uint8_t*) Xaligned_alloc(16, bufferSize + sizeof(uint16_t)*destBufferRes.x); scanPosLookupTable = (uint16_t*) (buffer + bufferSize);