public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* GCC needlessly saves Global Register Variables
@ 2013-03-16 11:13 eewiz
  0 siblings, 0 replies; only message in thread
From: eewiz @ 2013-03-16 11:13 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-03-16 11:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-16 11:13 GCC needlessly saves Global Register Variables eewiz

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).