public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Ondřej Bílka" <neleai@seznam.cz>
To: Joseph Myers <joseph@codesourcery.com>
Cc: Wilco Dijkstra <wdijkstr@arm.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH 2/*] Optimize generic strchrnul and strchr
Date: Thu, 28 May 2015 19:41:00 -0000	[thread overview]
Message-ID: <20150528175412.GA4872@domone> (raw)
In-Reply-To: <alpine.DEB.2.10.1505281733001.16930@digraph.polyomino.org.uk>

On Thu, May 28, 2015 at 05:36:04PM +0000, Joseph Myers wrote:
> On Wed, 27 May 2015, Wilco Dijkstra wrote:
> 
> > Finally first_nonzero_byte should just use __builtin_ffsl (yet another
> > function that should be inlined by default in the generic string.h...).
> 
> Will GCC always inline __builtin_ffsl (or call a libgcc function) rather 
> than generating a call to ffsl (user namespace) on some architectures?  If 
> it can ever call ffsl you need to do something similar to how we handle 
> __mempcpy calling __builtin_mempcpy (include/string.h redeclares mempcpy 
> with __asm__ ("__mempcpy"), so that libc-internal calls to __mempcpy 
> really do call that function at the assembler level if not inlined, rather 
> than calling mempcpy and having namespace issues).
> 
However it doesn't do it that well, I reported bug about that somewhere.
So after all you need to make assembly dump and fix gcc mistakes.

It don't eliminate ureachable checks when you put zero there, like for

int 
foo(int x)
{
  if (!x)
    return bar();
  return __builtin_ffsl(x);
}

You get following assembly:

    .cfi_startproc
        testl   %edi, %edi
        je      .L4
        movslq  %edi, %rax
        movq    $-1, %rdx
        bsfq    %rax, %rax
        cmove   %rdx, %rax
        addq    $1, %rax
        ret


  reply	other threads:[~2015-05-28 17:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 14:10 Wilco Dijkstra
2015-05-27 20:33 ` Ondřej Bílka
2015-05-28 11:27   ` Chris Metcalf
2015-05-28 18:05 ` Joseph Myers
2015-05-28 19:41   ` Ondřej Bílka [this message]
2015-05-28 20:36     ` Joseph Myers
  -- strict thread matches above, loose matches on Subject: below --
2015-05-27  9:19 [PATCH 1/*] Generic string function optimization: Add skeleton Ondřej Bílka
2015-05-27  9:19 ` [PATCH 2/*] Optimize generic strchrnul and strchr Ondřej Bílka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150528175412.GA4872@domone \
    --to=neleai@seznam.cz \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=wdijkstr@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).