Date: Wed, 16 Dec 2009 14:19:53 GMT From: Maxim Zakharov <maxime@maxime.net.ru> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/141682: Fester version of stncpy function Message-ID: <200912161419.nBGEJr7T029073@www.freebsd.org> Resent-Message-ID: <200912161420.nBGEK1mG066838@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 141682 >Category: misc >Synopsis: Fester version of stncpy function >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Dec 16 14:20:01 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Maxim Zakharov >Release: 7.1-BETA2 >Organization: >Environment: FreeBSD max.maxime.net.ru 7.1-BETA2 FreeBSD 7.1-BETA2 #0: Mon Oct 13 04:23:28 UTC 2008 root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 >Description: I would like to propose a faster version of strncpy function (/usr/src/lib/libc/string/strncpy.c). It's about 30% faster on aligned data, and about two times faster on unaligned data on modern pipelined processors (Intel Duo E8400 3MHz in particular). >How-To-Repeat: >Fix: void * dps_strncpy(char *dst0, char *src0, size_t length) { if (length) { register size_t n = (length + 7) / 8; register size_t r = (length % 8); register char *dst = dst0, *src = src0; if (r == 0) r = 8; if (!(dst[0] = src[0])) return dst0; if (r > 1) { if (!(dst[1] = src[1])) return dst0; if (r > 2) { if (!(dst[2] = src[2])) return dst0; if (r > 3) { if (!(dst[3] = src[3])) return dst0; if (r > 4) { if (!(dst[4] = src[4])) return dst0; if (r > 5) { if (!(dst[5] = src[5])) return dst0; if (r > 6) { if (!(dst[6] = src[6])) return dst0; if (r > 7) { if (!(dst[7] = src[7])) return dst0; }}}}}}} src += r; dst += r; while (--n > 0) { if (!(dst[0] = src[0])) break; if (!(dst[1] = src[1])) break; if (!(dst[2] = src[2])) break; if (!(dst[3] = src[3])) break; if (!(dst[4] = src[4])) break; if (!(dst[5] = src[5])) break; if (!(dst[6] = src[6])) break; if (!(dst[7] = src[7])) break; src += 8; dst += 8; } if (dst < dst0 + length) *dst = '\0'; } return dst0; } >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912161419.nBGEJr7T029073>