From nobody Tue Sep 12 03:41:46 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 4Rl8XB5Tptz4tSYD; Tue, 12 Sep 2023 03:41:46 +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 4Rl8XB4h5Bz4Syg; Tue, 12 Sep 2023 03:41:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694490106; 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=R+8OJjgghTyTC0wT1cyZcwvwNeGj/FdiCLUlTTIuGwo=; b=aaZuJgyTl7NDDnTqolyDDhBst/xlC6xEOqOGdJgbpkycnjK8Lwu/ir/WG7p34ZfaF17q+p fqqSCBMiwE2Mo4D23WUgGe1bB7yARQpu33klByziSWDmFxvFxdm1mQub/uhKh8JXvDgiMN Lj56129PTDcxVmONOIXReJ0UVA7hUdUjMZcctXi1jMOoKFuFU5CEJF0zzP8CKNpWqzsM7U q6pNxYqtgQiRPhL3NIFETMJ1fHEhKaQUN3AM7dDG0uU9MIlrMVZ3EpkEhMiJHNkSDKO/1f fzGL+kWX1balme89Vh2AEPgmlF/Da4sZ/5NubZ+3PRB3XIllieFDrbHg0oGwKQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694490106; a=rsa-sha256; cv=none; b=u1bIV/+q7poBXkcrDW9hjAbeHfC11EQ/43K1LniKiWooohonoGFcPRmkucVlD3ANmI6app qV+jSnuLarmcWHQFQeI7V1uvjDoB+xF3Lb2L+9LWSQGjgGGdkib8LpPX+DgVyW6nfQhKTf A3R8BROcwPPfcS2vwap/k0bPbqFhHTjoBm4fC21YggsuyFmtPWd4KH+/HePYT6khI1mOrG Aau8hwsOYNkuDIhUh9oNOYE7wTx9mQZB6FilKUAZVu0lnLt2a585Svks4WRt0q9xqudyaC 0R/xUosH4IeWccu8O9YJimA8clReTtlAbx4XLg6ODxBkFuNHRjCawNYkh5mf8A== 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=1694490106; 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=R+8OJjgghTyTC0wT1cyZcwvwNeGj/FdiCLUlTTIuGwo=; b=ZwQCPQbhl6tOmJylmc4zfBcvgU7Ay5m5aX5lSLo/sAjLr1fNOozS+KBirZN68kZl2MQ4Q8 6kdueOQgjr01H3GL5XWosPLvruBmyLYNrTl/UAe9+/Es8qd4fY5BZR6T/2fQq6hyaCsQ1u oFOCpNunhxQHwJXqHmk8W2fvVqErjGfeDjamCJ5ygvKXDhR2ijqMWdKC9dOOFnrTS4NfkV VkXRtIXICi+KJZ9m/+r2HTvYCUxCIrbsy6b5QrH7RHJmcgZnjdiI/V5wDA8DozJucgZd4u DNxK0l+2ATE37P/xEq7DAPgtkRc55beFqYRzECChl/XhF/MzqZeqUFB2Kzg+jA== 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 4Rl8XB3n3Vz1kR; Tue, 12 Sep 2023 03:41:46 +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 38C3fkZ4070756; Tue, 12 Sep 2023 03:41:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38C3fkuE070753; Tue, 12 Sep 2023 03:41:46 GMT (envelope-from git) Date: Tue, 12 Sep 2023 03:41:46 GMT Message-Id: <202309120341.38C3fkuE070753@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: 52d4a4d4e0de - main - lib/libc/amd64/string/strcspn.S: fix behaviour with sets of 17--32 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: 52d4a4d4e0dedc72bc33082a3f84c2d0fd6f2cbb Auto-Submitted: auto-generated The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=52d4a4d4e0dedc72bc33082a3f84c2d0fd6f2cbb commit 52d4a4d4e0dedc72bc33082a3f84c2d0fd6f2cbb Author: Robert Clausecker AuthorDate: 2023-09-11 23:56:30 +0000 Commit: Robert Clausecker CommitDate: 2023-09-12 02:58:43 +0000 lib/libc/amd64/string/strcspn.S: fix behaviour with sets of 17--32 When a string is matched against a set of 17--32 characters, each chunk of the string is matched first against the first 16 characters of the set and then against the remaining characters. We also check at the same time if the string has a nul byte in the current chunk, terminating the search if it does. Due to misconceived logic, the order of checks was "first half of set, nul byte, second half of set", meaning that a match with the second half of the set was ignored when the string ended in the same 16 bytes. Reverse the order of checks to fix this problem. Sponsored by: The FreeBSD Foundation Approved by: mjg (blanket, via IRC) MFC after: 1 week MFC to: stable/14 --- lib/libc/amd64/string/strcspn.S | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/libc/amd64/string/strcspn.S b/lib/libc/amd64/string/strcspn.S index de409db6d472..53100eeea9a5 100644 --- a/lib/libc/amd64/string/strcspn.S +++ b/lib/libc/amd64/string/strcspn.S @@ -259,27 +259,32 @@ ARCHENTRY(strcspn, x86_64_v2) movdqu 48(%rsp, %rcx, 1), %xmm3 # second part of set /* set is 17--32 bytes in size */ - pcmpistri $0, %xmm0, %xmm2 # match in head? - jbe .Lheadmatchv2 - pcmpistri $0, %xmm0, %xmm3 # ZF=1 not possible here + pcmpistri $0, %xmm0, %xmm2 # match in first set half? jb .Lheadmatchv2 + pcmpistri $0, %xmm0, %xmm3 # match in second set half or end of string? + jbe .Lheadmatchv2 ALIGN_TEXT 0: movdqa (%rax), %xmm0 pcmpistri $0, %xmm0, %xmm2 - jbe 1b + jb 2f # match in first set half? pcmpistri $0, %xmm0, %xmm3 - jb 1f # ZF=1 not possible here + jbe 1f # match in second set half or end of string? movdqa 16(%rax), %xmm0 add $32, %rax pcmpistri $0, %xmm0, %xmm2 - jbe 3b + jb 3f # match in first set half? pcmpistri $0, %xmm0, %xmm3 - jae 0b # ZF=1 not possible here + ja 0b # neither match in 2nd half nor string end? - sub $16, %rax # go back to second half -1: add %rcx, %rax - sub %rdi, %rax +3: lea -16(%rax), %rax # go back to second half +1: jc 2f # jump if match found + pxor %xmm1, %xmm1 + pcmpeqb %xmm1, %xmm0 # where is the NUL byte? + pmovmskb %xmm0, %ecx + tzcnt %ecx, %ecx # location of NUL byte in (%rax) +2: sub %rdi, %rax # offset of %xmm0 from beginning of string + add %rcx, %rax # prefix length before match/NUL leave ret