Reliability Types

What is the difference between the following types of judgment?

  • byte (8b) invariant of large and insignificance
  • half-layer (16b) invariant large and small value
  • word (32b) is an invariant of large and small specification
  • double word (64b) invariant large and small meaning

Are there other types / options?

+12
endianness
Aug 21 '08 at 23:42
source share
8 answers

There are two approaches to endian mapping: address invariance and data invariance.

Address Invariance

In this type of mapping, the byte address is always kept between large and small. This has a side effect of changing the order of significance (the most significant to the least significant) of a particular binding (for example, 2 or 4 byte words) and, therefore, the interpretation of the data. In particular, in little-endian the interpretation of data is the least significant for most significant bytes, while in big-endian the interpretation is most significant for the least significant. In both cases, the set of available bytes remains unchanged.

Example

Address Invariance (also known as Byte Invariance): The byte address is constant, and the byte value is canceled.

Addr Memory 7 0 | | (LE) (BE) |----| +0 | aa | lsb msb |----| +1 | bb | : : |----| +2 | cc | : : |----| +3 | dd | msb lsb |----| | | At Addr=0: Little-endian Big-endian Read 1 byte: 0xaa 0xaa (preserved) Read 2 bytes: 0xbbaa 0xaabb Read 4 bytes: 0xddccbbaa 0xaabbccdd 

Data invariance

In this type of mapping, the relative byte value is stored for data of a certain size. Therefore, there are different types of finite mappings that are invariant with respect to the data for different sizes. For example, a 32-bit word-invariant final matching will be used for database size 32. The effect of storing a binding value of a certain size is that byte addresses of bytes within the basis are between large and small suffixes.

Example

32-bit data invariance (also known as word invariance): A basis is a 32-bit word that always has a value of 0xddccbbaa , independent of conformation. However, for access smaller than words, the byte address is reversed between large and small endian mappings.

 Addr Memory | +3 +2 +1 +0 | <- LE |-------------------| +0 msb | dd | cc | bb | aa | lsb |-------------------| +4 msb | 99 | 88 | 77 | 66 | lsb |-------------------| BE -> | +0 +1 +2 +3 | At Addr=0: Little-endian Big-endian Read 1 byte: 0xaa 0xdd Read 2 bytes: 0xbbaa 0xddcc Read 4 bytes: 0xddccbbaa 0xddccbbaa (preserved) Read 8 bytes: 0x99887766ddccbbaa 0x99887766ddccbbaa (preserved) 

Example

16-bit data invariance (also known as half-word invariance): the null element is a 16-bit one that always has a value of 0xbbaa , independent of conformation. However, for access less than a half-word, the byte address is reversed between large and small endian mappings.

 Addr Memory | +1 +0 | <- LE |---------| +0 msb | bb | aa | lsb |---------| +2 msb | dd | cc | lsb |---------| +4 msb | 77 | 66 | lsb |---------| +6 msb | 99 | 88 | lsb |---------| BE -> | +0 +1 | At Addr=0: Little-endian Big-endian Read 1 byte: 0xaa 0xbb Read 2 bytes: 0xbbaa 0xbbaa (preserved) Read 4 bytes: 0xddccbbaa 0xddccbbaa (preserved) Read 8 bytes: 0x99887766ddccbbaa 0x99887766ddccbbaa (preserved) 

Example

64-bit data invariance (also known as double invariance): A basis is a 64-bit word that always has a value of 0x99887766ddccbbaa that is independent of the entity. However, for access smaller than a double word, the byte address is reversed between large and small endian mappings.

 Addr Memory | +7 +6 +5 +4 +3 +2 +1 +0 | <- LE |---------------------------------------| +0 msb | 99 | 88 | 77 | 66 | dd | cc | bb | aa | lsb |---------------------------------------| BE -> | +0 +1 +2 +3 +4 +5 +6 +7 | At Addr=0: Little-endian Big-endian Read 1 byte: 0xaa 0x99 Read 2 bytes: 0xbbaa 0x9988 Read 4 bytes: 0xddccbbaa 0x99887766 Read 8 bytes: 0x99887766ddccbbaa 0x99887766ddccbbaa (preserved) 
+23
Sep 14 '08 at 23:46
source share

There is also a middle or mixed end. See wikipedia for more details.

The only time I had to worry about this was writing network code in C. Networking usually uses widescreen IIRC. Most languages ​​either abstract away all this or offer libraries to ensure that you are using the correct endian-ness.

+3
Aug 21 '08 at 23:57
source share

Philibert said:

Bits

were actually inverted

I doubt that any architecture will break the byte value invariant. The order of bit fields may require inversion when matching structures containing them with data. This direct mapping depends on compiler features that are outside the scope of the C99 standard, but which can still be shared. Direct mapping is faster, but does not comply with the C99 standard, which does not provide for packing, alignment, and byte order. C99-compliant code should use slow mapping based on values, not addresses. That is, instead,

 #if LITTLE_ENDIAN struct breakdown_t { int least_significant_bit: 1; int middle_bits: 10; int most_significant_bits: 21; }; #elif BIG_ENDIAN struct breakdown_t { int most_significant_bits: 21; int middle_bits: 10; int least_significant_bit: 1; }; #else #error Huh #endif uint32_t data = ...; struct breakdown_t *b = (struct breakdown_t *)&data; 

you need to write this (and so the compiler will generate the code anyway, even for the above "direct matching"),

 uint32_t data = ...; uint32_t least_significant_bit = data & 0x00000001; uint32_t middle_bits = (data >> 1) & 0x000003FF; uint32_t most_significant_bits = (data >> 11) & 0x001fffff; 

The reason for the need to invert the order of bit fields in each endid independent data storage block for a particular application is that compilers group bit fields into bytes of growing addresses.

The "order of bits" in each byte does not matter, since the only way to extract them is to use value masks and an offset in the direction with the least significant or most significant bit. The question of “order of bits” would become important in an imaginary architecture with the concept of bit addresses. I believe that all existing architectures hide this concept in hardware and provide only the smallest compared to the most significant extraction of bits, which is a concept based on neutral byte values.

+3
Aug 27 '10 at 4:29
source share

Actually, I would describe the continent of the machine as an order of bytes within a word, and not an order of bits .

By "bytes" I mean "the smallest unit of memory that an architecture can individually control." So, if the smallest unit is 16 bits (which in x86 will be called a word), then a 32-bit "word" representing the value 0xFFFF0000 can be stored as follows:

 FFFF 0000 

or that:

 0000 FFFF 

in memory, depending on the degree.

So, if you have an 8-bit entity, this means that every word consisting of 16 bits will be stored as:

 FF 00 

or

 00 FF 

etc.

+1
Aug 22 '08 at 0:39
source share

The best article I've read about content is Understanding Big and Small Byte Byte Order .

+1
Aug 22 '08 at 1:57
source share

In practical terms, endianess refers to how the processor will interpret the contents of a specific memory location. For example, if we have a memory location 0x100 with the following contents (hexadecimal bytes)

 0x100: 12 34 56 78 90 ab cd ef Reads Little Endian Big Endian 8-bit: 12 12 16-bit: 34 12 12 34 32-bit: 78 56 34 12 12 34 56 78 64-bit: ef cd ab 90 78 56 34 12 12 34 56 78 90 ab cd ef 

In two situations where you need to remember endianess, there is network code, and if you are casting using pointers.

TCP / IP indicates that the data on the conductor should be large. If you pass types other than byte arrays (for example, pointers to structures), you should definitely use ntoh / hton macros to ensure that data is sent in large numbers. If you send from a low-intensity processor to a large number of processors (or vice versa), the data will be distorted ...

Casting problems:

 uint32_t* lptr = 0x100; uint16_t data; *lptr = 0x0000FFFF data = *((uint16_t*)lptr); 

What will be the value of the data? In a system with great enthusiasm, this would be 0 In a system with small values, this would be FFFF

0
Sep 16 '08 at 1:53
source share

13 years ago I worked on a tool that was portable for both the DEC ALPHA system and the PC. On this DEC ALPHA, the bit was actually inverted . I.e:

 1010 0011 

actually translated into

 1100 0101 

It was almost transparent and seamless in C code, except that I had a bitfield declared as

 typedef struct { int firstbit:1; int middlebits:10; int lastbits:21; }; 

which needs to be translated to (using conditional compilation #ifdef)

 typedef struct { int lastbits:21; int middlebits:10; int firstbit:1; }; 
0
Sep 16 '08 at 3:27
source share

the basic concept is the ordering of bits:

 1010 0011 

in little-endian is the same as

 0011 1010 

in big-endian (and vice versa).

You will notice order changes by grouping them, rather than a single bit. I do not know about the system, for example, where

 1100 0101 

will be a "different" version of the first version.

-one
Aug 21 '08 at 23:49
source share



All Articles