This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

trying to understand file-static variables in arm-linux-gcc



hi all

i'm trying to understand how arm-linux-gcc compiles code compared to the
assembler from ARM Ltd.


  ------------------------------------------------------------

here's an excerpt of a sample file:

   PFNISR pfnOldIRQ = 0;
   static int iIRQRefCount = 0;

   void
   InterruptRemoveIRQ(void)
   {
       if(pfnOldIRQ && !(--iIRQRefCount))
       {
           Angel_SetIRQ(0xFC, pfnOldIRQ);
           pfnOldIRQ = 0;
       }
   }


  ------------------------------------------------------------

gcc-2.95.3 -O2 -fomit-frame-pointer
  generates 15 instructions plus 2 relocations

00000224 <InterruptRemoveIRQ>:
 224:   e92d4030        stmdb   sp!, {r4, r5, lr}
 228:   e59f5030        ldr     r5, [pc, #30]   ; 260
 22c:   e5951000        ldr     r1, [r5]
 230:   e3510000        cmp     r1, #0  ; 0x0
 234:   08bd8030        ldmeqia sp!, {r4, r5, pc}
 238:   e59f2024        ldr     r2, [pc, #24]   ; 264
 23c:   e5923000        ldr     r3, [r2]
 240:   e2434001        sub     r4, r3, #1      ; 0x1
 244:   e3540000        cmp     r4, #0  ; 0x0
 248:   e5824000        str     r4, [r2]
 24c:   18bd8030        ldmneia sp!, {r4, r5, pc}
 250:   e3a000fc        mov     r0, #252        ; 0xfc
 254:   ebfffffe        bl      0 <IRQHandler>
 258:   e5854000        str     r4, [r5]
 25c:   e8bd8030        ldmia   sp!, {r4, r5, pc}
 260:   00000000        andeq   r0, r0, r0
 264:   00000004        andeq   r0, r0, r4


  ------------------------------------------------------------

"Norcroft  ARM C vsn 4.90 (ARM Ltd SDT2.50) [Build number 80]"
  generates 14 instructions plus 0 relocations

000001bc <InterruptRemoveIRQ>:
 1bc:	e92d4010 	stmdb	sp!, {r4, lr}
 1c0:	e51f4098 	ldr	r4, [pc, #ffffff68]	; 130
 1c4:	e5941000 	ldr	r1, [r4]
 1c8:	e3510000 	cmp	r1, #0	; 0x0
 1cc:	08bd8010 	ldmeqia	sp!, {r4, pc}
 1d0:	e5940004 	ldr	r0, [r4, #4]
 1d4:	e2500001 	subs	r0, r0, #1	; 0x1
 1d8:	e5840004 	str	r0, [r4, #4]
 1dc:	18bd8010 	ldmneia	sp!, {r4, pc}
 1e0:	e3a000fc 	mov	r0, #252	; 0xfc
 1e4:	ef123456 	swi	0x00123456
 1e8:	e3a00000 	mov	r0, #0	; 0x0
 1ec:	e5840000 	str	r0, [r4]
 1f0:	e8bd8010 	ldmia	sp!, {r4, pc}


  ------------------------------------------------------------

gcc creates 2 extra variable relocations (at 260 and 264), and it
does so for each function in the file.  on the other hand, norcroft
points all functions directly back to a single variable relocation
(at 130).

in general, gcc seems to make local relocations for everything on a per
function basis, which the other compiler handles them on a per-file basis.

can anyone tell me how to make gcc compile this file more efficiently, or
where in the gcc codebase i should be looking to figure this out myself, or
why it hasn't been/can't be done?


thanks

-- 
---------------------------------------------------------------------------
    Ray Lehtiniemi <rayl@mail.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]