aboutsummaryrefslogtreecommitdiffhomepage
path: root/endian.h
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-10-24 20:30:13 +0200
committerlemon <lsof@mailbox.org>2025-10-24 21:25:31 +0200
commita6693fca1061712db165b9af03008d24a1b7554f (patch)
tree6643dac2cbad1852950c31e1020281ab14f1f3af /endian.h
parente732643b8640bfdc822e2e4bd994977279b2f58b (diff)
c: bitfield initialzers
Diffstat (limited to 'endian.h')
-rw-r--r--endian.h43
1 files changed, 42 insertions, 1 deletions
diff --git a/endian.h b/endian.h
index e1e9740..08ce78f 100644
--- a/endian.h
+++ b/endian.h
@@ -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)