From nobody Tue Mar 29 10:25:34 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 CA9A31A51B76; Tue, 29 Mar 2022 10:25:34 +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 4KSQgf5KnSz3vtX; Tue, 29 Mar 2022 10:25:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648549534; 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=EvP49ekTKNw6eyQ3XENZnXgK9oS69M5iM4dAYQQSJuU=; b=sJJuQ4foXZmGT8NXR0eTba5iez8G2fh2LcU52DLxv63VBsQjSXZEH4RoQ1C0yYw59is5F6 +0AabhlPIa3PRL3qeTPONSWF0lB9XIUJ4xxSikluKKuHPd5lXtsv6yJ0Fm6Amq1aRkR1A0 d2mQL4Zet7lYZHXyKtpsiq0dUzH1/gDQiX0Kjhy/LDJSqDlf2poja47E2pZc1f3JbbLpJC rKivmKFUTdzDZSOEuBG+i2q0CZPXAbS7aQv4qLylE6tM8OrWiYSsFX+YG9dJ+O9tlOSvFI u+yxXjRiIXwFEQ8DjrUYcfETf5e17KqBq61n+UKUi/hqSYLtCnEMitF6eYFknA== 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 936851CF0B; Tue, 29 Mar 2022 10:25:34 +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 22TAPY4w024991; Tue, 29 Mar 2022 10:25:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22TAPY12024990; Tue, 29 Mar 2022 10:25:34 GMT (envelope-from git) Date: Tue, 29 Mar 2022 10:25:34 GMT Message-Id: <202203291025.22TAPY12024990@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: c5890784f6d3 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: c5890784f6d315c501586b39cf8c0c80b609be5b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648549534; 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=EvP49ekTKNw6eyQ3XENZnXgK9oS69M5iM4dAYQQSJuU=; b=EB8/SxKdwqT9vs2tqOoAgED2QPGUZAJdmMED9KTTvRogRZVAC8g4FIL0uYB7N41XmvCMvY Rg8KWGBC8+aMy8QBzap7gp1gRC5UMdLVnMwaxXajb+BjnvuyiJRcNvhleDCuww0dCrYtcf j3wr6Uo6MwwHRrgUTgckHoeBDznAOLGw8tG8FbY1HZpCg7nO8AzJI90MEcu4d5gO4H3nfC LozWiFAbt0Qtj7ujc0J2yxDeIHQ+6Pp5Xs48nQDfLq3jDShWSEV+avqBZxQXpfc3tixrk3 EhNBt9ODiiJbMet9pCrotOK5jO2LSDWmceBG+pIt4iT/c8CFcmg35OpXA6/4ZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648549534; a=rsa-sha256; cv=none; b=ku/4+GhXVrooNCXrlubO6q4ysQcvdtMxEBm0z9K2G/02iRkhKuGErM4GbzERZF3ckr1SoC +JB51BFSywgSMZEpdwj1T2B79bJDqjAOvpBPSjCrnvayk4vHu6U0neg7jfu+5f990JNnNY 0Wt+i3UOktzMbEp01OL8u28KFx2P9Vpoxgftf9TbGp+LzjhgFAcN7OAUkGlQTwosE8hLt3 3039ZaoskGaooQtoh2SbDjILWsSOPhFaNhfsMF40Ovu63hXv1AnU3ZKgGpCRYHiKYTjQ4e 0PoDdnyHnGLX5EGm+MRPUAM2V+k52kGfVTgaFfJ792H0WdrXNHRzfBJBV+lNGw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=c5890784f6d315c501586b39cf8c0c80b609be5b commit c5890784f6d315c501586b39cf8c0c80b609be5b Author: Mateusz Guzik AuthorDate: 2022-03-25 15:04:04 +0000 Commit: Mateusz Guzik CommitDate: 2022-03-29 10:25:17 +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 (cherry picked from commit fbc002cb72d2d9bb435cce99630d5d7da9f59390) --- 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