KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Byte Order

Byte-order management for the SH4 architecture More...

Files

file  byteorder.h
 Byte-order related macros.
 

Macros

#define BYTE_ORDER   LITTLE_ENDIAN
 Define the byte-order of the platform in use.
 
#define arch_swap16(x)
 Swap the byte order of a 16-bit integer.
 
#define arch_swap32(x)
 Swap the byte order of a 32-bit integer.
 
#define arch_ntohs(x)   arch_swap16(x)
 Convert network-to-host short.
 
#define arch_ntohl(x)   arch_swap32(x)
 Convert network-to-host long.
 
#define arch_htons(x)   arch_swap16(x)
 Convert host-to-network short.
 
#define arch_htonl(x)   arch_swap32(x)
 Convert host-to-network long.
 

Detailed Description

Byte-order management for the SH4 architecture

Macro Definition Documentation

◆ arch_htonl

#define arch_htonl ( x)    arch_swap32(x)

Convert host-to-network long.

This macro converts a value in the host's native byte order to network byte order (big endian). On a little endian system (like the Dreamcast), this should just call arch_swap32(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint32, or equivalent.
Returns
The converted value.

◆ arch_htons

#define arch_htons ( x)    arch_swap16(x)

Convert host-to-network short.

This macro converts a value in the host's native byte order to network byte order (big endian). On a little endian system (like the Dreamcast), this should just call arch_swap16(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint16, or equivalent.
Returns
The converted value.

◆ arch_ntohl

#define arch_ntohl ( x)    arch_swap32(x)

Convert network-to-host long.

This macro converts a network byte order (big endian) value to the host's native byte order. On a little endian system (like the Dreamcast), this should just call arch_swap32(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint32, or equivalent.
Returns
The converted value.

◆ arch_ntohs

#define arch_ntohs ( x)    arch_swap16(x)

Convert network-to-host short.

This macro converts a network byte order (big endian) value to the host's native byte order. On a little endian system (like the Dreamcast), this should just call arch_swap16(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint16, or equivalent.
Returns
The converted value.

◆ arch_swap16

#define arch_swap16 ( x)
Value:
({ \
uint16 __x = (x); \
__asm__ __volatile__("swap.b %0, %0" : "=r" (__x) : "0" (__x)); \
__x; \
})
unsigned short uint16
16-bit unsigned integer
Definition types.h:34

Swap the byte order of a 16-bit integer.

This macro swaps the byte order of a 16-bit integer in an architecture- defined manner.

Parameters
xThe value to be byte-swapped. This should be a uint16, or equivalent.
Returns
The swapped value.

◆ arch_swap32

#define arch_swap32 ( x)
Value:
({ \
uint32 __x = (x); \
__asm__ __volatile__("swap.b %0, %0\n\t" \
"swap.w %0, %0\n\t" \
"swap.b %0, %0\n\t" : "=r"(__x) : "0" (__x)); \
__x; \
})
unsigned long uint32
32-bit unsigned integer
Definition types.h:33

Swap the byte order of a 32-bit integer.

This macro swaps the byte order of a 32-bit integer in an architecture- defined manner.

Parameters
xThe value to be byte-swapped. This should be a uint32, or equivalent.
Returns
The swapped value.

◆ BYTE_ORDER

#define BYTE_ORDER   LITTLE_ENDIAN

Define the byte-order of the platform in use.