From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 3755E221E6 for ; Tue, 27 Feb 2024 15:08:51 +0100 (CET) Received: (qmail 20074 invoked by uid 550); 27 Feb 2024 14:05:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 20034 invoked from network); 27 Feb 2024 14:05:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709042917; x=1709647717; darn=lists.openwall.com; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ORfMXIoAtUYTSchS83t7tF/OtXeq2ahvh30w0rYea/o=; b=NMWsZlm9Nd2/u3c7grj7yhRLM0W6DU5MPLlbYiVrIoqovv1zoeCo2YftzkdoMmg6AP 9ZoQDaMzUaaRU0kl+oAEMbGwJfqJlaDxs5EhgpMI3gFtlIF8pNg4adkhLr4n0Qk19HqQ 8AVJpDnIIQlHZxvQ6OC6fATQ66vuWma6yIRA3MOx/0mapn/KUvt2JftoD0tu7AfefvnS 2/2dhEPHo0XY6cgUFPGsQBV56rmqPlyhQa6gjBqIKo0nywbVS2xo22Bbi6EWe1KbMvxu ZQvfc4WZyFDH8E3SfBn/ja/8L6QfUyXxKVSV6W0pbxPnZkKnPNEgojhmTQyplQ9Saguy bDhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709042917; x=1709647717; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ORfMXIoAtUYTSchS83t7tF/OtXeq2ahvh30w0rYea/o=; b=hNawHfht8uEgFKLNZoKr3dyLxccEirmUY9MFJIJpBvaJum53XeC0ggukyUxgvM4aeV oqaVWardeNKrKIzGQEveYlw3Ae8MIEi4jjSvf/F+yTcGQofUKiweS9nROMJNGd5fPloc 2CyZaX1hbw0uBFrNjDNABrzXx392NmE72g1tXsEkp3RVY+DmfIP5qF0fJV5bxsJIbTd8 D4d8COAoegYFSukqk3+P/N8kgKaOp7GxQEKMyxb6gY6JFQRTTi8ASBYHwZUD7m1IX0mP iNL/rsHIXCK/LynMz/KCvqtc4LNuE6ExwD5uc8lrUVX+zYmcmqqHY/Fmack4VPvDr/lG Qtow== X-Gm-Message-State: AOJu0YyFH5mxm9kAydi1b3ETylVBlGJokZNLk8VnWEZ67uVlWGWIGp9k eyEhAUXyLOBIRm0XJ1PvJOfJwJE7SkK5ERGFDHZ07SjZLtab2X7HArxiabPxtX8= X-Google-Smtp-Source: AGHT+IEL0SslKgt8CQ3BnCcK0zRoY1nE0mdkeo8r62UM7KqGbyzAk0/D33BrZB3jygLp+ZCh/7Yzdg== X-Received: by 2002:a17:902:f688:b0:1dc:3d5:bdcc with SMTP id l8-20020a170902f68800b001dc03d5bdccmr12060850plg.42.1709042916473; Tue, 27 Feb 2024 06:08:36 -0800 (PST) From: James Tirta Halim To: musl@lists.openwall.com Cc: James Tirta Halim Date: Tue, 27 Feb 2024 21:07:56 +0700 Message-ID: <20240227140756.216904-1-tirtajames45@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] add memcmpeq: memcmp that returns length of first mismatch (unaligned access must be supported for mempcmpeq if using word access) mempcmpeq returns the length of the first mismatched byte. If S1 and S2 are equal, n is returned. The function is meant to be used internally in strstr and memmem: https://inbox.vuxu.org/musl/20181108193451.GD5150@brightrain.aerifal.cx/ glibc bench-memcmpeq timings (Core i3-1115G4): mempcmpeq memcmp_musl memcmp __memcmpeq_evex __memcmpeq_avx2 __memcmpeq_sse2 Average: 62.3978 269.813 16.0426 14.9072 14.1125 20.6527 Total: 30637.3 132478 7876.92 7319.43 6929.23 10140.5 Passes glibc test-memcmpeq. Return value in testing and benchmarking is changed to suit the behavior of memcmpeq. --- src/string/mempcmpeq.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/string/mempcmpeq.c diff --git a/src/string/mempcmpeq.c b/src/string/mempcmpeq.c new file mode 100644 index 00000000..bc17bc58 --- /dev/null +++ b/src/string/mempcmpeq.c @@ -0,0 +1,19 @@ +#include + +size_t +mempcmpeq(const void *s1, + const void *s2, + size_t n) +{ + const size_t length = n; +#ifdef __GNUC__ + typedef size_t __attribute__((__may_alias__)) word; + const unsigned char *p1 = (const unsigned char *)s1; + const unsigned char *p2 = (const unsigned char *)s2; + for (; n >= sizeof(word) && *(word *)p1 == *(word *)p2; p1+=sizeof(word), p2+=sizeof(word), n-=sizeof(word)); +#endif + for (; n; --n) + if (*p1++ != *p2++) + return (size_t)((p1 - 1 - (const unsigned char *)s1)); + return length; +} -- 2.44.0