From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15316 invoked by alias); 16 Mar 2013 11:13:39 -0000 Received: (qmail 15305 invoked by uid 22791); 16 Mar 2013 11:13:38 -0000 X-SWARE-Spam-Status: No, hits=2.5 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,SPF_SOFTFAIL,URI_HEX X-Spam-Check-By: sourceware.org Received: from sam.nabble.com (HELO sam.nabble.com) (216.139.236.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 16 Mar 2013 11:13:29 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1UGp3I-0003ZL-LC for gcc-bugs@gcc.gnu.org; Sat, 16 Mar 2013 04:13:28 -0700 Date: Sat, 16 Mar 2013 11:13:00 -0000 From: eewiz To: gcc-bugs@gcc.gnu.org Message-ID: <1363432408651-921866.post@n5.nabble.com> Subject: GCC needlessly saves Global Register Variables MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg01166.txt.bz2 I use Microchip's C30 compiler which, for all appearances, including Microchip's statements, is derived from the GCC. It does us the ld linker. Although, Microchip refuses to address my issue because they say that the following is a GCC issue. Using this syntax, I declare a global register variable pointer "PntrC". register Cavity_t *PntrC asm("w13"); // Global cavity pointer So my question is, why does GCC bother to copy the "globally declared" w13 register into another register and then use that register as a pointer when w13 would have worked just fine. Over the length of my program, GCC has wasted 204 words of flash needlessly copying w13. Here are five examples out of the 204 total. D:\ES1030\Firmware\V-1.45_RCH\Subs.c:67036: 149CE 78040D mov.w w13,w8 D:\ES1030\Firmware\V-1.45_RCH\Subs.c:67209: 14A66 78018D mov.w w13,w3 D:\ES1030\Firmware\V-1.45_RCH\Subs.c:70555: 0536C 78008D mov.w w13,w1 D:\ES1030\Firmware\V-1.45_RCH\Subs.c:70726: 0542E 78010D mov.w w13,w2 D:\ES1030\Firmware\V-1.45_RCH\Subs.c:74011: 09258 78050D mov.w w13,w10 Search complete. 204 matches found. Here is an example: 426: PntrC->Cavity_TempFP = PntrC->Cavity_TempFP * 1.8 + 32.0; // Convert temperature to Fahrenheit 087F8 78040D mov.w w13,w8 087FA 266662 mov.w #0x6666,w2 087FC 23FE63 mov.w #0x3fe6,w3 087FE 90A86D mov.w [w13+220],w0 08800 90A8FD mov.w [w13+222],w1 08802 071EED rcall __mulsf3 08804 200002 mov.w #0x0,w2 08806 242003 mov.w #0x4200,w3 08808 071F79 rcall __addsf3 0880A 98AC60 mov.w w0,[w8+220] 0880C 98AC71 mov.w w1,[w8+222] 427: PntrAG->Data = (t_u16)PntrC->Cavity_TempFP; // Create the integer cavity temperature input 0880E 809EC9 mov.w PntrAG,w9 08810 78040D mov.w w13,w8 08812 90A86D mov.w [w13+220],w0 08814 90A8FD mov.w [w13+222],w1 08816 071DDC rcall __fixunssfsi 08818 780100 mov.w w0,w2 0881A 780C80 mov.w w0,[w9] 428: if (PntrC->Prb_Res_Avg_Cntr < PROBE_AVG_DVSR) // If the capture averager pipeline is not yet full 0881C 90A888 mov.w [w8+208],w1 0881E 200630 mov.w #0x63,w0 08820 508F80 sub.w w1,w0,[w15] 08822 3E0006 bra gtu, 0x008830 In the above code, GCC copies w13 to w8. Then it uses w13 as a pointer, as it should, until some math library calls, then it uses w8 for a while. Then GCC does it all again, another copy of w13 to w8, point with w13, then point with w8. Why??? One might say that GCC is afraid that the library routines might corrupt w13. But if that were the case, GCC should eventually copy w8 back to w13. This never happens. The only writes to w13 in the entire program are where my C code purposefully sets the cavity pointer w13. Since I only have about 150 words of flash left in the chip, I would dearly love to get back the 204 words needlessly used to save the global register variable w13. Is there a way to command GCC to always use the "global register" declared w13 pointer directly, without wasting resources needlessly copying it to other registers? Wouldn't you call this a bug? The driving idea behind "global register variables" is to create highly efficient machine code, not waste 0.5% of someone's 44,000 words of precious flash memory needlessly. -- View this message in context: http://gcc.1065356.n5.nabble.com/GCC-needlessly-saves-Global-Register-Variables-tp921866.html Sent from the gcc - bugs mailing list archive at Nabble.com.