"In the industry", the tactic is to convert the multibyte items
after they are input. The processor manipulates the data
according to its native Endianess. Before the data is output,
it is converted to the appropriate Endianess.
There could exist integrated circuits that perform Endianess
conversion, but I haven't seen any. ...
Some processors sold as embedded-system CPUs have "endianness
controls" built in.
First, a reminder: endianness is a result of the process of breaking
up or assembling data. Suppose you have a wooden plank you bought
at the local hardware store or lumber yard, that is two units thick,
four units wide, and 24 units long. (This is not actually a "two
by four" unless the units are odd -- "two by four"s are not 2 inches
by four inches; 2x4 inches are the sizes it had before it was cut
by an ancient kind of saw that no longer is used but the sizes are
now standardized based on it. Yes, lumber-milling has ANSI/ISO
standards that vendors must obey. There are standards for *everything*
-- one of the great examples I heard was the standards for bridges
and mast-heights on ships ["mast stepping" really]. These standards
have to agree, or the ships may never get under the bridges.)
Anyway, given this single piece of wood that is two by four by 24
units, suppose you were to carve and/or paint a (long, skinny)
picture on it (perhaps a fancy Celtic knot). No matter how you
pick up and put down the plank, it continues to have a single,
cohesive image on it ... until you get out the saw. (This is a
very special saw with a zero-unit kerf; perhaps it is made of
monomolecular wire.
)
You have decided to move the plank from your house to someone
else's, and your shipping department (or post office) refuses to
send a whole 24-unit-long plank, but they will send shorter ones.
Using your saw, you cut up the plank into four pieces: 2 x 4 x 6.
Your picture spans all four pieces, but now the order you pick
them up and set them back down when you move the plank *matters*.
If you re-assemble the pieces in the wrong order, the image you
put on them, back when it was a single block of wood, will be
wrecked. The wood now has an "endian-ness", based on the order
you use when you send the separate pieces.
Note that there WAS NO ENDIAN-NESS before you broke up the item,
and if you glue the four pieces back in the correct order once they
arrive at their destination, so that they are no longer break-up-able,
there will be no endianness after that either. This "endian"
property arises *because* you broke up a whole into a bunch of
parts. The one "breaking up the whole" picks some order, and to
re-assemble the thing properly, the one re-assembling had better
use the same order.
The same holds for CPUs. If you have byte-at-a-time memory, and
the CPU has instructions that work on four-byte-at-a-time units
(such as 32-bit integers or 32-bit floating-point numbers), the
CPU is going to have to break up and assemble things. When it does
so, it will use *its* order, whatever that is, to do this. When
people talk about doing endianness conversion in moving data from
one system to another, telling you that you are going to have to
convert the data when you read it, what they really mean is:
"I have chosen to be a slave to the way my system breaks things
up, and therefore I am going to make YOU be a slave to the way
my system breaks things up too. If YOUR system happens to use
some other order, i.e., to assemble the broken-up things in
some other way, YOU are going to have to do a whole lot of work
to get around this."
Now, their choice -- to be a slave to their system -- is not
necessarily a *bad* one. In particular, it makes *their* job a
lot easier, and it makes *their* code run faster. But it is awfully
selfish, and if it turns out that they depend on you as much as
you depend on them, it could turn out to be a poor decision after
all. But if they have made that choice and you are stuck with it,
why then, you are stuck.
Today, however, some computers actually offer the programmer a
choice of endian-ness, using one or more "endian control bits".
In other words, the system has not made an irrevocable decision up
front for you-the-programmer. But the system *does* break up and
assemble things, so there *is* an order, and someone has to decide
it -- perhaps *you*, now. It turns out to be pretty easy to offer
"reversible endian-ness" in CPUs, simply by re-wiring the low-order
address lines. To reverse the endianness, we can just invert them.
(The actual on-chip implementation may be more complicated than
this, but the principle works.) Some computer-makers have taken
this a step beyond a simple "global" control bit (or pin) in (on)
the CPU, and have MMU-level and/or instruction-level control bits
for reversing. The UltraSPARC in particular has a control bit in
the CPU, another control bit in every MMU page-table entry --
including the I/O MMUs in the U2S and U2P adapters -- and a third
control bit in instructions (via the endian-inverting Address Space
Identifiers). These three bits are simply xor'ed together; the
result controls the low-order-pin inversion. This seems convenient,
but can be a big mess in practice, because the I/O can be "streaming"
or "non", and the size of the chunks whose low-order addresses are
to be inverted rapidly becomes confusing. (The microSPARC had
similar features, but no address-inverting ASIs and no "streaming
mode" I/O through U2whatever adapters, not having a UPA bus in the
first place. [They had M-to-S and M-to-P, or ran native PCI in
the first place.])
Anyway, to summarize all this: endianness is the result of breaking-up
of large, cohesive wholes into pieces. It is the one who does the
breaking-up who determines the endianness. If that one is you --
the programmer -- then you are *not* at the mercy of your system;
but if you choose to have the system do it (perhaps for speed
reasons, as the system probably does it a lot faster), just keep
in mind the control you are giving up. Make sure you are "getting
your money's worth".