Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Willem <willem@toad.stack.nl> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Optimisation questions |
| Date | 2012-02-06 18:51 +0000 |
| Organization | Stack Usenet News Service |
| Message-ID | <slrnjj088n.2o2q.willem@toad.stack.nl> (permalink) |
| References | (1 earlier) <jgkfso$1bh$2@dont-email.me> <jgkgra$886$1@dont-email.me> <jgkou6$g96$1@dont-email.me> <20120205034114.797@kylheku.com> <MPG.2999b0533378d8cf989693@aioe.org> |
Dann Corbit wrote:
) Using gcc 4.7 with -O3 on this program:
)
) #include <stdio.h>
) #include <stdlib.h>
)
) int div8_0(int x)
) {
) return x >> 3;
) }
)
) int div8_1(int x)
) {
) return x / 8;
) }
)
) int main(void)
) {
) int a = rand();
) int result0 = div8_0(a);
) int result1 = div8_1(a);
) printf("%d / 8 = %d, %d\n", a, result0, result1);
) return 0;
) }
)
) gave this output, which adds additional instructions for the division as
) opposed to the shift:
That's probably because the compiler has a bit more freedom to deal with
shifts of negative integers. The extra instructions look like they fix
some issue with signed shifting on that architecture.
IOW: Another case of 'undefined behaviour enables faster code'.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Optimisation questions Raj Pashwar <raj121190@hotmail.NOSPAM.com> - 2012-02-04 22:30 +0000
Re: Optimisation questions Ian Collins <ian-news@hotmail.com> - 2012-02-05 11:44 +1300
Re: Optimisation questions Keith Thompson <kst-u@mib.org> - 2012-02-04 14:52 -0800
Re: Optimisation questions Ian Collins <ian-news@hotmail.com> - 2012-02-05 11:55 +1300
Re: Optimisation questions Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-21 18:41 +0200
Re: Optimisation questions "BartC" <bc@freeuk.com> - 2012-02-04 22:44 +0000
Re: Optimisation questions "BartC" <bc@freeuk.com> - 2012-02-04 23:41 +0000
Re: Optimisation questions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-04 17:51 -0500
Re: Optimisation questions Keith Thompson <kst-u@mib.org> - 2012-02-04 14:52 -0800
Re: Optimisation questions James Kuyper <jameskuyper@verizon.net> - 2012-02-04 18:44 -0500
Re: Optimisation questions Stephen Sprunk <stephen@sprunk.org> - 2012-02-04 18:00 -0600
Re: Optimisation questions James Kuyper <jameskuyper@verizon.net> - 2012-02-04 21:18 -0500
Re: Optimisation questions Kaz Kylheku <kaz@kylheku.com> - 2012-02-05 03:04 +0000
Re: Optimisation questions Dann Corbit <dcorbit@connx.com> - 2012-02-06 09:40 -0800
Re: Optimisation questions Willem <willem@toad.stack.nl> - 2012-02-06 18:51 +0000
Re: Optimisation questions Markus Wichmann <nullplan@gmx.net> - 2012-02-07 14:19 +0100
Re: Optimisation questions Dann Corbit <dcorbit@connx.com> - 2012-02-07 14:25 -0800
Re: Optimisation questions Stephen Sprunk <stephen@sprunk.org> - 2012-02-06 17:29 -0600
Re: Optimisation questions Kaz Kylheku <kaz@kylheku.com> - 2012-02-06 23:52 +0000
Re: Optimisation questions pete <pfiland@mindspring.com> - 2012-02-06 19:10 -0500
Re: Optimisation questions Raj Pashwar <raj121190@hotmail.NOSPAM.com> - 2012-02-05 10:51 +0000
Re: Optimisation questions Ian Collins <ian-news@hotmail.com> - 2012-02-06 00:08 +1300
Re: Optimisation questions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-05 08:13 -0500
Re: Optimisation questions "BartC" <bc@freeuk.com> - 2012-02-05 11:33 +0000
Re: Optimisation questions Zoltan Kocsi <zoltan@bendor.com.au> - 2012-02-05 23:24 +1100
Re: Optimisation questions Raj Pashwar <raj121190@hotmail.NOSPAM.com> - 2012-02-05 22:28 +0000
Re: Optimisation questions Kaz Kylheku <kaz@kylheku.com> - 2012-02-05 22:37 +0000
Re: Optimisation questions Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-05 17:48 -0500
Re: Optimisation questions Keith Thompson <kst-u@mib.org> - 2012-02-05 15:57 -0800
Re: Optimisation questions "BartC" <bc@freeuk.com> - 2012-02-05 12:53 +0000
Re: Optimisation questions Geoff <geoff@invalid.invalid> - 2012-02-04 16:07 -0800
Re: Optimisation questions "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-02-04 15:37 -0800
Re: Optimisation questions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-05 04:26 -0800
Re: Optimisation questions lawrence.jones@siemens.com - 2012-02-07 10:56 -0500
Re: Optimisation questions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-05 04:29 -0800
Re: Optimisation questions Michael Angelo Ravera <maravera@prodigy.net> - 2012-02-05 23:24 -0800
csiph-web