public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how is strcmp implemented so efficiently?
@ 2008-09-30 22:40 Reza Roboubi
  2008-09-30 22:55 ` me22
  2008-10-01  0:58 ` Ian Lance Taylor
  0 siblings, 2 replies; 3+ messages in thread
From: Reza Roboubi @ 2008-09-30 22:40 UTC (permalink / raw)
  To: gcc-help

I noticed that strcmp is extremely smart.  It knows when one parameter 
has constant length, determined at compile time.  In that case it 
reverts to an inline version of the x86 string commands.

I looked into the headers and strcmp is defined as an extern(not inline.)

How would I ever write such an efficient function?  Is it possible(even 
_with_ the use of asm?!)

Reza.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how is strcmp implemented so efficiently?
  2008-09-30 22:40 how is strcmp implemented so efficiently? Reza Roboubi
@ 2008-09-30 22:55 ` me22
  2008-10-01  0:58 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: me22 @ 2008-09-30 22:55 UTC (permalink / raw)
  To: Reza Roboubi; +Cc: gcc-help

On Tue, Sep 30, 2008 at 18:40, Reza Roboubi <reza@parvan.net> wrote:
> I noticed that strcmp is extremely smart.  It knows when one parameter has
> constant length, determined at compile time.  In that case it reverts to an
> inline version of the x86 string commands.
>

Sounds like one of the optimizer passes has special-case code to handle it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how is strcmp implemented so efficiently?
  2008-09-30 22:40 how is strcmp implemented so efficiently? Reza Roboubi
  2008-09-30 22:55 ` me22
@ 2008-10-01  0:58 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2008-10-01  0:58 UTC (permalink / raw)
  To: Reza Roboubi; +Cc: gcc-help

Reza Roboubi <reza@parvan.net> writes:

> I noticed that strcmp is extremely smart.  It knows when one parameter
> has constant length, determined at compile time.  In that case it
> reverts to an inline version of the x86 string commands.
>
> I looked into the headers and strcmp is defined as an extern(not inline.)
>
> How would I ever write such an efficient function?  Is it
> possible(even _with_ the use of asm?!)

The compiler automatically recognizes strcmp when compiling C/C++
code, among many other builtin functions.  See the docs for the
complete list.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-10-01  0:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-30 22:40 how is strcmp implemented so efficiently? Reza Roboubi
2008-09-30 22:55 ` me22
2008-10-01  0:58 ` Ian Lance Taylor

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).