GCC optimization problem

Silverio Diquigiovanni silverio.di at qem.it
Fri Sep 29 09:26:54 UTC 2000


Hi to all,
I'm aware this isn't a good place to post this question but I hope
someone can help me in this hard moment....

Architecture : sh7045F
RTOS	     : RTEMS 4.5
GCC	     : sh-rtems-gcc ( 2.95.2 )

In my source code I must often use an assembler line which call an
software trap called " trap #37 ". During that trap a function modify
various variables and also the variable called " my_var " :


< -- start snip code --- >

    while ( my_var && 0x08 )
    {
    	asm( " trapa #37 " : : );    /* some function modify my_var */
    }

< -- end snip code --- >


In the not optimized code ( -O0 ) the result code is :


< -- start snip code --- >

L18:	mov.l	L102,r1		! my_var address
	mov.b	@r1,r2		
	mov	#8,r1		
	and	r2,r1
	exts.b	r1,r2
	tst	r2,r2
	bt	L20
	bra	L19
	nop

L20:	trapa #37
	bra	L18
	nop

L19:	........

< -- end snip code --- >


This work very fine, but when I try to optimize the code with -O2,
-O3, -O.., a bad code result because the compiler isn't aware of
assembler body matter .....


< -- start snip code --- >

L17:	mov	r10,r0			
	mov.b	@(r0,r8),r1
	mov	r1,r0
	and	#8,r0
	tst	r0,r0
	bf	L19

L20:	trapa #37
	bra	L20
	nop

L19:	........

< -- end snip code --- >


how you can see in L20 don't read the possible new value of
" my_var " variable. In this case this become an infinite bad loop.

I have tried to declare my_var " volatile " but the result is same.

Then,
how I can teach to compiler that my assembler routine ( trapa #37 )
can modify the value of " my_var " ?

Thank you very much !!!!!!!
Best Regards,

Silverio Diquigiovanni



More information about the users mailing list