From: graydon h. <gr...@re...> - 2003-01-31 05:14:16
|
so, after several hours of banging my head against this problem, I realized the fact which is probably totally obvious to everyone else: endianness is a property of the datum being fetched by the CPU at any given access, and has nothing to do with the memory system at all. alignment and byte-numbering modulo current offset are irrelevant. it's sufficient to just store a flag saying which endianness you're using, and either count up or down for the current datum. sigh. I humbly submit this patch, which as far as I can tell fixes libabi, as tested with a full x86->ppc64->X86 op_import round trip (on real live hardware) of a database file: $ hexdump x86.db | head -n 8 0000000 4144 0a45 0008 0000 0001 0000 0080 0000 0000010 0000 0000 0000 0000 0003 0000 beef dead 0000020 0000 0000 0000 0000 a4af 3dad 0000 0000 0000030 0000 0000 0000 0000 0000 0000 0000 0000 * 0000080 1000 0000 0ed1 0000 0000 0000 0000 0000 0000090 0000 0000 0000 0000 0000 0000 0000 0000 * $ hexdump x86-ppc64.db | head -n 8 0000000 4144 0a45 0000 0800 0001 0000 0000 8000 0000010 0000 0000 0000 0000 0000 0300 adde efbe 0000020 0000 0000 0000 0000 ad3d afa4 0000 0000 0000030 0000 0000 0000 0000 0000 0000 0000 0000 * 0000080 0000 0010 0000 d10e 0000 0000 0000 0000 0000090 0000 0000 0000 0000 0000 0000 0000 0000 * $ hexdump x86-ppc64-x86.db | head -n 8 0000000 4144 0a45 0008 0000 0001 0000 0080 0000 0000010 0000 0000 0000 0000 0003 0000 beef dead 0000020 0000 0000 0000 0000 a4af 3dad 0000 0000 0000030 0000 0000 0000 0000 0000 0000 0000 0000 * 0000080 1000 0000 0ed1 0000 0000 0000 0000 0000 0000090 0000 0000 0000 0000 0000 0000 0000 0000 * $ ls -l x86.db x86-ppc64.db x86-ppc64-x86.db -rw-r--r-- 1 graydon graydon 65696 Jan 30 23:57 x86.db -rw-r--r-- 1 graydon graydon 65696 Jan 30 23:57 x86-ppc64.db -rw-r--r-- 1 graydon graydon 65696 Jan 30 23:57 x86-ppc64-x86.db $ cmp x86.db x86-ppc64-x86.db $ hooray for endianness. I will now wear a paper bag on my head. would someone with even more exotic hardware care to confirm? -graydon |