What are the benefits of the different endiannesses?
Asked Answered
A

5

15

Why did some processor manifacturers decide to use

  • Little endian
  • Big endian
  • Middle endian
  • Any others?

?

I've heard that with big endian one can find out faster, if a number is negative or positive, because that bit is the first one. (This doesn't matter on modern CPUs, as individual bit can't be accessed anymore.)

Alarcon answered 27/5, 2009 at 7:21 Comment(4)
Is middle endian where you have your egg on it's side and break it down the middle?Wellinformed
Middle endian is the scheme used by the PDP-11: Bits 15..8, then 7..0, 31..24, 23..16.Restrict
So middle endian is just 16 bit little endianLewanna
@DavidSykes and big endian is just 32-bit little endian? (Or 64-bit little endian on modern Intel chips?)Sybil
L
26

The benefit of little endianness is that a variable can be read as any length using the same address.

For example a 32 bit variable can be read as an 8 bit or 16 bit variable without changing the address. This may have limited benefit these days, but in the days of assembler and limited memory it could be a significant advantage

Lewanna answered 27/5, 2009 at 7:38 Comment(10)
I'm not sure there is an actual benefit to big endian, other than compatibility with other systems. In most high level languages the endianness is irrelevant anywayLewanna
One benefit of big-endian is that you can read 16-bit and 32-bit values as most humans do; from left to right. A memory dump of 4 bytes that says ffaa8800 is actually 0xffaa8800 not 0x0088aaff as little-endian would be.Romanticism
@DavidSykes : In that case, changing bit order instead of byte ordering would be more simple and achieve the same effect. I think it’s more at an electronic level rather to what is exposed to the developer.Bimah
@Bimah The benefit to the developer was real, I and many others used it back in the dayLewanna
@DavidSykes : Yes but, using bit ordering would so much simpler with flip‑flops, that I don’t understand where the idea of reverse byte ordering come from.Bimah
That is an edge-case that is/was rarely used. There was more than one benefit to little-endian. It also allowed some ALU ops to start executing during progressive decoding and/or before all memory reads finished. Nowadays, with wide buses it makes little difference.Adolphus
And if you think endianness is a PITA, look at DDR4 data line mapping... basically a RAM controller needs all sorts of crossbars because RAM sticks can route traces to almost any pin they please (within SPD config limits).Adolphus
not uncommon for the data busses to be one byte wide at this time, so as answered 8, 16 bit quantities had the same address. with big endian machines some level of logic would do the work either the machine used the same address but would have to fetch in the right order possibly reading 0x101 first then 0x100, instead of a natural 0x100 0x101. but it is all very machine dependent. Little endian is clean and simple and required less logic. Human readable is irrelevant, perhaps an excuse for the design at the time, but is not a good reason for such a design.Czardas
Today with wider busses, it doesnt make much sense, and or it is an illusion, a big or little endian machine could use the same right to left bit numbering and right to left byte numbering or whatever combination, you generally dont want to be doing less than bus sized accesses anyway due to the potential performance hits. The logic to select the byte lanes on the bus for either endianness do not have any or any relevant gains either way.Czardas
@PeyloW, and boy does it ever simplify SIMD...Sybil
H
3

There is no particular benefit of big or little endian as such, except using native CPU endianness or handling specified file endianness.

The reason why both big and little endian coexist is that different CPU makers used different conventions for representing multibyte data, and no standard emerged at the time.

Heiney answered 27/5, 2009 at 7:34 Comment(3)
having studying electronics, I’m familiar with bit ordering, but byte ordering seems really exotic.Bimah
According to Intel, it was essentially a "mistake" that made it into the wild by purely arbitrary circumstances. "Mistake" here means they designed a chip for a client, but the client never had any built. It's almost like a "why do clocks run clockwise?" question.Sybil
@SO_fix_the_vote_sorting_bugcan you bring a reference to your explanation?Wenda
P
2

Certain operations benefit from having parts of a value available before another part. When adding two unsigned or two's-complement numbers which are too large to read all at once, the lower bits of the result can be computed before the upper bits are available, but not vice versa, implying that little-endian order is advantageous there. When accessing a serial flash chip, row decoding can only begin when all of the bits which define the row (typically all but the least-significant 8-12 bits, depending on the chip) become available, implying that big-endian order is advantageous there.

Prehension answered 16/6, 2016 at 19:56 Comment(2)
Modern RAM, decoding and execution logic is most often far more than 8 bits wide. It only makes sense on old or narrow bus / serial PICs.Adolphus
@Barry: The cases I know of where little-endian is advantageous stem from the ability to start operations on the lower bits of a number before all of the upper bits are available. Such cases arise far less often today than in years past, but the fact that hardware used to benefit from such abilities is almost certainly the reason that little-endian is common today.Prehension
A
1

Using the endianness of the CPU (no matter little or big) gives you the speed benefit on arithmetics: you can add, subtract etc. multibyte integers directly in memory.

Using a predefined, prescribed endianness (no matter little or big) in a file format gives you the benefit of being able to read the file on any system, no matter the endianness of the CPU of the other system. Systems with the right endianness can read the file faster (if the read routine is written and optimized properly), but even systems with the wrong endianness can read it. Usually, the speed difference is negligable (except for very large files with lots of integers), so it is a good idea to first measure the maximum possible speed gain of optimizing the read routine.

Some file formats (for example TIFF) support both endianness. In this case it is a good idea to generate the file with the CPU's endianness, assuming the file would be post-processed on the same machine, or a similar machine.

Astrosphere answered 27/5, 2009 at 7:26 Comment(4)
Actually, for a large file, even if only integers, you're going to be limited by the speed at which you can read it from disk or network if the only processing you need to do is swap ends. In fact, on modern CPUs you can do a lot more work than that before you're slower than your I/O, which is why often storing files on disk compressed, and decompressing them on the fly as you process them is faster than just processing an uncompressed file.Levon
Can you please explain how Endianness is important for reading Files. How does it matter if I read a Text File ?Hamburg
Well if for example you are reading a file which is a text file storing UTF16LE (little endian) characters, then if your native format was UTF16BE (big), you would have to reverse the sense of the characters as they were read in. However, as Curt Samson points out, this probably makes little difference since the speed of the CPU and main memory is much higher than the diskStirrup
@Hamburg When a binary file is read into a byte buffer, bytes are just thrown into memory in the order they appear on disk. LE and BE determine how a processor interprets multi-byte integers in memory. If an int was written to a binary file on an LE machine by directly converting the int to a byte buffer and read on a BE machine to a byte buffer directly interpreted as an int, it will be wrong.Adolphus
C
-1

In little endian you don't bother to change the address, but in big endian you have to: http://www.noveltheory.com/techpapers/endian.asp

I don't actually know if still little endian has advantage over big endian in modern CPUs. I -naively- think that switching the address costs the CPU picowatts of power :)

Centigram answered 27/5, 2011 at 1:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.