Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libsa Add standalone 64-bit to/from {big, little}-end...



details:   https://anonhg.NetBSD.org/src/rev/f625f3a09fa1
branches:  trunk
changeset: 516855:f625f3a09fa1
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Oct 31 20:19:52 2001 +0000

description:
Add standalone 64-bit to/from {big,little}-endian routines.

diffstat:

 sys/lib/libsa/byteorder.c |  63 ++++++++++++++++++++++++++++++++++++++++++++++-
 sys/lib/libsa/byteorder.h |  10 ++++++-
 2 files changed, 71 insertions(+), 2 deletions(-)

diffs (103 lines):

diff -r 5422e8bd539f -r f625f3a09fa1 sys/lib/libsa/byteorder.c
--- a/sys/lib/libsa/byteorder.c Wed Oct 31 20:08:17 2001 +0000
+++ b/sys/lib/libsa/byteorder.c Wed Oct 31 20:19:52 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: byteorder.c,v 1.1 2001/10/30 23:35:33 thorpej Exp $    */
+/*     $NetBSD: byteorder.c,v 1.2 2001/10/31 20:19:52 thorpej Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -47,6 +47,11 @@
        uint8_t bytes[4];
 } un32;
 
+typedef union {
+       uint64_t val;
+       uint32_t words[2];
+} un64;
+
 /* 16-bit */
 
 uint16_t
@@ -146,3 +151,59 @@
                (un.bytes[1] << 8) |
                 un.bytes[0]);
 }
+
+/* 64-bit */
+
+uint64_t
+sa_htobe64(uint64_t val)
+{
+       un64 un;
+
+       un.words[BE64_HI] = sa_htobe32(val >> 32);
+       un.words[BE64_LO] = sa_htobe32(val & 0xffffffffU);
+
+       return (un.val);
+}
+
+uint64_t
+sa_htole64(uint64_t val)
+{
+       un64 un;
+
+       un.words[LE64_HI] = sa_htole32(val >> 32);
+       un.words[LE64_LO] = sa_htole32(val & 0xffffffffU);
+
+       return (un.val);
+}
+
+uint64_t
+sa_be64toh(uint64_t val)
+{
+       un64 un;
+       uint64_t rv;
+
+       un.val = val;
+       un.words[BE64_HI] = sa_be32toh(un.words[BE64_HI]);
+       un.words[BE64_LO] = sa_be32toh(un.words[BE64_LO]);
+
+       rv = (((uint64_t)un.words[BE64_HI]) << 32) |
+            un.words[BE64_LO];
+
+       return (rv);
+}
+
+uint64_t
+sa_le64toh(uint64_t val)
+{
+       un64 un;
+       uint64_t rv;
+
+       un.val = val;
+       un.words[LE64_HI] = sa_le32toh(un.words[LE64_HI]);
+       un.words[LE64_LO] = sa_le32toh(un.words[LE64_LO]);
+
+       rv = (((uint64_t)un.words[LE64_HI]) << 32) |
+            un.words[LE64_LO];
+
+       return (rv);
+}
diff -r 5422e8bd539f -r f625f3a09fa1 sys/lib/libsa/byteorder.h
--- a/sys/lib/libsa/byteorder.h Wed Oct 31 20:08:17 2001 +0000
+++ b/sys/lib/libsa/byteorder.h Wed Oct 31 20:19:52 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: byteorder.h,v 1.1 2001/10/30 23:35:33 thorpej Exp $    */
+/*     $NetBSD: byteorder.h,v 1.2 2001/10/31 20:19:52 thorpej Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -54,4 +54,12 @@
 uint32_t       sa_be32toh(uint32_t);
 uint32_t       sa_le32toh(uint32_t);
 
+/* Order of the words in a big-endian 64-bit word. */
+#define        BE64_HI 0
+#define        BE64_LO 1
+
+/* Order of the words in a little-endian 64-bit word. */
+#define        LE64_HI 1
+#define        LE64_LO 0
+
 #endif /* _LIBSA_BYTEORDER_H_ */



Home | Main Index | Thread Index | Old Index