This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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

Re: PowerPC and Volatile



>> >Naturally, the locations we are talking about are declared volatile, so the
>> >compiler does not optimize the code, but the PowerPC has its own
>> >optimization in the form of pipelining, and it seems to be causing this
>> >problem.
>> >
>> >The question is, should the compiler be inserting an "eieio" instruction at
>> >the sequence points in the code, such as the end of the loop mentioned
>> >above?  This PPC instruction tells the processor to hold off its
>> >pipelining.  We have been inserting them in the code ourselves, but it is a
>> >bit of a pain to have to do it.
>>
>>No, the compiler can't automatically insert eieio instructions
>>since it doesn't know which pairs of *locations* need to have the eieio
>>synchronization.  That is something that only the hardware knows
>>about.  If it automatically put in an eieio before every volatile
>>reference, then it would uncecessarily slow down all volatile
>>accesses, even those between volatile locations that *don't* require it.
>>
>>I understand that its a pain, but when dealing with memory mapped i/o
>>devices and high performance processors, its part of the price you pay
>>for the gain in speed.
>
>I have a book titled "C A Reference Manual", by Samuel P. Harbison and Guy 
>L. Steele Jr.  In section 4.4.5, they say the following:
>
>"   To be more precise, ISO C introduces the notion of sequence points in C 
>programs.  A sequence point exists at the completion of all expressions 
>that are not part of a larger expression--that is, at the end of expression 
>statements, control expressions if, switch, while, and do statements, each 
>of the three control expressions in the for statement, return statement 
>expressions, and initializers.  Additional sequence points are present in 
>function calls immediately after all the arguments are evaluated, in the 
>logical AND (&&) and OR (||) expressions, and before the conditional 
>operator (?:) and the comma operator (,).
>    References to and modifications of volatile objects must not be 
>optimized across sequence points, although optimizations between sequence 
>points are permitted."
>
>Based on this (I do not have the ISO C Standard to check), there -are- 
>known locations at which the eieio instructions could be (and should be, to 
>my reading) inserted.

There's no doubt that you can modify the compiler to spit out eieio
instructions at sequencing points; but to what point? It will slow
down the code everywhere to make that tiny percentage of the code 
that needs the eieio instructions to work correctly.  That is like
using a bazooka to hunt mosquitoes; it works, but it is really inefficient. 

Its better to fix the code, not the compiler.

-- 
Peter Barada                                   Peter.Barada@motorola.com
Wizard                                         781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)   781-270-0193 (fax)

"The real art of conversation is not only to say the right thing at the
right time, but also to leave unsaid the wrong thing at the tempting
moment."  -- Unknown

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


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