Changeset 2b17f47 in mainline for kernel/arch/amd64/include/memstr.h
- Timestamp:
- 2008-06-02T20:54:30Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0e6461d
- Parents:
- 3d6c468
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/include/memstr.h
r3d6c468 r2b17f47 36 36 #define KERN_amd64_MEMSTR_H_ 37 37 38 /** Copy memory 39 * 40 * Copy a given number of bytes (3rd argument) 41 * from the memory location defined by 2nd argument 42 * to the memory location defined by 1st argument. 43 * The memory areas cannot overlap. 44 * 45 * @param dst Destination 46 * @param src Source 47 * @param cnt Number of bytes 48 * @return Destination 49 */ 50 static inline void * memcpy(void * dst, const void * src, size_t cnt) 51 { 52 unative_t d0, d1, d2; 38 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt)) 53 39 54 asm volatile( 55 "rep movsq\n\t" 56 "movq %4, %%rcx\n\t" 57 "andq $7, %%rcx\n\t" 58 "jz 1f\n\t" 59 "rep movsb\n\t" 60 "1:\n" 61 : "=&c" (d0), "=&D" (d1), "=&S" (d2) 62 : "0" ((unative_t)(cnt / 8)), "g" ((unative_t)cnt), "1" ((unative_t) dst), "2" ((unative_t) src) 63 : "memory"); 40 extern void memsetw(uintptr_t dst, size_t cnt, uint16_t x); 41 extern void memsetb(uintptr_t dst, size_t cnt, uint8_t x); 64 42 65 return dst; 66 } 67 68 69 /** Compare memory regions for equality 70 * 71 * Compare a given number of bytes (3rd argument) 72 * at memory locations defined by 1st and 2nd argument 73 * for equality. If bytes are equal function returns 0. 74 * 75 * @param src Region 1 76 * @param dst Region 2 77 * @param cnt Number of bytes 78 * @return Zero if bytes are equal, non-zero otherwise 79 */ 80 static inline int memcmp(const void * src, const void * dst, size_t cnt) 81 { 82 unative_t d0, d1, d2; 83 unative_t ret; 84 85 asm ( 86 "repe cmpsb\n\t" 87 "je 1f\n\t" 88 "movq %3, %0\n\t" 89 "addq $1, %0\n\t" 90 "1:\n" 91 : "=a" (ret), "=&S" (d0), "=&D" (d1), "=&c" (d2) 92 : "0" (0), "1" (src), "2" (dst), "3" ((unative_t)cnt) 93 ); 94 95 return ret; 96 } 97 98 /** Fill memory with words 99 * Fill a given number of words (2nd argument) 100 * at memory defined by 1st argument with the 101 * word value defined by 3rd argument. 102 * 103 * @param dst Destination 104 * @param cnt Number of words 105 * @param x Value to fill 106 */ 107 static inline void memsetw(uintptr_t dst, size_t cnt, uint16_t x) 108 { 109 unative_t d0, d1; 110 111 asm volatile ( 112 "rep stosw\n\t" 113 : "=&D" (d0), "=&c" (d1), "=&a" (x) 114 : "0" (dst), "1" ((unative_t)cnt), "2" (x) 115 : "memory" 116 ); 117 118 } 119 120 /** Fill memory with bytes 121 * Fill a given number of bytes (2nd argument) 122 * at memory defined by 1st argument with the 123 * word value defined by 3rd argument. 124 * 125 * @param dst Destination 126 * @param cnt Number of bytes 127 * @param x Value to fill 128 */ 129 static inline void memsetb(uintptr_t dst, size_t cnt, uint8_t x) 130 { 131 unative_t d0, d1; 132 133 asm volatile ( 134 "rep stosb\n\t" 135 : "=&D" (d0), "=&c" (d1), "=&a" (x) 136 : "0" (dst), "1" ((unative_t)cnt), "2" (x) 137 : "memory" 138 ); 139 140 } 43 extern int memcmp(uintptr_t src, uintptr_t dst, int cnt); 141 44 142 45 #endif
Note:
See TracChangeset
for help on using the changeset viewer.