avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignm


From: James Washer
Subject: Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Wed, 8 Dec 2004 17:11:17 -0800

I'm certainly no language lawyer.. just a programmer, but

It's quite common to have to introduce "barriers" in your code to force 
everything ABOVE the barrier to complete, before anything below the barrier is 
started. This is because compilers will re-order code, and processors will be 
working on more than one instruction at a time.

Here's a snippet from the Linux kernel. Note the comment about devices:

/*
 * Force strict CPU ordering.
 * And yes, this is required on UP too when we're talking
 * to devices.
 *
 * For now, "wmb()" doesn't actually do anything, as all
 * Intel CPU's follow what Intel calls a *Processor Order*,
 * in which all writes are seen in the program order even
 * outside the CPU.
 *
 * I expect future Intel CPU's to have a weaker ordering,
 * but I'd also expect them to finally get their act together
 * and add some real memory barriers if so.
 *
 * Some non intel clones support out of order store. wmb() ceases to be a
 * nop for these.
 */

#define mb()    __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
#define rmb()   mb()

#ifdef CONFIG_X86_OOSTORE
#define wmb()   __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
#else
#define wmb()   __asm__ __volatile__ ("": : :"memory")
#endif



On Wed, 08 Dec 2004 17:17:07 -0700
"E. Weddington" <address@hidden> wrote:

> Richard Urwin wrote:
> 
> >On Wednesday 08 Dec 2004 11:20 pm, Dave Hylands wrote:
> >  
> >
> >>So, what this says to me, is that it's perfectly reasonable for the
> >>compiler to take an expression like:
> >>
> >> x = 1 + 2 + 3;
> >>
> >>and compile it as:
> >>
> >> tmp = 1;
> >> tmp += 2;
> >> tmp += 3;
> >> x = tmp;
> >>
> >>or as:
> >>
> >> x = 1;
> >> x += 2;
> >> x += 3;
> >>    
> >>
> >
> >I would say that a volatile should only be written to as many times as 
> >the code says. 
> >  
> >
> 
> Unfortunately, it's not what you say (or what one says) that counts. 
> What matters is what the C standard specification says that counts.... 
> Any language lawyers in the house care to comment? Can we get chapter 
> and verse?
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
> 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]