>the stack works quite well and it's efficient. Where else do you want to put them?
Arent variables normally allocated on the heap?
I am tuning some code to run fast on a TI c6416 dsp. I have a problem with thrashing of one of my dynamic arrays, and I want to make sure that this array is read into a different cache-line than the arrays that might be thrashing it.
I am not sure this code will make any sense in regards to the cache problems but here it goes:
Code:
static void jpc_qmfb1d_split(jpc_fix_t *startptr, int startind, int endind,
register int step, jpc_fix_t *lstartptr, int lstartind, int lendind,
jpc_fix_t *hstartptr, int hstartind, int hendind)
{
const int bufsize = JPC_CEILDIVPOW2(endind - startind, 2);
#if !defined(HAVE_VLA)
#define QMFB_SPLITBUFSIZE 4096
jpc_fix_t *splitbuf=(jpc_fix_t*)malloc(sizeof(jpc_fix_t)*QMFB_SPLITBUFSIZE);
#else
jpc_fix_t *splitbuf=(jpc_fix_t*)malloc(sizeof(jpc_fix_t)*bufsize);
#endif
jpc_fix_t *buf;
int llen;
int hlen;
int twostep;
jpc_fix_t *tmpptr;
register jpc_fix_t *ptr;
register jpc_fix_t *hptr;
register jpc_fix_t *lptr;
register int n;
int state;
buf = splitbuf;
twostep = step << 1;
llen = lendind - lstartind;
hlen = hendind - hstartind;
#if !defined(HAVE_VLA)
if (bufsize > QMFB_SPLITBUFSIZE) { //esbn: ..SIZE=4096.
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
abort();
}
}
#endif
state = 0;
ptr = startptr;
lptr = lstartptr;
tmpptr = buf;
n = llen;
#pragma MUST_ITERATE(2,,);
while (n-- > 0) {
if (state) {
*tmpptr = *lptr;
++tmpptr;
}
*lptr = *ptr;
ptr += twostep;
lptr += step;
state ^= 1;
}
ptr = &startptr[((((llen + hlen) >> 1) << 1) - 1) * step];
hptr = &hstartptr[(hlen - 1) * step];
n = hlen - (tmpptr - buf);
#pragma MUST_ITERATE(2,,);
while (n-- > 0) {
*hptr = *ptr;
ptr -= twostep;
hptr -= step;
}
n = tmpptr - buf;
#pragma MUST_ITERATE(2,,);
while (n-- > 0) {
--tmpptr;
*hptr = *tmpptr;
hptr -= step;
}
#if !defined(HAVE_VLA)
/* If the split buffer was allocated on the heap, free this memory. */
if (buf != splitbuf) {
jas_free(buf);
}
#endif
}
My problem is with the 'tmpptr', which points 'buf', whick points to 'splitbuf'. I would like to control the allocation of this 'splitbuf' to avoid thrashing...
Hope this made some sense...
Esben.