Re: kernel patch: byteorder+ufs facelift

Linus Torvalds (torvalds@transmeta.com)
Fri, 5 Dec 1997 10:24:46 -0800 (PST)


On 5 Dec 1997, Jes Degn Soerensen wrote:
>
> This patch still breaks libc ....

So fix libc.. Or don't use the Linux headers for user space programs, like
glibc does.

But I just tested at least the x86 version of the Linux files, and they
work fine in user space too:

#include "asm-i386/byteorder.h"

int main(int argc)
{
return htonl(1)+htonl(++argc);
}

results in

main:
movl 4(%esp),%eax
incl %eax
#APP
xchgb %al,%ah
rorl $16,%eax
xchgb %al,%ah
#NO_APP
addl $16777216,%eax
ret

which is correct in the presense of "side effects" _and_ does the correct
constant case optimization (it doesn't use the "bswap" instruction because
only the kernel uses that when compiled for >386 - the header files are
set up to avoid bswap for user programs so that we don't get binaries that
only work on certain machines).

And the advantage of the new scheme is the size of the architecture
"byteorder.h" code. It only needs to define a few very simple basic
operations, and then the generic headers take it from there and do all the
complex stuff like the constant optimization etc..

Linus