42#include <sys/_types.h>
43#include <machine/endian.h>
45#ifndef _UINT8_T_DECLARED
46typedef __uint8_t uint8_t;
47#define _UINT8_T_DECLARED
50#ifndef _UINT16_T_DECLARED
51typedef __uint16_t uint16_t;
52#define _UINT16_T_DECLARED
55#ifndef _UINT32_T_DECLARED
56typedef __uint32_t uint32_t;
57#define _UINT32_T_DECLARED
60#ifndef _UINT64_T_DECLARED
61typedef __uint64_t uint64_t;
62#define _UINT64_T_DECLARED
68#define bswap16(x) __bswap16(x)
69#define bswap32(x) __bswap32(x)
70#define bswap64(x) __bswap64(x)
76#if _BYTE_ORDER == _LITTLE_ENDIAN
77#define htobe16(x) bswap16((x))
78#define htobe32(x) bswap32((x))
79#define htobe64(x) bswap64((x))
80#define htole16(x) ((uint16_t)(x))
81#define htole32(x) ((uint32_t)(x))
82#define htole64(x) ((uint64_t)(x))
84#define be16toh(x) bswap16((x))
85#define be32toh(x) bswap32((x))
86#define be64toh(x) bswap64((x))
87#define le16toh(x) ((uint16_t)(x))
88#define le32toh(x) ((uint32_t)(x))
89#define le64toh(x) ((uint64_t)(x))
91#define htobe16(x) ((uint16_t)(x))
92#define htobe32(x) ((uint32_t)(x))
93#define htobe64(x) ((uint64_t)(x))
94#define htole16(x) bswap16((x))
95#define htole32(x) bswap32((x))
96#define htole64(x) bswap64((x))
98#define be16toh(x) ((uint16_t)(x))
99#define be32toh(x) ((uint32_t)(x))
100#define be64toh(x) ((uint64_t)(x))
101#define le16toh(x) bswap16((x))
102#define le32toh(x) bswap32((x))
103#define le64toh(x) bswap64((x))
108static __inline uint16_t
109be16dec(
const void *pp)
111 uint8_t
const *
p = (uint8_t
const *)pp;
113 return (((
unsigned)
p[0] << 8) |
p[1]);
116static __inline uint32_t
117be32dec(
const void *pp)
119 uint8_t
const *
p = (uint8_t
const *)pp;
121 return (((uint32_t)
p[0] << 24) | ((uint32_t)
p[1] << 16) |
122 ((uint32_t)
p[2] << 8) |
p[3]);
125static __inline uint64_t
126be64dec(
const void *pp)
128 uint8_t
const *
p = (uint8_t
const *)pp;
130 return (((uint64_t)be32dec(
p) << 32) | be32dec(
p + 4));
133static __inline uint16_t
134le16dec(
const void *pp)
136 uint8_t
const *
p = (uint8_t
const *)pp;
138 return (((
unsigned)
p[1] << 8) |
p[0]);
141static __inline uint32_t
142le32dec(
const void *pp)
144 uint8_t
const *
p = (uint8_t
const *)pp;
146 return (((uint32_t)
p[3] << 24) | ((uint32_t)
p[2] << 16) |
147 ((uint32_t)
p[1] << 8) |
p[0]);
150static __inline uint64_t
151le64dec(
const void *pp)
153 uint8_t
const *
p = (uint8_t
const *)pp;
155 return (((uint64_t)le32dec(
p + 4) << 32) | le32dec(
p));
159be16enc(
void *pp, uint16_t u)
161 uint8_t *
p = (uint8_t *)pp;
163 p[0] = (u >> 8) & 0xff;
168be32enc(
void *pp, uint32_t u)
170 uint8_t *
p = (uint8_t *)pp;
172 p[0] = (u >> 24) & 0xff;
173 p[1] = (u >> 16) & 0xff;
174 p[2] = (u >> 8) & 0xff;
179be64enc(
void *pp, uint64_t u)
181 uint8_t *
p = (uint8_t *)pp;
183 be32enc(
p, (uint32_t)(u >> 32));
184 be32enc(
p + 4, (uint32_t)(u & 0xffffffffU));
188le16enc(
void *pp, uint16_t u)
190 uint8_t *
p = (uint8_t *)pp;
193 p[1] = (u >> 8) & 0xff;
197le32enc(
void *pp, uint32_t u)
199 uint8_t *
p = (uint8_t *)pp;
202 p[1] = (u >> 8) & 0xff;
203 p[2] = (u >> 16) & 0xff;
204 p[3] = (u >> 24) & 0xff;
208le64enc(
void *pp, uint64_t u)
210 uint8_t *
p = (uint8_t *)pp;
212 le32enc(
p, (uint32_t)(u & 0xffffffffU));
213 le32enc(
p + 4, (uint32_t)(u >> 32));
unsigned p
Definition: tte.h:17