Re:Ask HN: Is big-endian dead?
by kazinator on Friday January 19, 2018 @02:48PM
(#16189146)
OTOH, big-endian is better for comparison; you can tell when one integer is larger than another by looking at as little as just one bit, from the most significant end.
[ Parent
| on HN ]
That's only an scalar code optimization though. You can still do comparison in constant time on little endian data, you just lack the ability to early-exit from the loop. In the modern world of SIMD data, that optimization often doesn't exist. Fair enough point though.
But comparison is done in registers which don't have a byte order. Unless you mean doing something like 256bit_a > 256bit_b which I would think it's a very rare operation. Good point though.
To follow up on this, I recently implemented a packed vector format. As a LE advocate I surprised myself by ordering the packing in BE order ā because that let me simply byte-compare vector encodings to compare the underlying vectors, which was a huge performance increase.
Data structures which are frequently compared, e.g. to be sorted, benefit from BE ordering. Just binary compare them as byte strings, usually an efficient inline operation.
If I were implementing a packed wire format for SQL data, for example, Iād probably do it in BE order.
In the worst case, comparison is still like subtraction.