From owner-svn-src-all@freebsd.org Wed Jan 15 19:53:04 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AACEF1FB9C1; Wed, 15 Jan 2020 19:53:04 +0000 (UTC) (envelope-from luporl@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47ydKX44Qvz3QkK; Wed, 15 Jan 2020 19:53:04 +0000 (UTC) (envelope-from luporl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 86C74BD94; Wed, 15 Jan 2020 19:53:04 +0000 (UTC) (envelope-from luporl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00FJr4CU012989; Wed, 15 Jan 2020 19:53:04 GMT (envelope-from luporl@FreeBSD.org) Received: (from luporl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00FJr3LM012985; Wed, 15 Jan 2020 19:53:03 GMT (envelope-from luporl@FreeBSD.org) Message-Id: <202001151953.00FJr3LM012985@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: luporl set sender to luporl@FreeBSD.org using -f From: Leandro Lupori Date: Wed, 15 Jan 2020 19:53:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356766 - in head/lib/libc: powerpc64/string string X-SVN-Group: head X-SVN-Commit-Author: luporl X-SVN-Commit-Paths: in head/lib/libc: powerpc64/string string X-SVN-Commit-Revision: 356766 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jan 2020 19:53:04 -0000 Author: luporl Date: Wed Jan 15 19:53:03 2020 New Revision: 356766 URL: https://svnweb.freebsd.org/changeset/base/356766 Log: [PPC64] strncpy optimization Assembly optimization of strncpy for PowerPC64, using double words instead of bytes to copy strings. Submitted by: Leonardo Bianconi (original version) Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D15369 Added: head/lib/libc/powerpc64/string/strncpy.c (contents, props changed) head/lib/libc/powerpc64/string/strncpy_arch_2_05.S (contents, props changed) head/lib/libc/powerpc64/string/strncpy_resolver.c (contents, props changed) Modified: head/lib/libc/powerpc64/string/Makefile.inc head/lib/libc/string/strncpy.c Modified: head/lib/libc/powerpc64/string/Makefile.inc ============================================================================== --- head/lib/libc/powerpc64/string/Makefile.inc Wed Jan 15 19:46:01 2020 (r356765) +++ head/lib/libc/powerpc64/string/Makefile.inc Wed Jan 15 19:53:03 2020 (r356766) @@ -3,4 +3,7 @@ MDSRCS+= \ strcpy_arch_2_05.S \ strcpy.c \ - strcpy_resolver.c + strcpy_resolver.c \ + strncpy_arch_2_05.S \ + strncpy.c \ + strncpy_resolver.c Added: head/lib/libc/powerpc64/string/strncpy.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/powerpc64/string/strncpy.c Wed Jan 15 19:53:03 2020 (r356766) @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2019 Leandro Lupori + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include +__FBSDID("$FreeBSD$"); + +#define WEAK_STRNCPY +#include "../../string/strncpy.c" Added: head/lib/libc/powerpc64/string/strncpy_arch_2_05.S ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/powerpc64/string/strncpy_arch_2_05.S Wed Jan 15 19:53:03 2020 (r356766) @@ -0,0 +1,131 @@ +/*- + * Copyright (c) 2018 Instituto de Pesquisas Eldorado + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +ENTRY(__strncpy_arch_2_05) + stdu %r1,-40(%r1) + mflr %r0 + std %r0,16(%r1) + std %r3,32(%r1) + + xor %r6,%r6,%r6 /* fixed 0 reg */ + +/* align loop */ + addi %r3,%r3,-1 +.Lalign_loop: + /* len? */ + cmpdi %r5,0 + beq .Lexit + /* aligned? */ + andi. %r0,%r4,7 + beq .Ldw_copy + /* copy */ + lbz %r7,0(%r4) + stbu %r7,1(%r3) + addi %r4,%r4,1 + addi %r5,%r5,-1 + /* zero? */ + cmpdi %r7,0 + beq .Lzero + b .Lalign_loop + +/* dword copy loop */ +.Ldw_copy: + /* prepare src and dst to use load/store and update */ + addi %r3,%r3,-7 + addi %r4,%r4,-8 +.Ldw_copy_loop: + cmpdi %r5,8 + blt .Lbyte_copy + + ldu %r0,8(%r4) + /* check for 0 */ + cmpb %r7,%r0,%r6 + cmpdi %r7,0 + bne .Lbyte_copy_and_zero + /* copy to dst */ + stdu %r0,8(%r3) + addi %r5,%r5,-8 + b .Ldw_copy_loop + +/* Copy remaining src bytes, zero-out buffer + * Note: r5 will be >= 8 + */ +.Lbyte_copy_and_zero: + addi %r3,%r3,7 + addi %r4,%r4,-1 +.Lbyte_copy_and_zero_loop: + lbzu %r7,1(%r4) + stbu %r7,1(%r3) + addi %r5,%r5,-1 + cmpdi %r7,0 + beq .Lzero + b .Lbyte_copy_and_zero_loop + +/* zero-out remaining dst bytes */ +.Lzero: + addi %r3,%r3,1 + li %r4,0 + /* r5 has len already */ + bl memset + nop + b .Lexit + +/* copy remaining (< 8) bytes */ +.Lbyte_copy: + cmpdi %r5,0 + beq .Lexit + addi %r3,%r3,7 + addi %r4,%r4,7 + mtctr %r5 +.Lbyte_copy_loop: + lbzu %r7,1(%r4) + stbu %r7,1(%r3) + cmpdi %r7,0 + /* 0 found: zero out remaining bytes */ + beq .Lbyte_copy_zero + bdnz .Lbyte_copy_loop + b .Lexit +.Lbyte_copy_zero_loop: + stbu %r6,1(%r3) +.Lbyte_copy_zero: + bdnz .Lbyte_copy_zero_loop + +.Lexit: + /* epilogue */ + ld %r3,32(%r1) + ld %r0,16(%r1) + mtlr %r0 + addi %r1,%r1,40 + blr + +END(__strncpy_arch_2_05) + + .section .note.GNU-stack,"",%progbits Added: head/lib/libc/powerpc64/string/strncpy_resolver.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/powerpc64/string/strncpy_resolver.c Wed Jan 15 19:53:03 2020 (r356766) @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2019 Leandro Lupori + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +char * +__strncpy_arch_2_05(char * restrict dst, const char * restrict src, size_t len); + +char * +__strncpy(char * restrict dst, const char * restrict src, size_t len); + +DEFINE_UIFUNC(, char *, strncpy, + (char * restrict, const char * restrict, size_t)) +{ + if (cpu_features & PPC_FEATURE_ARCH_2_05) + return (__strncpy_arch_2_05); + else + return (__strncpy); +} Modified: head/lib/libc/string/strncpy.c ============================================================================== --- head/lib/libc/string/strncpy.c Wed Jan 15 19:46:01 2020 (r356765) +++ head/lib/libc/string/strncpy.c Wed Jan 15 19:53:03 2020 (r356766) @@ -44,8 +44,17 @@ __FBSDID("$FreeBSD$"); * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. */ +#ifdef WEAK_STRNCPY +__weak_reference(__strncpy, strncpy); +#endif + char * -strncpy(char * __restrict dst, const char * __restrict src, size_t n) +#ifdef WEAK_STRNCPY +__strncpy +#else +strncpy +#endif +(char * __restrict dst, const char * __restrict src, size_t n) { if (n != 0) { char *d = dst;