4 ms·
Little endian won. You almost don't have to worry about a new piece of software running on a big-endian machine.
by bitwize 5y ago
Little endian won. You almost don't have to worry about a new piece of software running on a big-endian machine.
- minusf 5y agowhich is a loss, as according to openbsd developers developing for both caught a lot of bugs otherwise not found easily..
- edflsafoiewq 5y agoGive us an example.
- saurik 5y ago(I mean it just seems obvious you would catch more bugs given the format of big-endian, right?... it comes directly from the dual of one of the not-really-a-benefits of little-endian: how you can cast between pointers of different integer types without moving the pointer.)
- agent327 5y agoI'm totally onboard with casting integers, and I can understand casting between pointers-to-char and pointers-to-other, but why on earth would you want to cast between pointers to (different) integers? That seems like asking for trouble, for no benefit I can discern...
- masklinn 5y agohttps://news.ycombinator.com/item?id=28218704 https://news.ycombinator.com/item?id=28218704
- iainmerrick 5y agoCouldn’t you keep that benefit by testing on emulated big-endian hardware, though? (edit to fix interesting autocorrect glitch... “bug-endian” indeed!)
- iainmerrick 5y agoApart from most file formats and internet standards being big-endian, you mean? Although to borrow from minusf’s point, it’s good for software robustness that file formats and hardware use different endianness, as it forces you to read things byte-by-byte rather than lazily assuming you can just read 4 bytes and cast them directly to an int32.
- walki 5y ago> it’s good for software robustness that file formats and hardware use different endianness, as it forces you to read things byte-by-byte rather than lazily assuming you can just read 4 bytes and cast them directly to an int32. Except that it is very bad for performance. As far as CPUs are concerned little-endian has definitely won, most CPU architectures that have been big endian in the past (e.g. PowerPC) are now little endian by default. If all new CPU architectures are little endian this means that within a decade or two there won't be any operating systems that support big endian anymore.
- iainmerrick 5y agoFor performance, can’t you “just” have a swap-endianness instruction in your CPU, and have the compiler use it when it detects byte-shuffling code? (That may even happen already on some architectures for all I know)
- walki 5y ago> For performance, can’t you “just” have a swap-endianness instruction in your CPU Yes, most CPUs have special instructions for swapping between little and big endian byte arrangement. The GCC compiler has the __builtin_bswap64(x) for accessing this instruction. However this is an additional instruction that needs to be executed for each read of a 64-bit word that needs to be converted, in some workloads this can double the number of executed instructions and hence add significant overhead. Supporting big endian CPUs in systems programming sucks beyond imagination. There are virtually no big endian users anymore and making sure your software works fine on big endian requires testing it on a big endian CPU. However it is not possible to buy a big endian CPU anymore as there exist no more consumer big endian CPUs. For this reason I still have a Mac PowerPC from 2003 at home running an ancient version of Mac OS X. But over the last 2 years I have stopped testing my software on big endian, I just don't care about big endian anymore...