diff options
| author | 2025-10-24 20:30:13 +0200 | |
|---|---|---|
| committer | 2025-10-24 21:25:31 +0200 | |
| commit | a6693fca1061712db165b9af03008d24a1b7554f (patch) | |
| tree | 6643dac2cbad1852950c31e1020281ab14f1f3af /endian.h | |
| parent | e732643b8640bfdc822e2e4bd994977279b2f58b (diff) | |
c: bitfield initialzers
Diffstat (limited to 'endian.h')
| -rw-r--r-- | endian.h | 43 |
1 files changed, 42 insertions, 1 deletions
@@ -105,7 +105,48 @@ wr64be(uchar *p, uvlong x) memcpy(p, &x, sizeof x); } -/** target-endian memory writes **/ +/** target-endian memory read/write **/ + +static inline ushort +rd16targ(uchar *p) +{ + ushort x; + memcpy(&x, p, sizeof x); + if (!hostntarg_sameendian()) x = bswap16(x); + return x; +} + +static inline uint +rd32targ(uchar *p) +{ + uint x; + memcpy(&x, p, sizeof x); + if (!hostntarg_sameendian()) x = bswap16(x); + return x; +} + +static inline uvlong +rd64targ(uchar *p) +{ + uvlong x; + memcpy(&x, p, sizeof x); + if (!hostntarg_sameendian()) x = bswap16(x); + return x; +} + +static inline float +rdf32targ(uchar *p) +{ + union { uint i; float f; } u = { rd32targ(p) }; + return u.f; +} + +static inline double +rdf64targ(uchar *p) +{ + union { uvlong i; double f; } u = { rd64targ(p) }; + return u.f; +} static inline void wr16targ(uchar *p, ushort x) |