Overall
In big endian byte order, the **most significant byte (MSB) is stored at the lowest memory address, and the least significant byte (LSB) is stored at the highest memory address.
This is also known as network byte order, because it is the format used in internet protocols like TCP/IP in general.
Big-Endian in TVM
In TVM, integers within cells are serialized using the big-endian format by default. This means that when an integer is converted into a sequence of bytes to be stored, the most significant byte is placed at the beginning.
Example 1: Big-Endian Serialization
Consider the 16-bit integer 0xABCD
. In big-endian format, it would be stored as:
0xAB 0xCD
Little-Endian with Special Primitives
The text also mentions special primitives such as STULE
that allow for (de)serializing little-endian integers. In a little-endian system, the least significant byte is stored first.
Example 2: Little-Endian Serialization
Using little-endian for the same integer 0xABCD
, it would be stored as:
0xCD 0xAB
Relevance to TVM
- Big-Endian Default: TVM uses big-endian for standard serialization of integers within cells, making it a big-endian machine in this respect.
- Internal Representation: The internal representation of integers within the TVM is implementation-dependent and not relevant to how TVM operates.
- Little-Endian Primitives: Special primitives for handling little-endian integers are available, which can be useful when interfacing with systems or data formats that use little-endian. This could be important for parsing custom messages from external sources.
Summary
Understanding the endianness is vital when working with low-level data manipulation in TVM.
By default, TVM uses big-endian, but there are tools for handling little-endian data when needed.
The choice between big-endian and little-endian affects how data is read from and written to memory, so it's essential to be aware of the specific format being used in the context of TVM or any other system you are working with.