Changeset e353e85 in mainline for kernel/generic/src/lib/memstr.c
- Timestamp:
- 2011-04-01T11:59:10Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9b640c42
- Parents:
- cd1e6b62 (diff), 27bdfa5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/lib/memstr.c
rcd1e6b62 re353e85 28 28 */ 29 29 30 /** @addtogroup generic 30 /** @addtogroup generic 31 31 * @{ 32 32 */ … … 34 34 /** 35 35 * @file 36 * @brief 36 * @brief Memory string operations. 37 37 * 38 * This file provides architecture independent functions to manipulate blocks of 39 * memory. These functions are optimized as much as generic functions of this 40 * type can be. However, architectures are free to provide even more optimized 41 * versions of these functions. 38 * This file provides architecture independent functions to manipulate blocks 39 * of memory. These functions are optimized as much as generic functions of 40 * this type can be. 42 41 */ 43 42 44 43 #include <memstr.h> 45 44 #include <typedefs.h> 46 #include <align.h>47 45 48 /** Copyblock of memory.46 /** Fill block of memory. 49 47 * 50 * Copy cnt bytes from src address to dst address. The copying is done 51 * word-by-word and then byte-by-byte. The source and destination memory areas 52 * cannot overlap. 48 * Fill cnt bytes at dst address with the value val. 53 49 * 54 * @param src Source address to copy from.55 * @param dst Destination address to copy to.56 * @param cnt Number of bytes to copy.50 * @param dst Destination address to fill. 51 * @param cnt Number of bytes to fill. 52 * @param val Value to fill. 57 53 * 58 * @return Destination address.59 54 */ 60 void *_memcpy(void *dst, const void *src, size_t cnt)55 void memsetb(void *dst, size_t cnt, uint8_t val) 61 56 { 62 unsigned int i, j; 57 memset(dst, val, cnt); 58 } 59 60 /** Fill block of memory. 61 * 62 * Fill cnt words at dst address with the value val. The filling 63 * is done word-by-word. 64 * 65 * @param dst Destination address to fill. 66 * @param cnt Number of words to fill. 67 * @param val Value to fill. 68 * 69 */ 70 void memsetw(void *dst, size_t cnt, uint16_t val) 71 { 72 size_t i; 73 uint16_t *ptr = (uint16_t *) dst; 63 74 64 if (ALIGN_UP((uintptr_t) src, sizeof(sysarg_t)) != (uintptr_t) src || 65 ALIGN_UP((uintptr_t) dst, sizeof(sysarg_t)) != (uintptr_t) dst) { 66 for (i = 0; i < cnt; i++) 67 ((uint8_t *) dst)[i] = ((uint8_t *) src)[i]; 68 } else { 69 for (i = 0; i < cnt / sizeof(sysarg_t); i++) 70 ((sysarg_t *) dst)[i] = ((sysarg_t *) src)[i]; 71 72 for (j = 0; j < cnt % sizeof(sysarg_t); j++) 73 ((uint8_t *)(((sysarg_t *) dst) + i))[j] = 74 ((uint8_t *)(((sysarg_t *) src) + i))[j]; 75 } 76 77 return (char *) dst; 75 for (i = 0; i < cnt; i++) 76 ptr[i] = val; 78 77 } 79 78 80 79 /** Move memory block with possible overlapping. 81 80 * 82 * Copy cnt bytes from src address to dst address. The source and destination83 * memory areas may overlap.81 * Copy cnt bytes from src address to dst address. The source 82 * and destination memory areas may overlap. 84 83 * 85 * @param src Source address to copy from.86 * @param dst Destination address to copy to.87 * @param cnt 84 * @param dst Destination address to copy to. 85 * @param src Source address to copy from. 86 * @param cnt Number of bytes to copy. 88 87 * 89 * @return Destination address. 88 * @return Destination address. 89 * 90 90 */ 91 void *memmove(void *dst, const void *src, size_t n)91 void *memmove(void *dst, const void *src, size_t cnt) 92 92 { 93 const uint8_t *sp;94 uint8_t *dp;95 96 93 /* Nothing to do? */ 97 94 if (src == dst) 98 95 return dst; 99 96 100 97 /* Non-overlapping? */ 101 if (dst >= src + n || src >= dst + n) { 102 return memcpy(dst, src, n); 103 } 104 98 if ((dst >= src + cnt) || (src >= dst + cnt)) 99 return memcpy(dst, src, cnt); 100 101 uint8_t *dp; 102 const uint8_t *sp; 103 105 104 /* Which direction? */ 106 105 if (src > dst) { 107 106 /* Forwards. */ 107 dp = dst; 108 108 sp = src; 109 dp = dst; 110 111 while (n-- != 0) 109 110 while (cnt-- != 0) 112 111 *dp++ = *sp++; 113 112 } else { 114 113 /* Backwards. */ 115 sp = src + (n- 1);116 dp = dst + (n- 1);117 118 while ( n-- != 0)114 dp = dst + (cnt - 1); 115 sp = src + (cnt - 1); 116 117 while (cnt-- != 0) 119 118 *dp-- = *sp--; 120 119 } 121 120 122 121 return dst; 123 }124 125 /** Fill block of memory126 *127 * Fill cnt bytes at dst address with the value x. The filling is done128 * byte-by-byte.129 *130 * @param dst Destination address to fill.131 * @param cnt Number of bytes to fill.132 * @param x Value to fill.133 *134 */135 void _memsetb(void *dst, size_t cnt, uint8_t x)136 {137 unsigned int i;138 uint8_t *p = (uint8_t *) dst;139 140 for (i = 0; i < cnt; i++)141 p[i] = x;142 }143 144 /** Fill block of memory.145 *146 * Fill cnt words at dst address with the value x. The filling is done147 * word-by-word.148 *149 * @param dst Destination address to fill.150 * @param cnt Number of words to fill.151 * @param x Value to fill.152 *153 */154 void _memsetw(void *dst, size_t cnt, uint16_t x)155 {156 unsigned int i;157 uint16_t *p = (uint16_t *) dst;158 159 for (i = 0; i < cnt; i++)160 p[i] = x;161 122 } 162 123
Note:
See TracChangeset
for help on using the changeset viewer.