From nobody Mon Dec 25 14:25:51 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SzKvM5vDcz54nKf; Mon, 25 Dec 2023 14:25:51 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SzKvM4pLPz3Mhk; Mon, 25 Dec 2023 14:25:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703514351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=X10wquK/qdCNt6cD8Em2YCJCNm0ysgA7DTtCnvkoje4=; b=ZD5Yi0i6/APqlo9l9jbwygEt8qwHO7+e6BZ4cTjknQAXHl0U1gU6/tRvTjMr1aOW1h8hDf ISbGmCF7WzJfHfgleGrjeL/SeTyh7BIeUO6Yht+ku4xuqU6Ige19oK4LeCPj64rgo+miFp Aa92X/NaJRHUR+JCeu2f9ZEIQVdiO6LOnoI+FKZmhY+gllfqLXjcWzh7YuxYU9Do6qjXWP RdpqUDwLObcBRsuWe0kwIWlUCntY4B9ZHVdy8+cn8tDKn+k8Z6nN/3eEpq4fOAjjshq3Lx C5z/yx7rEr+LjYrFGhzI1DF+OnnV1VQLxeiu+Kf+/MB1grTZzxsAlt1wv2iKew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703514351; a=rsa-sha256; cv=none; b=Fbl7WjpNBmGB4lLZfnXyXgPAfofj1B7tW+16aq/khbHqN7b2EAVoAFEMUr1Toxq02d/N/+ 5okN7RizxVbKdaNplF2pUuElZ/ZTG/IuBI742P5RiQTskVDdHTkoJF275zFLYxC/YcTdud QteLXIjf44h0PdCj1jScN0IfailiLGhuSPAeFWVDEq4AFtJuDo1kK5ZhNVu9ORDOfjA1AZ CYdv/ziiDdi6bK7ynxRnFJgs0a4mrwacwQgqAzziL1t3Umvkaows1PwALlZA1NUU9M9YH7 KGBKZoRq0pgyF1436Eew3NxGwp5xRN5hBo4sNU79LrTBjmOQU/xN23jDr6Exug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703514351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=X10wquK/qdCNt6cD8Em2YCJCNm0ysgA7DTtCnvkoje4=; b=YvgTDW10tD/2X9PQowbRCSLs3EnR8XEgGKL2brewis9jDWWYYT57BcPL7GsQcdIlRCKY/+ 0bkx3FQcwETqMGTCfkhUwxbjPhy0wVwtOc87Qvf+jMgR9NdGZruWMENgU0BCu/jnrijfAa r5Af53OxudKdH4oF/3lLZzWk+6dcW1oNGG1X9FldA4ohI51pvj+FgDuTtimy9g3u0rQaZ4 qND3JRommt4umgHTQm0IaqcAxgcS1WGApKwH0hsfsv92KrwOuX1GJHcKcVhXG0L93HgZ0v zty4ov7EqqnL8EX95R6PSTsn5lV6uMotVROL9tL11GxnJnOk6NCdaV6neyLHxw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SzKvM3t96zJy; Mon, 25 Dec 2023 14:25:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BPEPpSj023419; Mon, 25 Dec 2023 14:25:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BPEPpkY023416; Mon, 25 Dec 2023 14:25:51 GMT (envelope-from git) Date: Mon, 25 Dec 2023 14:25:51 GMT Message-Id: <202312251425.3BPEPpkY023416@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Clausecker Subject: git: aff9143a242c - main - lib/libc/amd64/string/strcat.S: enable use of SIMD List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: aff9143a242c0012b0195b3666e03fa3b7cd33e8 Auto-Submitted: auto-generated The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=aff9143a242c0012b0195b3666e03fa3b7cd33e8 commit aff9143a242c0012b0195b3666e03fa3b7cd33e8 Author: Robert Clausecker AuthorDate: 2023-11-14 18:09:08 +0000 Commit: Robert Clausecker CommitDate: 2023-12-25 13:55:53 +0000 lib/libc/amd64/string/strcat.S: enable use of SIMD strcat has a bespoke scalar assembly implementation we inherited from NetBSD. While it performs well, it is better to call into our SIMD implementations if any SIMD features are available at all. So do that and implement strcat() by calling into strlen() and strcpy() if these are available. Sponsored by: The FreeBSD Foundation Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785 Differential Reviison: https://reviews.freebsd.org/D42600 --- lib/libc/amd64/string/strcat.S | 47 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/libc/amd64/string/strcat.S b/lib/libc/amd64/string/strcat.S index 0834408acfb7..081e98840cee 100644 --- a/lib/libc/amd64/string/strcat.S +++ b/lib/libc/amd64/string/strcat.S @@ -1,6 +1,14 @@ -/* - * Written by J.T. Conklin - * Public domain. +/*- + * Copyright (c) 2023, The FreeBSD Foundation + * + * SPDX-License-Expression: BSD-2-Clause + * + * Portions of this software were developed by Robert Clausecker + * under sponsorship from the FreeBSD Foundation. + * + * Adapted from NetBSD's common/lib/libc/arch/x86_64/string/strcat.S + * written by J.T. Conklin + * that was originally dedicated to the public domain */ #include @@ -8,7 +16,14 @@ RCSID("$NetBSD: strcat.S,v 1.4 2004/07/26 18:51:21 drochner Exp $") #endif -ENTRY(strcat) +#include "amd64_archlevel.h" + +ARCHFUNCS(strcat) + ARCHFUNC(strcat, scalar) + ARCHFUNC(strcat, baseline) +ENDARCHFUNCS(strcat) + +ARCHENTRY(strcat, scalar) movq %rdi,%rax movabsq $0x0101010101010101,%r8 movabsq $0x8080808080808080,%r9 @@ -161,6 +176,28 @@ ENTRY(strcat) .Ldone: ret -END(strcat) +ARCHEND(strcat, scalar) + +/* + * Call into strlen + strcpy if we have any SIMD at all. + * The scalar implementation above is better for the scalar + * case as it avoids the function call overhead, but pessimal + * if we could call SIMD routines instead. + */ +ARCHENTRY(strcat, baseline) + push %rbp + mov %rsp, %rbp + push %rsi + push %rbx + mov %rdi, %rbx # remember destination for later + call CNAME(strlen) # strlen(dest) + mov -8(%rbp), %rsi + lea (%rbx, %rax, 1), %rdi # dest + strlen(dest) + call CNAME(__stpcpy) # stpcpy(dest + strlen(dest), src) + mov %rbx, %rax # return dest + pop %rbx + leave + ret +ARCHEND(strcat, baseline) .section .note.GNU-stack,"",%progbits