4 ms·
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 significa
by kazinator 9y ago
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.
- IshKebab 9y agoBut 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.
- amelius 9y agoIn the worst case, comparison is still like subtraction.
- kazinator 9y agoEven if the whole datum is examined, comparison is more parallelizable; it doesn't require carry propagation.
- ajross 9y agoThat'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.
- garmaine 9y agoTo 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.