Re: Constant byteorder macros.

From: H. Peter Anvin (hpa@transmeta.com)
Date: Wed Jan 19 2000 - 20:14:01 EST


Followup to: <E12AyZR-0002gU-00@devel2.axiom.internal>
By author: David Woodhouse <dwmw2@infradead.org>
In newsgroup: linux.dev.kernel
>
>
> In order to use cpu_to_le16() et al. in case statements, for example:
>
> switch (status) {
> case cpu_to_le16(CONSTANT_XYZ):
>
>
> ... I need to define new macros __constant_cpu_to_le16(), etc.
>
> Ideally, gcc would be able to tell that it's constant, and I would be able to
> use the 'normal' cpu_to_le16 macro. But as someone's evidently already given
> up on that with __constant_htonl() etc., I'm going to assume that it's not
> currently possible.
>

Given that gcc has a __builtin_constant_p(x), you ought to be able to
do:

#define cpu_to_le16(x) ( __builtin_constant_p(x) ? __constant_cpu_to_le16(x) : __cpu_to_le16(x) )

        -hpa

-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Jan 23 2000 - 21:00:21 EST