Re: [patch] CFS scheduler, -v8

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

 




On Mon, 7 May 2007, Esben Nielsen wrote:
> 
> What is (long)(a-b) ? I have tried to look it up in the C99 standeard but I
> can't find it. Maybe it is in the referred LIA-1 standeard, which I can't find
> with google.

I don't worry about non-2's-complement machines (they don't exist, and 
likely won't exist in the future either).

So I worry about compilers rewriting my code.

So "(long)(a-b) < 0" (with "a" and "b" being unsigned long) is basically a 
portable way of testing the high bit of the result.

> I think the best would be to use "a-b > ULONG_MAX/2" when you mean "a<b" as
> that should be completely portable.

That certainly works too, but the difference is irrelevant, since Linux is 
unlikely to work on insane machines anyway (ie we do make a lot of other 
assumptions about the architecture, being two's-complement is the least of 
those).

So you basically shouldn't worry about hardware: everybody is pretty much 
the same. You should worry about *compilers* - that's where the 
differences show up.

So "(long)(a-b)" may be "implementation defined" (but since 
implementations are all 2's complement, we don't care), but a signed 
"(a-b)" that over/overflows is *undefined*, and that is much worse because 
it means that the compiler can do some funky stuff, and _that_ is a real 
practical worry.

And no, I also don't worry about porting Linux to 18-bit machines, or to 
ternary CPU's.  

			Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux