mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Zoltán Kócsi" <zoltan@bendor.com.au>
To: barebox@lists.infradead.org
Subject: Re: test app
Date: Tue, 15 Mar 2011 22:47:28 +1100	[thread overview]
Message-ID: <20110315224728.0d958936@manocska.bendor.com.au> (raw)
In-Reply-To: <6EE7D1502C48E44E92DCADF9DD3E0DB9017FF3BF4F05@SRV-VS06.TELEVIC.COM>

> If I use a division operator or a modulo division operator in a
> static function, all compiles well. If I change the static function
> into a global function, I get following errors : Undefined reference
> to '__aeabi_idiv' Undefined reference to '__aeabi_idivmod'

Those are the division routines in gcc's libgcc.a library. Your problem
is this:

> CFLAGS		= -Wall -Os -nostdlib -Wl,-Ttext=0xA0000000

-nostdlib tells the compiler not to link against the standard
libraries, which include libgcc.a.

> %.elf : $(SRCS)
> 	$(CC) $(CFLAGS) $^ -o $@

If you add a -lgcc to the line above, it should compile.

> I never encountered this problem before in other projects and I don't
> see why this is working in static functions and not in global
> functions.... 

Possibly because if you have static functions, then the compiler can
inline them. If after the inlining it can work out that you are
dividing with a constant, then it won't pull in the division routines,
but substitute division with a multiplication, two shifts and an
addition (the cost of calculating the constant to multiply with and
the shift amounts involves, among other things, a 64-bit division, but
that all happens in compile time - at runtime it's just the mul, shift,
add, which is orders of magnitue faster as well as smaller than a real
division). If you have a global function, gcc must assume that it can
be called with arbitrary arguments from other C files, therefore it must
do real (i.e. runtime) division.
 
Regards,

Zoltan

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2011-03-15 11:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-07 13:05 Vanalme Filip
2011-03-08  5:40 ` Baruch Siach
2011-03-08  8:13   ` Vanalme Filip
2011-03-08 10:09     ` Vanalme Filip
2011-03-08 11:22       ` Baruch Siach
2011-03-08 15:52         ` Vanalme Filip
2011-03-08 18:08           ` Baruch Siach
2011-03-09  8:28             ` Vanalme Filip
2011-03-14 14:55               ` Vanalme Filip
2011-03-14 17:31                 ` Jean-Christophe PLAGNIOL-VILLARD
2011-03-14 18:03                 ` Baruch Siach
2011-03-15 11:03                   ` Vanalme Filip
2011-03-15 11:47                     ` Zoltán Kócsi [this message]
2011-03-08 11:43       ` Sascha Hauer
2011-03-08 12:43         ` Vanalme Filip
2011-03-08 11:50 ` Sascha Hauer

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=20110315224728.0d958936@manocska.bendor.com.au \
    --to=zoltan@bendor.com.au \
    --cc=barebox@lists.infradead.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