di2569.txt ;************************************************************************************************** ; LISTING 1 - FUNCTION-ACCELERATION CODE FOR C16x MICROCONTROLLERS ; ; "Speed C functions for C16x Microcontrollers," EDN, Aug 3, 2000, pg 130 ; ; http://www.ednmag.com/ednmag/reg/2000/08032000/designideas.htm#16di6 ;*************************************************************************************************** void far * fast_memset ( void far *pvDest, UCHAR ucVal, UINT uiSize ) { UINT uiVal; UINT far *p; if ( uiSize ) /* ignore function call if count is 0 */ { p = pvDest; /* keep a copy of the pointer */ uiVal = ((UINT) ucVal << 8) + ucVal; /* create a word to fill the memory */ if ( _pof ( p ) & 1 ) /* if the start address is odd */ { *(UCHAR far*)p = ucVal; /* write a byte to the start address */ p = (UINT far*) ((UCHAR far*) p + 1); /* move pointer to next even address */ --uiSize; /* count one byte written*/ } USR0 = uiSize & 1; /* USR0 = 1 if remaining count is odd */ uiSize >>=1; /* convert remaining byte count to word count */ while ( uiSize ) /* write to all words */ { *p = uiVal; /* write a word */ p += 1; /* point to the next word */ --uiSize; /* decrement the word counter */ } if ( USR0 ) /* if one byte is left*/ { *(UCHAR far*)p = ucVal; /* write to the last byte */ } } return ( pvDest ); /* return the pointer to start of memory area */ }