Forum Discussion
Altera_Forum
Honored Contributor
9 years agoIn your project settings, change the optimization level from "None" to -O3. Your software might break, or it might be fine.
Your code boils down to:
void IINCHIP_WRITE(uint32 addr, uint16 data) {
(*((vuint16*) addr)) = data;
}
uint32 wiz_write_buf(SOCKET s, uint8* buf, uint32 len) {
uint32 idx = 0;
// M_08082008
IINCHIP_CRITICAL_SECTION_ENTER();
for (idx = 0; idx < len; idx += 2)
IINCHIP_WRITE(Sn_TX_FIFOR(s), *((uint16*) (buf + idx)));
// M_08082008
IINCHIP_CRITICAL_SECTION_EXIT();
}
The compiler can do some improvements by itself when you have enabled the optimizer, but as an example, changing to a macro and using the 'register' keyword probably will bring some improvement:
#define IINCHIP_WRITE(addr, data) ((*((vuint16*) addr)) = data)
uint32 wiz_write_buf(SOCKET s, uint8* buf, uint32 len) {
register uint32 idx = 0;
register uint32 fifo_addr = Sn_TX_FIFOR(s);
// M_08082008
IINCHIP_CRITICAL_SECTION_ENTER();
for (idx = 0; idx < len; idx += 2)
IINCHIP_WRITE(fifo_addr, *((uint16*) (buf + idx)));
// M_08082008
IINCHIP_CRITICAL_SECTION_EXIT();
}
The simple above edits eliminated 2 x 16 = 32 function call overheads from your loop. The math in the loop also isn't great, but deal with the function calls first.