Message ID | 20220613025739.23612-1-brandonfoongyankai@gmail.com |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FA6438460AE for <patchwork@sourceware.org>; Mon, 13 Jun 2022 02:58:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FA6438460AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655089104; bh=mBQCmvmkBG7S1rih3yA/H70rF2sZvbgcFIROy3Ls80k=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=irv7t//31+KDmOT3+KX60211G1sefrFAyWfl57bPqDVCHsqIR9Icx2nYd7wmpzv/8 INH1xCAChJrxkAKvl9ERFu532FiKYDBpN+0Z/aThoQ1wr3Q8WelBeBxMLWsDkIYGVG 4LlRL8ZT7JfmJbsO69OO+kox6nhMGWnDPGqI++ac= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 4D8AF385354D for <libc-alpha@sourceware.org>; Mon, 13 Jun 2022 02:58:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D8AF385354D Received: by mail-pl1-x62b.google.com with SMTP id u18so3995008plb.3 for <libc-alpha@sourceware.org>; Sun, 12 Jun 2022 19:58:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mBQCmvmkBG7S1rih3yA/H70rF2sZvbgcFIROy3Ls80k=; b=1WNrfEHNwAR1i90GRfmaB69ee5eTiSmYzZ3N88NmlI8tB4bGTz6F7tPgG/4Ih7f0up Ccw2Ek8re56Q2wvWxHiHpfvdc7XafMaYl7+TRzF1PjBe6HGHBwV7rSsb4+sHqoulKeoL NhQKeLiu1UxSKdOr2BkhTndG3bBBErGuG8h4o5iRTZp4pXVhMGyS4ufLac9w8en064g1 BSkUKq9U7Vpjvz2gKVl0JghFZ6YLn6Gio+rPmYwRFNerkj85fzSf3JtMdD3g9cP8UzHw 0A0DfzgBhkdIlnHYV+wXNDIIsI4GYYcgxeeXUbKL2mU3R6HmsBkAgpL2LWn1uskbH4UZ r6qg== X-Gm-Message-State: AOAM530AO1XbzNlnaPsWZ566AeZ9Hzqgk4SrwuqwwYIx7qSlhfuY1z2T BnRh+2QWPAKeYKWUD62XnZQYuvykn0s= X-Google-Smtp-Source: ABdhPJw+Ss00L7KSpxhiJx8QGv9po4/wngxhFXe1OBRQewlHXkluYSc9hfDEBnY4HwE/MTq6N8fhYA== X-Received: by 2002:a17:90a:b284:b0:1e3:826b:d11d with SMTP id c4-20020a17090ab28400b001e3826bd11dmr13467688pjr.79.1655089081163; Sun, 12 Jun 2022 19:58:01 -0700 (PDT) Received: from sgwld-bfoong1.us.drwholdings.com ([103.58.110.6]) by smtp.gmail.com with ESMTPSA id p15-20020a1709027ecf00b00165103c9903sm3742167plb.113.2022.06.12.19.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 19:58:00 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 0/1] Adding mempbrk() function to glibc Date: Mon, 13 Jun 2022 10:57:38 +0800 Message-Id: <20220613025739.23612-1-brandonfoongyankai@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: brandonfoongyankai--- via Libc-alpha <libc-alpha@sourceware.org> Reply-To: brandonfoongyankai@gmail.com Cc: Brandon Foong <brandonfoongyankai@gmail.com> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Adding mempbrk() function to glibc
|
|
Message
develop--- via Libc-alpha
June 13, 2022, 2:57 a.m. UTC
From: Brandon Foong <brandonfoongyankai@gmail.com>
Hi,
This follows up on a previous thread regarding the addition of mempbrk (https://sourceware.org/pipermail/libc-alpha/2022-January/135013.html). I have added a simple implementation of mempbrk, as well as its corresponding tests.
Brandon Foong (1):
string: Add basic implementation of mempbrk
include/string.h | 1 +
string/Makefile | 2 +
string/Versions | 1 +
string/mempbrk.c | 56 ++++++++++
string/string.h | 15 +++
string/test-mempbrk.c | 242 ++++++++++++++++++++++++++++++++++++++++++
6 files changed, 317 insertions(+)
create mode 100644 string/mempbrk.c
create mode 100644 string/test-mempbrk.c
Comments
* brandonfoongyankai: > From: Brandon Foong <brandonfoongyankai@gmail.com> > > Hi, > > This follows up on a previous thread regarding the addition of mempbrk (https://sourceware.org/pipermail/libc-alpha/2022-January/135013.html). I have added a simple implementation of mempbrk, as well as its corresponding tests. Andrew Pinski's advice is that this should be fixed in the compiler or libstdc++: | Really the issue is: | _8 = __builtin_memchr ("eE", _7, 2); | if (_8 != 0B) | | | Should just be expanded to _7 == 'e' || _7 == 'E' . | | That is: | int f(char a) | { | return __builtin_memchr ("e", a, 1) != 0; | } | int f1(char a) | { | return a == 'e'; | } | int g(char a) | { | return __builtin_memchr ("eE", a, 2) != 0; | } | int g1(char a) | { | return a == 'e' || a == 'E'; | } | | f and f1 should produce the same assembly | and g and g1 should produce the same (similar) assembly. <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103798> The challenge with mempbrk (and similar functions in general) is that the setup cost is so high. The interface is just isn't very good. It works for the programmer, but the compiler-generated code and the library implementing it should likely use a different interface. Thanks, Florian
On 6/13/2022 7:29 AM, Florian Weimer via Libc-alpha wrote: > * brandonfoongyankai: > >> From: Brandon Foong <brandonfoongyankai@gmail.com> >> >> Hi, >> >> This follows up on a previous thread regarding the addition of mempbrk (https://sourceware.org/pipermail/libc-alpha/2022-January/135013.html). I have added a simple implementation of mempbrk, as well as its corresponding tests. > Andrew Pinski's advice is that this should be fixed in the compiler or > libstdc++: > > | Really the issue is: > | _8 = __builtin_memchr ("eE", _7, 2); > | if (_8 != 0B) > | > | > | Should just be expanded to _7 == 'e' || _7 == 'E' . > | > | That is: > | int f(char a) > | { > | return __builtin_memchr ("e", a, 1) != 0; > | } > | int f1(char a) > | { > | return a == 'e'; > | } > | int g(char a) > | { > | return __builtin_memchr ("eE", a, 2) != 0; > | } > | int g1(char a) > | { > | return a == 'e' || a == 'E'; > | } > | > | f and f1 should produce the same assembly > | and g and g1 should produce the same (similar) assembly. > > <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103798> Yea, I'd tend to agree with Andrew on this. Paying the call overhead for something this trivial is crazy. jeff