|parrotcode: Byteorder Conversion Functions|
|Contents | Documentation|
docs/dev/byteorder.dev - Byteorder Conversion Functions
The byteorder code will check the endianness of an
INTVAL or an
opcode_t value and swap from little to big,
or big to little when appropriate.
Functions also exist to convert a 4,
or 16 byte character buffer to big or little endian.
The functions will be placed in the PackFile vtable and will be called when necessary.
The Parrot interpreter should be smart enough to avoid calling these functions when converting from and to the same byteorder.
The algorithm to change from one endianness to another is identical and simple to understand.
the size of an
opcode_t is used to determine at compile time how many bits should be shifted around.
Then the correct bits are shifted by the correct amounts (please look at source code for exact amounts).
The buffer change functions are implemented by a straight forward algorithm that assigns swaps all of the bytes.
INTVALinto little endian format. It is a no-op if the native format is already little endian.
INTVALinto big endian format. It is a no-op if the native format is already big endian.
opcode_tinto little endian format. It is a no-op if the native format is already little endian.
opcode_tinto big endian format. It is a no-op if the native format is already big endian.
memcpyis performed if the native format is already little endian.
memcpyis performed if the native format is already big endian.
INTVALdirectly from a bytestream
INTVALdirectly on a bytestream
Initial version by Melvin on 2002/05/01
This assumes big or little endianness...other,
more esoteric forms (such as middle endian) are not supported.
an assumption of 4 or 8 byte
opcode_t's is made.