[Bug 1443] PowerPC in_cksum() requires optimization

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Wed Aug 31 15:49:56 UTC 2011


https://www.rtems.org/bugzilla/show_bug.cgi?id=1443

--- Comment #8 from strauman at slac.stanford.edu 2011-08-31 10:49:54 CDT ---
Please don't discuss the copyright notice here. This is not what this bug is
about.

One thing that immediately jumps to my eye is that the PPC inline assembly
assumes that the carry flag is preserved between two __asm__ statements.
AFAIK this is not a 'legal' assumption (and disassembling the -O0 variant
shows that there are indeed 'addic' instructions interspersed between
the desired addc/adde/adde ones). If the optimized code works then we are
just lucky.

Needless to say that it is impossible to write this kind of routine
in a 100% alias-rule safe manner. An IP checksum necessarily accesses
the to-be-checked object violating that rule. in_cksum is one place
where type-punning is liberally done.

Inline assembly is very, very tricky and as gcc gets smarter there
are almost always new pitfalls (not that this particular one is a
new one).

IMO the addc/adde sequences should be coded in a single statement
with a 'cc' and 'memory' clobber (since you want to make sure
that gcc writes the memory before the inline asm accesses it).
It would be possible to specify only the relevant memory region as an input
operand (so that gcc may still optimize with irrelevant memory)
but using an "m" constraint does *not* produce the desired result
and I don't know how to do it properly. Needless to say that there
is no thorough documentation...

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list