Subject: Re: getting rid of NTOHS() in ip_input()
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Bill Studenmund <email@example.com>
Date: 08/13/2002 10:54:19
On Tue, 13 Aug 2002, der Mouse wrote:
> > one of them (ip_off & 0x7) i kept byteswap ip_off, as the meaning of
> > "0x7" becomes non-obvious if we byteswap it.
> Surely the right thing is "ip_off & htons(0x7)", and let the compiler
> constant-fold when possible? If htons is done right, a smart compiler
> could constant-fold it even on little-endian machines. (On big-endian
> machines, of course, [hn]to[hn]? all go away anyway.) And even if the
> compiler doesn't constant-fold, swapping 7 is no worse than swapping a
> run-time variable, and leaves the way open for optimization when
> compilers smarten up.
Agreed. Swapping the constant is the best thing to do. Either it changes
nothing, or the compiler will optimize it.