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

@@ -1078,11 +1078,11 @@
 #endif /* DEBUG */
 
 #endif  /* __lint */
 
         /*
-         * Berkley 4.3 introduced symbolically named interrupt levels
+         * Berkeley 4.3 introduced symbolically named interrupt levels
          * as a way deal with priority in a machine independent fashion.
          * Numbered priorities are machine specific, and should be
          * discouraged where possible.
          *
          * Note, for the machine specific priorities there are

@@ -1191,11 +1191,11 @@
         ENTRY(spl0)
         SETPRI(0)
         SET_SIZE(spl0)
 
 
-        /* splx implentation */
+        /* splx implementation */
         ENTRY(splx)
         jmp     do_splx         /* redirect to common splx code */
         SET_SIZE(splx)
 
 #endif  /* __lint */

@@ -2025,65 +2025,63 @@
         SET_SIZE(curcpup)
 
 #endif  /* __i386 */
 #endif  /* __lint */
 
+/* htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
+ * These functions reverse the byte order of the input parameter and returns
+ * the result.  This is to convert the byte order from host byte order
+ * (little endian) to network byte order (big endian), or vice versa.
+ */
+
 #if defined(__lint)
 
-/* ARGSUSED */
+uint64_t
+htonll(uint64_t i)
+{ return (i); }
+
+uint64_t
+ntohll(uint64_t i)
+{ return (i); }
+
 uint32_t
 htonl(uint32_t i)
-{ return (0); }
+{ return (i); }
 
-/* ARGSUSED */
 uint32_t
 ntohl(uint32_t i)
-{ return (0); }
+{ return (i); }
 
+uint16_t
+htons(uint16_t i)
+{ return (i); }
+
+uint16_t
+ntohs(uint16_t i)
+{ return (i); }
+
 #else   /* __lint */
 
 #if defined(__amd64)
 
+        ENTRY(htonll)
+        ALTENTRY(ntohll)
+        movq    %rdi, %rax
+        bswapq  %rax
+        ret
+        SET_SIZE(ntohll)
+        SET_SIZE(htonll)
+
         /* XX64 there must be shorter sequences for this */
         ENTRY(htonl)
         ALTENTRY(ntohl)
         movl    %edi, %eax
         bswap   %eax
         ret
         SET_SIZE(ntohl)
         SET_SIZE(htonl)
 
-#elif defined(__i386)
-
-        ENTRY(htonl)
-        ALTENTRY(ntohl)
-        movl    4(%esp), %eax
-        bswap   %eax
-        ret
-        SET_SIZE(ntohl)
-        SET_SIZE(htonl)
-
-#endif  /* __i386 */
-#endif  /* __lint */
-
-#if defined(__lint)
-
-/* ARGSUSED */
-uint16_t
-htons(uint16_t i)
-{ return (0); }
-
-/* ARGSUSED */
-uint16_t
-ntohs(uint16_t i)
-{ return (0); }
-
-
-#else   /* __lint */
-
-#if defined(__amd64)
-
         /* XX64 there must be better sequences for this */
         ENTRY(htons)
         ALTENTRY(ntohs)
         movl    %edi, %eax
         bswap   %eax

@@ -2092,10 +2090,28 @@
         SET_SIZE(ntohs) 
         SET_SIZE(htons)
 
 #elif defined(__i386)
 
+        ENTRY(htonll)
+        ALTENTRY(ntohll)
+        movl    4(%esp), %edx
+        movl    8(%esp), %eax
+        bswap   %edx
+        bswap   %eax
+        ret
+        SET_SIZE(ntohll)
+        SET_SIZE(htonll)
+
+        ENTRY(htonl)
+        ALTENTRY(ntohl)
+        movl    4(%esp), %eax
+        bswap   %eax
+        ret
+        SET_SIZE(ntohl)
+        SET_SIZE(htonl)
+
         ENTRY(htons)
         ALTENTRY(ntohs)
         movl    4(%esp), %eax
         bswap   %eax
         shrl    $16, %eax