From: Sylvain Leroux <sylvain@chicoree.fr>
To: gcc-help@gcc.gnu.org
Subject: Optimizing 32 bits integer manipulation on 8 bit AVR target
Date: Thu, 30 Aug 2012 15:32:00 -0000 [thread overview]
Message-ID: <503F6297.7080406@chicoree.fr> (raw)
Hi,
It seems to me that avr-gcc/avr-g++ is producing sub-optimal code for
the 'f' function in the following source code:
---------8<-----------------------------------
#include <avr/io.h>
void f(uint32_t i) {
i |= ((uint32_t)(0xFF) << 16);
/* DDRA is an 8 bit register */
DDRA = (uint32_t)(i);
DDRA = (uint32_t)(i>>8);
DDRA = (uint32_t)(i>>16);
DDRA = (uint32_t)(i>>24);
}
int main() {
volatile uint32_t n = 0x01020304;
f(n);
}
---------8<-----------------------------------
Having compiled with the following options:
avr-gcc c.c -mmcu=attiny2313
-Os -ffunction-sections -fdata-sections
-g -Wl,--gc-sections -Wl,--print-gc-sections
-fipa-cp -fcprop-registers -fweb
... here is the relevant fragment as displayed by avr-objdump. I marked
with a star (*) all the instruction that appears to be useless:
---------8<-----------------------------------
void f(uint32_t i) {
i |= ((uint32_t)(0xFF) << 16);
34: 8f 6f ori r24, 0xFF ; 255
DDRA = (uint32_t)(i);
36: 6a bb out 0x1a, r22 ; 26
DDRA = (uint32_t)(i>>8);
38: 27 2f mov r18, r23
* 3a: 38 2f mov r19, r24
* 3c: 49 2f mov r20, r25
* 3e: 55 27 eor r21, r21
40: 2a bb out 0x1a, r18 ; 26
DDRA = (uint32_t)(i>>16);
42: 9c 01 movw r18, r24
* 44: 44 27 eor r20, r20
* 46: 55 27 eor r21, r21
48: 2a bb out 0x1a, r18 ; 26
DDRA = (uint32_t)(i>>24);
4a: 69 2f mov r22, r25
* 4c: 77 27 eor r23, r23
* 4e: 88 27 eor r24, r24
* 50: 99 27 eor r25, r25
52: 6a bb out 0x1a, r22 ; 26
}
54: 08 95 ret
---------8<-----------------------------------
Both gcc and g++ produce the same code. And I get the same results both
with 4.3.5 and 4.7.1
Here is my question:
Is there any option(s) that will help gcc to not produce those extra
instructions in such case?
Regards,
- Sylvain
--
-- Sylvain Leroux
-- sylvain@chicoree.fr
-- http://www.chicoree.fr
next reply other threads:[~2012-08-30 12:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-30 15:32 Sylvain Leroux [this message]
2012-08-30 18:05 ` Sylvain Leroux
2012-08-31 11:51 ` David Brown
2012-08-31 22:37 ` Georg-Johann Lay
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=503F6297.7080406@chicoree.fr \
--to=sylvain@chicoree.fr \
--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).