Changeset 11 for trunk/kernel/libk/memcpy.c
- Timestamp:
- Apr 26, 2017, 2:29:23 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/memcpy.c
r1 r11 23 23 24 24 #include <hal_types.h> 25 #include <printk.h> 25 26 26 27 ///////////////////////////////// … … 32 33 const uint32_t * wsrc = src; 33 34 35 // word per word copy if both addresses aligned 34 36 if (!((uint32_t) wdst & 3) && !((uint32_t) wsrc & 3) ) 35 37 { … … 44 46 unsigned char *csrc = (unsigned char*)wsrc; 45 47 48 // byte per byte for last bytes (or not aligned) 46 49 while (size--) 47 50 { … … 51 54 } 52 55 53 /////////////////////////// 54 void * memset( void * dst,55 int s,56 uint32_t size)56 ////////////////////////////// 57 void * memset( void * dst, 58 uint32_t val, 59 uint32_t size) 57 60 { 58 char * a = (char *) dst; 59 while (size--) 61 // build 8 bits and 32 bits values 62 uint8_t byte = (uint8_t)(val & 0xFF); 63 uint32_t word = (val<<24) | (val<<16) | (val<<8) | val; 64 65 // word per word if address aligned 66 uint32_t * wdst = (uint32_t *)dst; 67 68 if( (((uint32_t)dst) & 0x3) == 0 ) 60 69 { 61 *a++ = (char)s; 70 while( size > 3 ) 71 { 72 *wdst++ = word; 73 size -= 4; 74 } 62 75 } 76 77 // byte per byte for last bytes (or not aligned) 78 char * cdst = (char *)wdst; 79 80 while( size-- ) 81 { 82 *cdst++ = byte; 83 } 84 63 85 return dst; 64 86 }
Note: See TracChangeset
for help on using the changeset viewer.