From nobody Tue Mar 29 12:41:06 2022 X-Original-To: dev-commits-src-all@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 A45D01A4C144; Tue, 29 Mar 2022 12:41:07 +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 4KSTh308lsz4pmt; Tue, 29 Mar 2022 12:41:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648557667; 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=icnADsi+Z5A4/p3QhiMbDM6d/1QagGjxfaGvZyUpMaQ=; b=SYpQJSKW++hGw5YS2mkPH6cHulVLQh/7Wv+S2mOPTjBrdXB6PDt6yjcCbUXQ1QEFWBqxZn YmSlJTwu5QaHsFkzu35UBz2/Ns6AY7Q2CRCm3ToY412SQpgMwfF+xX35NRGeFJ/FvRauUa YXAVoU3aSkuaDzWiz8UqHOjgcDdiCjdmI1uvblukJYcYd1MGpRCttfJnv9S1gXI58KKG2g +BMdgWVpBOCfnOcKJ617kyMxp72USs+QA1BcPfO5NXXDWFQNefkJpLSnrBLO67wgIzKRua 9z73RARHqwj2QLJR4jXeFKnnEdiBQK7miVqC/g99a3Dy7E/KFvHvEfG0CnGMxw== 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 B51CA1E777; Tue, 29 Mar 2022 12:41:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22TCf6n4009287; Tue, 29 Mar 2022 12:41:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22TCf6x6009286; Tue, 29 Mar 2022 12:41:06 GMT (envelope-from git) Date: Tue, 29 Mar 2022 12:41:06 GMT Message-Id: <202203291241.22TCf6x6009286@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 1544cd332b96 - releng/13.1 - amd64: bring back asm bcmp, shared with memcmp List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.1 X-Git-Reftype: branch X-Git-Commit: 1544cd332b9635a4a3c1821d895c3ad40bc630f9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648557667; 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=icnADsi+Z5A4/p3QhiMbDM6d/1QagGjxfaGvZyUpMaQ=; b=ZZXFm4ORNQ0mlgyMZbmUNEE8Pgtfd4W288u3Vt5QBU1ZlbmNm7yLGdcIcePZ/miRNHNgP6 YEOFcPQXlfZcUdYdzg1++V5LveM2k3H9w6E2zoY1IY0MSSUdhHJxu9dHsZXGzbICGRVriX YOOh/tWf50tyMg2EugQJQ+A0pZFPeJPExPJGTlWPei/zZm0zfwuYfA/Md/8Hztlfa2GzTF rwdR3MjUz7X/DSB2MTks3UXJRoLpRCWWf7OF20GUdh7dGBBNR2YRd4AcCnSl4BDihJhfve Nsxbl//3Cg3Zyji9AaB7QBzp7TjX6LVq59/sNU0VntSuOS0PzsPqFlUMTPLpjg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648557667; a=rsa-sha256; cv=none; b=yZwf3/VuA5Mvq6zSUAOpEJe97L47pq+Hb7JdqiCQ/43bE9kxisoRqht9cpxvY/GyC5y/WX MY2+evl9Zl+r3jNHm/pPf7d6vzTFzBJd4BdsIQj61kRa3Oa0GFkC3eUs3EKCDeIMNEBpAC bv9L+HKMA/0QZjJbY1Dp0hX5pn337mDlQaORFykRROYp+p7GfjOPGTd6+i5esI+L341IiR GoXttH7ceCZxiIUPTWvn9RjQ/XfvPVbiVbBCIIH2bwMgQnuO29TvOnSFtFOKZQvQHtwbda k9ZFxn3RcyGgoNnB7OMrSOmzHoxNeTOzxO7GBA8baOq5w+cbQb1JAGjxBXfUkw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=1544cd332b9635a4a3c1821d895c3ad40bc630f9 commit 1544cd332b9635a4a3c1821d895c3ad40bc630f9 Author: Mateusz Guzik AuthorDate: 2022-03-25 15:04:04 +0000 Commit: Mateusz Guzik CommitDate: 2022-03-29 12:40:32 +0000 amd64: bring back asm bcmp, shared with memcmp Turns out clang converts "memcmp(foo, bar, len) == 0" and similar to bcmp calls. Reviewed by: emaste (previous version), jhb (previous version) Differential Revision: https://reviews.freebsd.org/D34673 Approved by: re (gjb) (cherry picked from commit fbc002cb72d2d9bb435cce99630d5d7da9f59390) (cherry picked from commit c5890784f6d315c501586b39cf8c0c80b609be5b) --- lib/libc/amd64/string/bcmp.S | 122 ++--------------------------------------- lib/libc/amd64/string/memcmp.S | 26 ++++++++- 2 files changed, 28 insertions(+), 120 deletions(-) diff --git a/lib/libc/amd64/string/bcmp.S b/lib/libc/amd64/string/bcmp.S index efdc6d33e4dd..f7a4603f6c5a 100644 --- a/lib/libc/amd64/string/bcmp.S +++ b/lib/libc/amd64/string/bcmp.S @@ -1,121 +1,7 @@ /*- - * Copyright (c) 2018 The FreeBSD Foundation - * - * This software was developed by Mateusz Guzik - * under sponsorship from the FreeBSD Foundation. - * - * 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. - * - * 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. - * - * $FreeBSD$ + * Written by Mateusz Guzik + * Public domain. */ -#include -__FBSDID("$FreeBSD$"); - -ENTRY(bcmp) - cmpq $16,%rdx - jae 5f -1: - testq %rdx,%rdx - je 3f - xorl %ecx,%ecx -2: - movzbl (%rdi,%rcx,1),%eax - movzbl (%rsi,%rcx,1),%r8d - cmpb %r8b,%al - jne 4f - addq $1,%rcx - cmpq %rcx,%rdx - jz 3f - movzbl (%rdi,%rcx,1),%eax - movzbl (%rsi,%rcx,1),%r8d - cmpb %r8b,%al - jne 4f - addq $1,%rcx - cmpq %rcx,%rdx - jz 3f - movzbl (%rdi,%rcx,1),%eax - movzbl (%rsi,%rcx,1),%r8d - cmpb %r8b,%al - jne 4f - addq $1,%rcx - cmpq %rcx,%rdx - jz 3f - movzbl (%rdi,%rcx,1),%eax - movzbl (%rsi,%rcx,1),%r8d - cmpb %r8b,%al - jne 4f - addq $1,%rcx - cmpq %rcx,%rdx - jne 2b -3: - xorl %eax,%eax - ret -4: - movl $1,%eax - ret -5: - cmpq $32,%rdx - jae 7f -6: - /* - * 8 bytes - */ - movq (%rdi),%r8 - movq (%rsi),%r9 - cmpq %r8,%r9 - jne 4b - leaq 8(%rdi),%rdi - leaq 8(%rsi),%rsi - subq $8,%rdx - cmpq $8,%rdx - jae 6b - jl 1b - jmp 3b -7: - /* - * 32 bytes - */ - movq (%rsi),%r8 - movq 8(%rsi),%r9 - subq (%rdi),%r8 - subq 8(%rdi),%r9 - or %r8,%r9 - jnz 4b - - movq 16(%rsi),%r8 - movq 24(%rsi),%r9 - subq 16(%rdi),%r8 - subq 24(%rdi),%r9 - or %r8,%r9 - jnz 4b - - leaq 32(%rdi),%rdi - leaq 32(%rsi),%rsi - subq $32,%rdx - cmpq $32,%rdx - jae 7b - jnz 1b - jmp 3b -END(bcmp) - - .section .note.GNU-stack,"",%progbits +#define BCMP +#include "memcmp.S" diff --git a/lib/libc/amd64/string/memcmp.S b/lib/libc/amd64/string/memcmp.S index 0c8121f9d885..3e6df7966312 100644 --- a/lib/libc/amd64/string/memcmp.S +++ b/lib/libc/amd64/string/memcmp.S @@ -39,7 +39,11 @@ __FBSDID("$FreeBSD$"); #define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ +#ifdef BCMP +ENTRY(bcmp) +#else ENTRY(memcmp) +#endif xorl %eax,%eax 10: cmpq $16,%rdx @@ -143,8 +147,25 @@ ENTRY(memcmp) /* * Mismatch was found. - * - * Before we compute it we narrow down the range (16 -> 8 -> 4 bytes). + */ +#ifdef BCMP + ALIGN_TEXT +10320016: +10320000: +10081608: +10163224: +10163216: +10163208: +10040804: +80: +1: + leal 1(%eax),%eax + ret +END(bcmp) +#else +/* + * We need to compute the difference between strings. + * Start with narrowing the range down (16 -> 8 -> 4 bytes). */ ALIGN_TEXT 10320016: @@ -214,5 +235,6 @@ ENTRY(memcmp) subl %r8d,%eax ret END(memcmp) +#endif .section .note.GNU-stack,"",%progbits