public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Enrico Weigelt <weigelt@metux.de>
To: gcc-help@gcc.gnu.org
Subject: Re: suggestion for GCC (1)
Date: Sun, 06 Mar 2011 13:19:00 -0000	[thread overview]
Message-ID: <20110306131537.GA14742@nibiru.local> (raw)
In-Reply-To: <iiu3gi$21o$1@dough.gmane.org>

* David Brown <david@westcontrol.com> wrote:

> gcc itself knows about /some/ of these things, given the correct flags 
> (it will probably know about alignment issues, but is unlikely to know 
> about cache line sizes).  Thus it will sometimes inline memcpy using the 
> builtin code, such as for small copies where the number of bytes is 
> fixed at compile time, and it will sometimes call an external function.

Apropos: is there some way to extend these builtins from external
libraries ?

Let's assume I'm writing some library for very common ATDs, eg. lists,
hashtables, etc. And for some specific targets I'd like to do some
heavy optimizations, which should be completely hidden behind the
API (just like done with memcpy, etc). So it would be nice to somehow
plug into the compiler's code generation, but w/o touching the compiler
itself, just giving it more deeper information beyond the usual C code.

An typical use case could be string concatenation, an strcat() that
takes multiple arguments. For example:

    char buffer[1024];
    const char* ptr const = "huh";
    strcatx(buffer, "hello", " world: ", strerror(errno), " blah ", ptr);

This could well be implemented as a macro using __VA_ARGS etc, but there's
still much room for optimization which would require compiler-internal
information. In this particular case we know several things, eg:

    * "hello" and " world: " are really constant strings, so the result
      of their concatenation is known at compile time: "hello world: "
    * strerror() maps a limited number range to fixed strings, to it
      could be a direct array lookup (after proper bounds checking)
    * concetenation of " blah " and ptr also has an known result at
      compile time: " blah huh"
    * sizes of the constant strings is already defined at compile time.

So the same could also be written that ways:

    const char* _errptr;
    int _errlen;
    if ((errno >= ERRNO_MIN_IDX) && (errno <= ERRNO_MAX_IDX))
    {
	_errptr = _errno_str_vector[errno];
	_errlen = _errno_sz_vector[errno];
    }
    else
	_errptr = "Unknown error code";
	_errlen = 18;
    }
    char buffer[1024];
    memcpy(buffer, "hello world: ");
    memcpy(buffer+13, sizeof(buffer)-13, _errptr);
    memcpy(buffer+13+_errlen, sizeof(buffer)-13-_errlen, " blah foo", 9);
    buffer[13+_errlen+9] = 0;


Is there a way to add those things by external libraries, w/o
touching the compiler itself ?

> There are plenty of complete toolchains based on gcc.  A good source of 
> these is www.codesourcery.com - the developers there do a lot of work on 
> various embedded gcc targets.  When you download a toolchain from them, 
> you get the assembler, linker and libraries included.  There are also 
> plenty of other ready-packaged gcc-based toolchains for other 
> microcontrollers.

Maybe crosstool-ng might also be worth looking at.
 

cu
-- 
----------------------------------------------------------------------
 Enrico Weigelt, metux IT service -- http://www.metux.de/

 phone:  +49 36207 519931  email: weigelt@metux.de
 mobile: +49 151 27565287  icq:   210169427         skype: nekrad666
----------------------------------------------------------------------
 Embedded-Linux / Portierung / Opensource-QM / Verteilte Systeme
----------------------------------------------------------------------

  reply	other threads:[~2011-03-06 13:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-09  5:17 ali hagigat
2011-02-09  5:27 ` Ian Lance Taylor
2011-02-09  6:03   ` ali hagigat
2011-02-09  7:05     ` ali hagigat
2011-02-09 10:26       ` Ian Lance Taylor
2011-02-09 15:23       ` David Brown
2011-03-06 13:19         ` Enrico Weigelt [this message]
2011-02-09  7:08     ` Ian Lance Taylor
  -- strict thread matches above, loose matches on Subject: below --
2011-02-07 10:23 ali hagigat
2011-02-07 10:26 ` Kai Ruottu
2011-02-07 10:29   ` Kai Ruottu
2011-02-07 10:57     ` ali hagigat
2011-02-07 11:03     ` ali hagigat
2011-02-07 23:43 ` Ian Lance Taylor
2011-02-08  0:44   ` Thomas Martitz
2011-02-08  7:35     ` Ian Lance Taylor
2011-02-08 14:23       ` David Brown
2011-02-09  4:54         ` Ian Lance Taylor

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=20110306131537.GA14742@nibiru.local \
    --to=weigelt@metux.de \
    --cc=gcc-help@gcc.gnu.org \
    /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).