mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
constify various cache1d and pragmas functions, some copybuf* -> memcpy/move.
The following functions have const qualifiers attached for the 'destination' arguments: kdfwrite, dfwrite in cache1d.c and copybuf{byte,reverse,} in the pragmas source or headers. A couple uses of the latter ones were replaced with calls to standard library functions. git-svn-id: https://svn.eduke32.com/eduke32@2361 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
b51a3d91a3
commit
103a6e76f9
6 changed files with 55 additions and 39 deletions
|
@ -62,8 +62,8 @@ CACHE1D_FIND_REC *klistpath(const char *path, const char *mask, int32_t type);
|
|||
|
||||
int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil);
|
||||
int32_t dfread(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil);
|
||||
void kdfwrite(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil);
|
||||
void dfwrite(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil);
|
||||
void kdfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil);
|
||||
void dfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ static inline int32_t divscale(int32_t eax, int32_t ebx, int32_t ecx) { return d
|
|||
// maybe one day I'll make these into macros
|
||||
int32_t boundmulscale(int32_t a, int32_t b, int32_t c);
|
||||
void clearbufbyte(void *D, int32_t c, int32_t a);
|
||||
void copybufbyte(void *S, void *D, int32_t c);
|
||||
void copybufreverse(void *S, void *D, int32_t c);
|
||||
void copybufbyte(const void *S, void *D, int32_t c);
|
||||
void copybufreverse(const void *S, void *D, int32_t c);
|
||||
|
||||
|
||||
#ifdef NO_GCC_BUILTINS
|
||||
|
@ -964,7 +964,7 @@ void copybufreverse(void *S, void *D, int32_t c);
|
|||
: "=&D" (__D), "=&c" (__c) : "0" (__D), "1" (__c), "a" (__a) : "memory", "cc"); \
|
||||
0; })
|
||||
#define copybuf(S,D,c) \
|
||||
({ void *__S=(S), *__D=(D); int32_t __c=(c); \
|
||||
({ const void *__S=(S), *__D=(D); int32_t __c=(c); \
|
||||
__asm__ __volatile__ ("rep; movsl" \
|
||||
: "=&S" (__S), "=&D" (__D), "=&c" (__c) : "0" (__S), "1" (__D), "2" (__c) : "memory", "cc"); \
|
||||
0; })
|
||||
|
@ -1442,7 +1442,7 @@ static __inline void clearbufbyte(void *d, int32_t c, int32_t a)
|
|||
}
|
||||
}
|
||||
|
||||
static __inline void copybuf(void *s, void *d, int32_t c)
|
||||
static __inline void copybuf(const void *s, void *d, int32_t c)
|
||||
{
|
||||
_asm {
|
||||
mov esi, s
|
||||
|
@ -1452,7 +1452,7 @@ static __inline void copybuf(void *s, void *d, int32_t c)
|
|||
}
|
||||
}
|
||||
|
||||
static __inline void copybufbyte(void *s, void *d, int32_t c)
|
||||
static __inline void copybufbyte(const void *s, void *d, int32_t c)
|
||||
{
|
||||
_asm {
|
||||
mov esi, s
|
||||
|
@ -1492,7 +1492,7 @@ static __inline void copybufbyte(void *s, void *d, int32_t c)
|
|||
}
|
||||
}
|
||||
|
||||
static __inline void copybufreverse(void *s, void *d, int32_t c)
|
||||
static __inline void copybufreverse(const void *s, void *d, int32_t c)
|
||||
{
|
||||
_asm {
|
||||
mov esi, s
|
||||
|
@ -1892,12 +1892,12 @@ void qinterpolatedown16 (intptr_t bufptr, int32_t num, int32_t val, int32_t add)
|
|||
void qinterpolatedown16short (intptr_t bufptr, int32_t num, int32_t val, int32_t add);
|
||||
|
||||
void clearbuf(void* d, int32_t c, int32_t a);
|
||||
void copybuf(void* s, void* d, int32_t c);
|
||||
void copybuf(const void* s, void* d, int32_t c);
|
||||
void swapbuf4(void* a, void* b, int32_t c);
|
||||
|
||||
void clearbufbyte(void *D, int32_t c, int32_t a);
|
||||
void copybufbyte(void *S, void *D, int32_t c);
|
||||
void copybufreverse(void *S, void *D, int32_t c);
|
||||
void copybufbyte(const void *S, void *D, int32_t c);
|
||||
void copybufreverse(const void *S, void *D, int32_t c);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -168,7 +168,8 @@ void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr)
|
|||
|
||||
//Remove all blocks except 1
|
||||
suckz -= (bestz+1); cacnum -= suckz;
|
||||
copybufbyte(&cac[bestz+suckz],&cac[bestz],(cacnum-bestz)*sizeof(cactype));
|
||||
// copybufbyte(&cac[bestz+suckz],&cac[bestz],(cacnum-bestz)*sizeof(cactype));
|
||||
Bmemmove(&cac[bestz], &cac[bestz+suckz], (cacnum-bestz)*sizeof(cactype));
|
||||
cac[bestz].hand = newhandle; *newhandle = cachestart+(intptr_t)besto;
|
||||
cac[bestz].leng = newbytes;
|
||||
cac[bestz].lock = newlockptr;
|
||||
|
@ -213,12 +214,16 @@ void suckcache(intptr_t *suckptr)
|
|||
if ((i > 0) && (*cac[i-1].lock == 0))
|
||||
{
|
||||
cac[i-1].leng += cac[i].leng;
|
||||
cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); // XXX: this looks suspicious, copybuf already multiplies by 4...
|
||||
cacnum--;
|
||||
//copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); // this looks suspicious, copybuf already multiplies by 4...
|
||||
Bmemmove(&cac[i], &cac[i+1], (cacnum-i)*sizeof(cactype));
|
||||
}
|
||||
else if ((i < cacnum-1) && (*cac[i+1].lock == 0))
|
||||
{
|
||||
cac[i+1].leng += cac[i].leng;
|
||||
cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); // XXX: see above
|
||||
cacnum--;
|
||||
//copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); // see above
|
||||
Bmemmove(&cac[i], &cac[i+1], (cacnum-i)*sizeof(cactype));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1166,8 +1171,8 @@ failure:
|
|||
static char *lzwbuf1, *lzwbuf4, *lzwbuf5, lzwbuflock[5];
|
||||
static int16_t *lzwbuf2, *lzwbuf3;
|
||||
|
||||
static int32_t lzwcompress(char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf);
|
||||
static int32_t lzwuncompress(char *lzwinbuf, int32_t compleng, char *lzwoutbuf);
|
||||
static int32_t lzwcompress(const char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf);
|
||||
static int32_t lzwuncompress(const char *lzwinbuf, int32_t compleng, char *lzwoutbuf);
|
||||
|
||||
int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
|
||||
{
|
||||
|
@ -1247,11 +1252,11 @@ int32_t dfread(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil)
|
|||
return count;
|
||||
}
|
||||
|
||||
void kdfwrite(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
|
||||
void kdfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
|
||||
{
|
||||
uint32_t i, j, k;
|
||||
int16_t leng, swleng;
|
||||
char *ptr;
|
||||
const char *ptr;
|
||||
|
||||
lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200;
|
||||
if (lzwbuf1 == NULL) allocache((intptr_t *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
|
||||
|
@ -1261,7 +1266,7 @@ void kdfwrite(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
|
|||
if (lzwbuf5 == NULL) allocache((intptr_t *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
|
||||
|
||||
if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; }
|
||||
ptr = (char *)buffer;
|
||||
ptr = buffer;
|
||||
|
||||
copybufbyte(ptr,lzwbuf4,(int32_t)dasizeof);
|
||||
k = dasizeof;
|
||||
|
@ -1291,11 +1296,11 @@ void kdfwrite(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
|
|||
lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 1;
|
||||
}
|
||||
|
||||
void dfwrite(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil)
|
||||
void dfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil)
|
||||
{
|
||||
uint32_t i, j, k;
|
||||
int16_t leng, swleng;
|
||||
char *ptr;
|
||||
const char *ptr;
|
||||
|
||||
lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200;
|
||||
if (lzwbuf1 == NULL) allocache((intptr_t *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
|
||||
|
@ -1305,7 +1310,7 @@ void dfwrite(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil)
|
|||
if (lzwbuf5 == NULL) allocache((intptr_t *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
|
||||
|
||||
if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; }
|
||||
ptr = (char *)buffer;
|
||||
ptr = buffer;
|
||||
|
||||
copybufbyte(ptr,lzwbuf4,(int32_t)dasizeof);
|
||||
k = dasizeof;
|
||||
|
@ -1335,7 +1340,7 @@ void dfwrite(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil)
|
|||
lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 1;
|
||||
}
|
||||
|
||||
static int32_t lzwcompress(char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf)
|
||||
static int32_t lzwcompress(const char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf)
|
||||
{
|
||||
int32_t i, addr, newaddr, addrcnt, zx, *intptr;
|
||||
int32_t bytecnt1, bitcnt, numbits, oneupnumbits;
|
||||
|
@ -1399,13 +1404,14 @@ static int32_t lzwcompress(char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf)
|
|||
return(uncompleng+4);
|
||||
}
|
||||
|
||||
static int32_t lzwuncompress(char *lzwinbuf, int32_t compleng, char *lzwoutbuf)
|
||||
static int32_t lzwuncompress(const char *lzwinbuf, int32_t compleng, char *lzwoutbuf)
|
||||
{
|
||||
int32_t strtot, currstr, numbits, oneupnumbits;
|
||||
int32_t i, dat, leng, bitcnt, outbytecnt, *intptr;
|
||||
int16_t *shortptr;
|
||||
int32_t i, dat, leng, bitcnt, outbytecnt;
|
||||
const int32_t *intptr;
|
||||
const int16_t *shortptr;
|
||||
|
||||
shortptr = (int16_t *)lzwinbuf;
|
||||
shortptr = (const int16_t *)lzwinbuf;
|
||||
strtot = (int32_t)B_LITTLE16(shortptr[1]);
|
||||
if (strtot == 0)
|
||||
{
|
||||
|
@ -1417,7 +1423,7 @@ static int32_t lzwuncompress(char *lzwinbuf, int32_t compleng, char *lzwoutbuf)
|
|||
numbits = 8; oneupnumbits = (1<<8);
|
||||
do
|
||||
{
|
||||
intptr = (int32_t *)&lzwinbuf[bitcnt>>3];
|
||||
intptr = (const int32_t *)&lzwinbuf[bitcnt>>3];
|
||||
dat = ((B_LITTLE32(intptr[0])>>(bitcnt&7)) & (oneupnumbits-1));
|
||||
bitcnt += numbits;
|
||||
if ((dat&((oneupnumbits>>1)-1)) > ((currstr-1)&((oneupnumbits>>1)-1)))
|
||||
|
|
|
@ -3445,7 +3445,9 @@ static inline void polymer_scansprites(int16_t sectnum, spritetype* localtsprit
|
|||
(spr->xrepeat > 0) && (spr->yrepeat > 0) &&
|
||||
(*localspritesortcnt < MAXSPRITESONSCREEN))
|
||||
{
|
||||
copybufbyte(spr,&localtsprite[*localspritesortcnt],sizeof(spritetype));
|
||||
// this function's localtsprite is either the tsprite global or
|
||||
// polymer_drawroom's locattsprite, so no aliasing
|
||||
Bmemcpy(&localtsprite[*localspritesortcnt], spr, sizeof(spritetype));
|
||||
localtsprite[(*localspritesortcnt)++].owner = i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ void clearbufbyte(void *D, int32_t c, int32_t a)
|
|||
);
|
||||
}
|
||||
|
||||
void copybufbyte(void *S, void *D, int32_t c)
|
||||
void copybufbyte(const void *S, void *D, int32_t c)
|
||||
{
|
||||
ASM(
|
||||
"cmpl $4, %%ecx\n\t" // cmp ecx, 4
|
||||
|
@ -129,7 +129,7 @@ void copybufbyte(void *S, void *D, int32_t c)
|
|||
);
|
||||
}
|
||||
|
||||
void copybufreverse(void *S, void *D, int32_t c)
|
||||
void copybufreverse(const void *S, void *D, int32_t c)
|
||||
{
|
||||
ASM(
|
||||
"shrl $1, %%ecx\n\t"
|
||||
|
@ -191,13 +191,16 @@ void qinterpolatedown16short(intptr_t bufptr, int32_t num, int32_t val, int32_t
|
|||
|
||||
void clearbuf(void *d, int32_t c, int32_t a)
|
||||
{
|
||||
int32_t *p = (int32_t *)d;
|
||||
int32_t *p = d;
|
||||
|
||||
while ((c--) > 0) *(p++) = a;
|
||||
}
|
||||
|
||||
void copybuf(void *s, void *d, int32_t c)
|
||||
void copybuf(const void *s, void *d, int32_t c)
|
||||
{
|
||||
int32_t *p = (int32_t *)s, *q = (int32_t *)d;
|
||||
const int32_t *p = s;
|
||||
int32_t *q = (int32_t *)d;
|
||||
|
||||
while ((c--) > 0) *(q++) = *(p++);
|
||||
}
|
||||
|
||||
|
@ -228,15 +231,19 @@ void clearbufbyte(void *D, int32_t c, int32_t a)
|
|||
}
|
||||
}
|
||||
|
||||
void copybufbyte(void *S, void *D, int32_t c)
|
||||
void copybufbyte(const void *S, void *D, int32_t c)
|
||||
{
|
||||
char *p = (char *)S, *q = (char *)D;
|
||||
const char *p = S;
|
||||
char *q = D;
|
||||
|
||||
while ((c--) > 0) *(q++) = *(p++);
|
||||
}
|
||||
|
||||
void copybufreverse(void *S, void *D, int32_t c)
|
||||
void copybufreverse(const void *S, void *D, int32_t c)
|
||||
{
|
||||
char *p = (char *)S, *q = (char *)D;
|
||||
const char *p = S;
|
||||
char *q = D;
|
||||
|
||||
while ((c--) > 0) *(q++) = *(p--);
|
||||
}
|
||||
|
||||
|
|
|
@ -10734,7 +10734,8 @@ int32_t G_DoMoveThings(void)
|
|||
randomseed = ticrandomseed;
|
||||
|
||||
TRAVERSE_CONNECT(i)
|
||||
copybufbyte(&inputfifo[(g_netServer && myconnectindex == i) ? 1 : 0][i],g_player[i].sync,sizeof(input_t));
|
||||
Bmemcpy(g_player[i].sync, &inputfifo[(g_netServer && myconnectindex == i) ? 1 : 0][i],
|
||||
sizeof(input_t));
|
||||
|
||||
G_UpdateInterpolations();
|
||||
|
||||
|
|
Loading…
Reference in a new issue