Why does linux use one byte accesses in memset?
Posted: Mon Aug 04, 2014 8:15 am
recently, I knew linux kernel source use "memset by one-byte"
following is that source...( linux kernel version - 2.6.32.63 , lib/string.c )
above is very slow in my own kernel... so I use following source
why linux kernel source use that slow memset source??
following is that source...( linux kernel version - 2.6.32.63 , lib/string.c )
Code: Select all
void *memset(void *s, int c, size_t count)
{
char *xs = s;
while (count--)
*xs++ = c;
return s;
}
Code: Select all
void kMemSet( void* pvDestination, BYTE bData, int iSize )
{
int i;
QWORD qwData;
int iRemainByteStartOffset;
qwData = 0;
for( i = 0 ; i < 8 ; i++ )
{
qwData = ( qwData << 8 ) | bData;
}
for( i = 0 ; i < ( iSize / 8 ) ; i++ )
{
( ( QWORD* ) pvDestination )[ i ] = qwData;
}
iRemainByteStartOffset = i * 8;
for( i = 0 ; i < ( iSize % 8 ) ; i++ )
{
( ( char* ) pvDestination )[ iRemainByteStartOffset++ ] = bData;
}
}