Re: [PATCH] aacraid 2.6: Address sparse warnings

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

 



On Fri, Apr 08, 2005 at 02:41:58PM -0400, Salyzyn, Mark wrote:
> As long as this is guaranteed on all platforms to do the right thing ...
> paranoid about compiler optimizations. MarkH, this should be an easy
> regroup :-)

Well, let's see.

cpu_to_le32(~0U) -> __cpu_to_le32(~0U) ->
[on little-endian]
	((__force __le32)(__u32)(~0U)) -> ((__le32)(__u32)(~0U))
[on big-endian]
	((__force __le32)__swab32((~0U))) ->
	((__le32)__swab32((~0U))) ->
((__le32) (__builtin_constant_p((__u32)((~0U))) ?
	 ___swab32(((~0U)))
: __fswab32(((~0U))))) ->
((__le32) (__builtin_constant_p((__u32)((~0U))) ?
({
        __u32 __x = ((~0U));
        ((__u32)(
                (((__u32)(__x) & (__u32)0x000000ffUL) << 24) |
                (((__u32)(__x) & (__u32)0x0000ff00UL) <<  8) |
                (((__u32)(__x) & (__u32)0x00ff0000UL) >>  8) |
                (((__u32)(__x) & (__u32)0xff000000UL) >> 24) ));
})
: __fswab32(((~0U)))))

And that's enough - __builtin_constant_p((__u32)((~0U)) is known at compile
time and is non-zero.  The rest is obvious and yes, gcc does understand
that __x is constant and so is the expression above.


IOW, all cpu_to_...(<constant>) will be simplified to constants at compile
time.  They will not be _constant_ _expressions_ from C point of view (IOW,
you can't say e.g.
	enum {
		A = cpu_to_le32(~0U)
	};
- that's what __constant_cpu_to_le32() is for), but they certainly will be
evaluated by compiler.
-
: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux