VOGONS


size optimization

Topic actions

First post, by ih8registrations

User metadata
Rank Oldbie
Rank
Oldbie

Awhile back I did some speed optimization to dma, which wd responded "yeah, but cache thrashing," so I started playing with size optimization. What I've done is check the .o sizes, using getdmachannel as an example; its object code should be the same size as resides in memory/cache.

Checked the sizes of empty method, original, 1st & 2nd path, & optimizations. Note, I have other changes in dma.cpp so the base size will be different if you test this yourself.

DmaChannel * GetDMAChannel(Bit8u chan) {
// LOG_MSG("getdmachannel");
/*
if (chan<4) {
// channel on first DMA controller
// if (DmaControllers[0]) return DmaControllers[0]->GetChannel(chan);
} else if (chan<8) {
// channel on second DMA controller
if (DmaControllers[1]) return DmaControllers[1]->GetChannel(chan-4);
}

return NULL;
*/
if (chan<8) {
bool ctrlr = chan >= 4;
if (DmaControllers[ctrlr]) {
chan -= ctrlr << 2;
return DmaControllers[ctrlr]->GetChannel(chan);
}
}
return NULL;
}

// core 2 duo cache line size = 64 bytes
// size of dma.o:
// 190,987 bytes empty method // commented out whole function
// 191,523 bytes original method = 536 bytes, 8.375 cache lines
// 191,241 bytes first path // commented out else if (chan<8) { .. }
// 191,377 bytes second path // commented out if (DmaControllers[0]) .. under if (chan<4)
// 191,269 bytes optimized // 282 bytes, 4.40625 cache lines

Optimized code uses +1 cl first path, -3 cl 2nd path.

For overall size, the obvious was getting rid of the second getchannel call.
Less obvious was setting ctrl by test condition vs an if, and setting ctrlr
and chan in their used scope instead of outside at the start of the method.