Messages in this thread | | | From | Denis Vlasenko <> | Subject | Re: Improving string.h memcp()y implementation | Date | Mon, 4 Nov 2002 14:51:24 -0200 |
| |
On 4 November 2002 14:29, Denis Vlasenko wrote: > static inline void * > vda_memcpy3(void * to, const void * from, size_t n) > { > int d0, d1, d2; > __asm__ __volatile__( > " rep; movsl\n" > " movl %4, %%ecx\n" > " rep; movsb\n" > > : "=&c" (d0), "=&D" (d1), "=&S" (d2) > : "0" (n/4), "g" (n&3), "1" ((long) to), "2" ((long) > : from) "memory" > > ); > return (to); > } ...... > void f5() { vda_memcpy3(to,from,sz); } ...... > Disassembly of section ff5: > > 00000000 <f5>: > 0: 8b 0d 00 00 00 00 mov 0x0,%ecx > 6: 57 push %edi > 7: 89 c8 mov %ecx,%eax > 9: 56 push %esi > a: 8b 3d 00 00 00 00 mov 0x0,%edi > 10: 8b 35 00 00 00 00 mov 0x0,%esi > 16: 83 e0 03 and $0x3,%eax > 19: c1 e9 02 shr $0x2,%ecx > 1c: f3 a5 repz movsl %ds:(%esi),%es:(%edi) > 1e: 89 c1 mov %eax,%ecx > 20: f3 a4 repz movsb %ds:(%esi),%es:(%edi) > 22: 5e pop %esi > 23: 5f pop %edi > 24: c3 ret > > I think I shall not look there for a while ;) > Please somebody stop me... ;) ;)
...before it will be too late:
static inline void * vda_memcpy3(void * to, const void * from, size_t n) { int d0, d1, d2; __asm__ __volatile__( " andb $3, %b4\n" // we can save here a byte if %4 == eax " rep; movsl\n" " movb %b4, %%cl\n" " rep; movsb\n" : "=&c" (d0), "=&D" (d1), "=&S" (d2) : "0" (n/4), "g" (n), "1" ((long) to), "2" ((long) from) : "memory" ); return (to); }
Disassembly of section ff5:
00000000 <f5>: 0: a1 00 00 00 00 mov 0x0,%eax 5: 57 push %edi 6: 89 c1 mov %eax,%ecx 8: 56 push %esi 9: 8b 3d 00 00 00 00 mov 0x0,%edi f: 8b 35 00 00 00 00 mov 0x0,%esi 15: c1 e9 02 shr $0x2,%ecx 18: 24 03 and $0x3,%al 1a: f3 a5 repz movsl %ds:(%esi),%es:(%edi) 1c: 88 c1 mov %al,%cl 1e: f3 a4 repz movsb %ds:(%esi),%es:(%edi) 20: 5e pop %esi 21: 5f pop %edi 22: c3 ret
;)))
-- vda - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |