[MUD-Dev] Naming and Directories?

Jay Carlson nop at mitre.org
Thu Mar 18 15:18:28 CET 1999


From: mud-dev-admin at kanga.nu [mailto:mud-dev-admin at kanga.nu]On Behalf Of
 Chris Gray

> [Jo Dillon:]

>  >  If it's that optimised might it not be defined in the header file,
>  >giving the compiler the source? I mean, if I was writing a highly
>  >optimised strcmp I wouldn't overlook the overhead involved in a function
>  >call...

Well, gcc doesn't.  From gcc's info files, 2.7.2.1 (closest I had at hand):

`-fno-builtin'
     Don't recognize builtin functions that do not begin with two
     leading underscores.  Currently, the functions affected include
     `abort', `abs', `alloca', `cos', `exit', `fabs', `ffs', `labs',
     `memcmp', `memcpy', `sin', `sqrt', `strcmp', `strcpy', and
     `strlen'.

     GCC normally generates special code to handle certain builtin
     functions more efficiently; for instance, calls to `alloca' may
     become single instructions that adjust the stack directly, and
     calls to `memcpy' may become inline copy loops.  The resulting
     code is often both smaller and faster, but since the function
     calls no longer appear as such, you cannot set a breakpoint on
     those calls, nor can you change the behavior of the functions by
     linking with a different library.

     The `-ansi' option prevents `alloca' and `ffs' from being builtin
     functions, since these functions do not have an ANSI standard
     meaning.

> I don't know if has been (or can be) done with strcmp in particular,
> but I've heard of optimized versions of memcpy that have quite long
> sources, sometimes written in assembler. They attempt to do things
> whole words at a time instead of a character at a time, have special
> cases for short operations, etc. I may be a few years out of date on
> this info, however. Personally, I don't recall seeing any functions
> given in system header files like that, other than things like
> 'FD_SET', etc. Keep in mind that the practice of having short accessor
> routines be 'inline' is a C++ thing, and doesn't port to ANSI C (I think -
> I know gcc supports 'inline', but is it part of ANSI C?)

Aw, it ports well enough to C.  If you define them as

  static INLINE get_foo() { return foo; }

you can just -DINLINE= for compilers that don't support the inline keyword
and presumably the optimizer will just inline it without prompting.  The
real fun starts with gcc's static inline and extern inline declarations....

I haven't built a system for *portably* making hints like these to the
compiler.  I may have to sooner or later for the MOO server, but just trying
to do the right thing with 32-bit pointers on the Alpha has been hard
enough.

Jay



_______________________________________________
MUD-Dev maillist  -  MUD-Dev at kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev




More information about the mud-dev-archive mailing list