svn commit: r266238 - head/contrib/ldns/ldns

Bruce Evans brde at optusnet.com.au
Sat May 17 04:04:52 UTC 2014


On Sat, 17 May 2014, [utf-8] Dag-Erling Smørgrav wrote:

> Bruce Evans <brde at optusnet.com.au> writes:
>> -Wcast-qual is especially onerous in contrib'ed code written to a lower
>> standard.
>
> Well, I could have just lowered WARNS...  LDNS actually isn't that bad.
> Unbound is much worse.
>
>> Converting this to use system endianness conversion functions wouldn't
>> take much more churn.
>
> Do our standard endianness conversion functions handle unaligned
> accesses?

Yes.  They intentionally use pessimal bytewise accesses for everything.

However, clang optimizes away all the pessimizations in many useful
cases, at last on amd64.  This depends on the functions being inline.
When clang can see that the pointed-to object is aligned, it generates
minimal code (at most a load-store for a null conversion, and I think
at most a load-bswap-store for a swapping conversion (I only checked
related cases for the latter)).  The case where the pointed-to object
is just an array of uint8_t is still pessimized.  Callers wanting to
avoid the pessimal case can avoid it by copying from the array to a
local variable.

gcc-4-2.1 doesn't optimize away any of the pessimizations.  However,
in even more complicated conversions in FP code, it optimizes the
union hack just as well as clang.

Bruce


More information about the svn-src-all mailing list