From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19163 invoked by alias); 30 Aug 2012 12:55:07 -0000 Received: (qmail 19155 invoked by uid 22791); 30 Aug 2012 12:55:06 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_40,RCVD_IN_DNSWL_NONE,TW_OV X-Spam-Check-By: sourceware.org Received: from 4.mo2.mail-out.ovh.net (HELO mo2.mail-out.ovh.net) (87.98.172.75) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 30 Aug 2012 12:54:51 +0000 Received: from mail406.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo2.mail-out.ovh.net (Postfix) with SMTP id 54650DC5DE0 for ; Thu, 30 Aug 2012 15:00:00 +0200 (CEST) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 30 Aug 2012 14:55:14 +0200 Received: from reverse-177-9.fdn.fr (HELO ?10.129.36.46?) (sylvain%chicoree.fr@80.67.177.9) by ns0.ovh.net with SMTP; 30 Aug 2012 14:55:13 +0200 Message-ID: <503F6297.7080406@chicoree.fr> Date: Thu, 30 Aug 2012 15:32:00 -0000 From: Sylvain Leroux User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110307 Icedove/3.0.11 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org X-Ovh-Mailout: 178.32.228.2 (mo2.mail-out.ovh.net) Subject: Optimizing 32 bits integer manipulation on 8 bit AVR target Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 7111465286815026815 X-Ovh-Remote: 80.67.177.9 (reverse-177-9.fdn.fr) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: 0 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehtddrfeeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpefuhihlvhgrihhnucfnvghrohhugicuoehshihlvhgrihhnsegthhhitghorhgvvgdrfhhrqeenucffohhmrghinheptghhihgtohhrvggvrdhfrhenucfjughrpefkfffhfgggvffutgfgsehtjegrtddtfedu X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehtddrfeeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpefuhihlvhgrihhnucfnvghrohhugicuoehshihlvhgrihhnsegthhhitghorhgvvgdrfhhrqeenucffohhmrghinheptghhihgtohhrvggvrdhfrhenucfjughrpefkfffhfgggvffutgfgsehtjegrtddtfedu Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg00296.txt.bz2 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 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