KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
byteorder.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 arch/dreamcast/include/arch/byteorder.h
4 Copyright (C) 2015 Lawrence Sebald
5
6*/
7
8/** \file arch/byteorder.h
9 \brief Byte-order related macros.
10 \ingroup system_arch
11
12 This file contains architecture-specific byte-order related macros and/or
13 functions. Each platform should define six macros/functions in this file:
14 arch_swap16, arch_swap32, arch_ntohs, arch_ntohl, arch_htons, and
15 arch_htonl. The first two of these swap the byte order of 16-bit and 32-bit
16 integers, respectively. The other four macros will be used by the kernel to
17 implement the network-related byte order functions.
18
19 \author Lawrence Sebald
20*/
21
22#ifndef __ARCH_BYTEORDER_H
23#define __ARCH_BYTEORDER_H
24
25#include <kos/cdefs.h>
26__BEGIN_DECLS
27
28/* Included to get the `LITTLE_ENDIAN` define */
29#include <machine/endian.h>
30
31#ifdef BYTE_ORDER
32/* If we've included <arch/types.h>, this might already be defined... */
33#undef BYTE_ORDER
34#endif
35
36/** \defgroup system_arch Byte Order
37 \brief Byte-order management for the SH4 architecture
38 \ingroup arch
39
40 @{
41*/
42
43/** \brief Define the byte-order of the platform in use. */
44#define BYTE_ORDER LITTLE_ENDIAN
45
46/** \brief Swap the byte order of a 16-bit integer.
47
48 This macro swaps the byte order of a 16-bit integer in an architecture-
49 defined manner.
50
51 \param x The value to be byte-swapped. This should be a uint16,
52 or equivalent.
53 \return The swapped value.
54*/
55__depr("arch_swap16() is deprecated, use __builtin_bswap16().")
56static inline uint16_t arch_swap16(uint16_t x) {
57 return __builtin_bswap16(x);
58}
59
60/** \brief Swap the byte order of a 32-bit integer.
61
62 This macro swaps the byte order of a 32-bit integer in an architecture-
63 defined manner.
64
65 \param x The value to be byte-swapped. This should be a uint32,
66 or equivalent.
67 \return The swapped value.
68*/
69__depr("arch_swap32() is deprecated, use __builtin_bswap32().")
71 return __builtin_bswap32(x);
72}
73
74/** \brief Convert network-to-host short.
75
76 This macro converts a network byte order (big endian) value to the host's
77 native byte order. On a little endian system (like the Dreamcast), this
78 should just call arch_swap16(). On a big endian system, this should be a
79 no-op.
80
81 \param x The value to be converted. This should be a uint16,
82 or equivalent.
83 \return The converted value.
84*/
85__depr("arch_ntohs() is deprecated, use ntohs() from <arpa/inet.h>")
86static inline uint16_t arch_ntohs(uint16_t x) {
87 return __builtin_bswap16(x);
88}
89
90/** \brief Convert network-to-host long.
91
92 This macro converts a network byte order (big endian) value to the host's
93 native byte order. On a little endian system (like the Dreamcast), this
94 should just call arch_swap32(). On a big endian system, this should be a
95 no-op.
96
97 \param x The value to be converted. This should be a uint32,
98 or equivalent.
99 \return The converted value.
100*/
101__depr("arch_ntohl() is deprecated, use ntohl() from <arpa/inet.h>")
103 return __builtin_bswap32(x);
104}
105
106/** \brief Convert host-to-network short.
107
108 This macro converts a value in the host's native byte order to network byte
109 order (big endian). On a little endian system (like the Dreamcast), this
110 should just call arch_swap16(). On a big endian system, this should be a
111 no-op.
112
113 \param x The value to be converted. This should be a uint16,
114 or equivalent.
115 \return The converted value.
116*/
117__depr("arch_htons() is deprecated, use htons() from <arpa/inet.h>")
118static inline uint16_t arch_htons(uint16_t x) {
119 return __builtin_bswap16(x);
120}
121
122/** \brief Convert host-to-network long.
123
124 This macro converts a value in the host's native byte order to network byte
125 order (big endian). On a little endian system (like the Dreamcast), this
126 should just call arch_swap32(). On a big endian system, this should be a
127 no-op.
128
129 \param x The value to be converted. This should be a uint32,
130 or equivalent.
131 \return The converted value.
132*/
133__depr("arch_htonl() is deprecated, use htonl() from <arpa/inet.h>")
135 return __builtin_bswap32(x);
136}
137
138/** @} */
139
140__END_DECLS
141
142#endif /* !__ARCH_BYTEORDER_H */
Various common macros used throughout the codebase.
static uint32_t("Please see purupuru_effect_t for modern equivalent.") PURUPURU_EFFECT2_UINTENSITY(uint8_t x)
Definition purupuru.h:96
arch_ntohs() is deprecated
Convert network-to-host short.
arch_ntohl() is deprecated
Convert network-to-host long.
use __builtin_bswap32().") static inline uint32_t arch_swap32(uint32_t x)
Definition byteorder.h:69
arch_swap32() is deprecated
Swap the byte order of a 32-bit integer.
arch_htons() is deprecated
Convert host-to-network short.
arch_swap16() is deprecated
Swap the byte order of a 16-bit integer.
use __builtin_bswap16().") static inline uint16_t arch_swap16(uint16_t x)
Definition byteorder.h:55
arch_htonl() is deprecated
Convert host-to-network long.
#define inline
Definition cdefs.h:107