Subject: Re: in_cksum asm chunks.
To: Chris Gilbert <chris@paradox.demon.co.uk>
From: Richard Earnshaw <rearnsha@arm.com>
List: port-arm
Date: 08/31/2001 10:56:15
> On Friday 31 August 2001  9:55 am, Richard Earnshaw wrote:
> > > Hi,
> > >
> > > I've just been looking over the asm chunks in in_chksum_arm.c, and
> > > noticed that we don't say that they overwrite the condition codes, I was
> > > wondering if any knew if this isn't needed on arm?
> >
> > It's good form to mention this in the clobber list, but the compiler will
> > assume that condition codes are clobbered by ASM statements.
> 
> That feels wrong, what if it's not clobbered by the asm stuff, does the 
> compiler have to store the condition code away and reload/recalculate it?

The condition code register is always maintained in the compiler as a 
"hard" register (normally the compiler uses pseudo registers before the 
register allocation pass).  As such it is generally calculated shortly 
before it is used (normally the preceding instruction).  Later passes can 
move things around a bit if it won't change the result.  Prohibiting the 
compiler from moving a compare across an ASM statement is a minor loss of 
optimization but not much, given the risk of doing so when it isn't safe.

Use of asm statements is generally bad news.  They should normally be 
confined to instructions that can't be described to the compiler at all 
(eg accessing things like CP15, atomic swap operations, etc).  Using them 
on the assumption that you will get better code that way is often a 
mistake, since the compiler has to tread very carefully around them and 
can't merge the asm statements into the rest of the code.

Please think very carefully whether the code would be better expressed as 
C.

R.