GCC optimization problem
Joel Sherrill
joel.sherrill at OARcorp.com
Fri Sep 29 15:22:33 UTC 2000
Silverio Diquigiovanni wrote:
>
> 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 --- >
A lot depends on precisely what gcc thinks is happening in the
asm. My intuition tells me that it does not think my_var can
change. I see a couple of options:
+ Make my_var volatile
+ add output constraints that say my_var could be modified.
I think your as should be "asm volatile" as well.
> 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
--
Joel Sherrill, Ph.D. Director of Research & Development
joel at OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
More information about the users
mailing list