Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474

@@ -17,32 +17,50 @@
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
         .file   "byteorder.s"
 
-#include "SYS.h"
+#include <sys/asm_linkage.h>
 
         /*
-         * NOTE: htonl/ntohl are identical routines, as are htons/ntohs.
-         * As such, they could be implemented as a single routine, using
-         * multiple ALTENTRY/SET_SIZE definitions. We don't do this so
+         * NOTE: htonll/ntohll, htonl/ntohl, and htons/ntohs are identical
+         * routines. As such, they could be implemented as a single routine,
+         * using multiple ALTENTRY/SET_SIZE definitions. We don't do this so
          * that they will have unique addresses, allowing DTrace and
          * other debuggers to tell them apart. 
          */
 
+/*
+ *      unsigned long long htonll( hll )
+ *      unsigned long long ntohll( hll )
+ *      unsigned long long hll;
+ *      reverses the byte order of 'uint64_t hll' on little endian machines
+ */
+        ENTRY(htonll)
+        movq    %rdi, %rax      /* %rax = hll */
+        bswapq  %rax            /* reverses the byte order of %rax */
+        ret                     /* return (%rax) */
+        SET_SIZE(htonll)
 
+        ENTRY(ntohll)
+        movq    %rdi, %rax      /* %rax = hll */
+        bswapq  %rax            /* reverses the byte order of %rax */
+        ret                     /* return (%rax) */
+        SET_SIZE(ntohll)
+
+
 /*
  *      unsigned long htonl( hl )
  *      unsigned long ntohl( hl )
- *      long hl;
- *      reverses the byte order of 'uint32_t hl'
+ *      unsigned long hl;
+ *      reverses the byte order of 'uint32_t hl' on little endian machines
  */
         ENTRY(htonl)
         movl    %edi, %eax      /* %eax = hl */
         bswap   %eax            /* reverses the byte order of %eax */
         ret                     /* return (%eax) */

@@ -54,13 +72,12 @@
         ret                     /* return (%eax) */
         SET_SIZE(ntohl)
 
 /*
  *      unsigned short htons( hs )
- *      short hs;
- *
- *      reverses the byte order in hs.
+ *      unsigned short hs;
+ *      reverses the byte order of 'uint16_t hs' on little endian machines.
  */
         ENTRY(htons)
         movl    %edi, %eax      /* %eax = hs */
         bswap   %eax            /* reverses the byte order of %eax */
         shrl    $16, %eax       /* moves high 16-bit to low 16-bit */