xref: /illumos-gate/usr/src/lib/libc/i386/gen/byteorder64.c (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright (c) 2015, Joyent, Inc.
26  */
27 
28 #include <sys/isa_defs.h>
29 #include <sys/types.h>
30 #include <netinet/in.h>
31 #include <inttypes.h>
32 
33 #if (defined(_BIG_ENDIAN) || defined(_LP64)) && !defined(__lint)
34 
35 #error	Use ISA-dependent byteorder64.c only on a 32-bit little-endian machine.
36 
37 #else
38 
39 uint64_t
40 htonll(uint64_t in)
41 {
42 	return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32));
43 }
44 
45 uint64_t
46 ntohll(uint64_t in)
47 {
48 	return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32);
49 }
50 
51 uint64_t
52 htobe64(uint64_t in)
53 {
54 	return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32));
55 }
56 
57 uint64_t
58 htole64(uint64_t in)
59 {
60 	return (in);
61 }
62 
63 uint64_t
64 betoh64(uint64_t in)
65 {
66 	return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32);
67 }
68 
69 uint64_t
70 letoh64(uint64_t in)
71 {
72 	return (in);
73 }
74 
75 uint64_t
76 be64toh(uint64_t in)
77 {
78 	return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32);
79 }
80 
81 uint64_t
82 le64toh(uint64_t in)
83 {
84 	return (in);
85 }
86 
87 #endif	/* (_BIG_ENDIAN) || _LP64) && !__lint */
88