lkml.org 
[lkml]   [2009]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: x86: Is 'volatile' necessary for readb/writeb and friends?
Date
> x86 memory-mapped IO register accessors cast the memory mapped address
> parameter to a one with the 'volatile' type qualifier. For example,
> here
> is readb() after cpp processing
>
> --> arch/x86/include/asm/io.h:
>
> static inline unsigned char readb(const volatile void __iomem *addr) {

This "volatile" is meaningless.

> unsigned char ret;
> asm volatile("movb %1, %0"

This "volatile" is required; without it, if "ret" isn't used (or can
be optimised away), the asm() could be optimised away.

> :"=q" (ret)
> :"m" (*(volatile unsigned char __force *)addr)

This "volatile" has no effect, since the asm has a "memory" clobber.
Without that clobber, this "volatile" would prevent moving the asm
over other memory accesses.

If you want to get all language-lawyery, if the object pointed to by
"addr" is volatile, the volatile here _is_ needed: accessing volatile
objects via a not volatile-qualified lvalue is undefined. But since
this is GCC-specific code anyway, do you care? :-)

> :"memory");
> return ret;
> }


Segher



\
 
 \ /
  Last update: 2009-12-04 15:35    [W:0.072 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site