endian.h (b4edbce08c03a664db413872cf5ba29aab3f0de4) endian.h (03516cfeb01dd63a72e120acc0ad027bd5bde63a)
1/*
2 * Copyright (c) 1987, 1991 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 44 unchanged lines hidden (view full) ---

53#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
54#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
55
56#define BYTE_ORDER LITTLE_ENDIAN
57
58#ifndef _KERNEL
59#include <sys/cdefs.h>
60#endif
1/*
2 * Copyright (c) 1987, 1991 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 44 unchanged lines hidden (view full) ---

53#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
54#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
55
56#define BYTE_ORDER LITTLE_ENDIAN
57
58#ifndef _KERNEL
59#include <sys/cdefs.h>
60#endif
61#include <machine/ansi.h>
61
62__BEGIN_DECLS
62
63__BEGIN_DECLS
63unsigned long htonl(unsigned long);
64unsigned short htons(unsigned short);
65unsigned long ntohl(unsigned long);
66unsigned short ntohs(unsigned short);
64__uint32_t htonl(__uint32_t);
65__uint16_t htons(__uint16_t);
66__uint32_t ntohl(__uint32_t);
67__uint16_t ntohs(__uint16_t);
67__END_DECLS
68
69#ifdef __GNUC__
70
68__END_DECLS
69
70#ifdef __GNUC__
71
71static __inline unsigned long
72__uint16_swap_uint32(unsigned long __x)
72static __inline __uint32_t
73__uint16_swap_uint32(__uint32_t __x)
73{
74 __asm ("rorl $16, %1" : "=r" (__x) : "0" (__x));
75
76 return __x;
77}
78
74{
75 __asm ("rorl $16, %1" : "=r" (__x) : "0" (__x));
76
77 return __x;
78}
79
79static __inline unsigned long
80__uint8_swap_uint32(unsigned long __x)
80static __inline __uint32_t
81__uint8_swap_uint32(__uint32_t __x)
81{
82#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
83 __asm ("bswap %0" : "=r" (__x) : "0" (__x));
84#else
85 __asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1"
86 : "=q" (__x) : "0" (__x));
87#endif
88 return __x;
89}
90
82{
83#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
84 __asm ("bswap %0" : "=r" (__x) : "0" (__x));
85#else
86 __asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1"
87 : "=q" (__x) : "0" (__x));
88#endif
89 return __x;
90}
91
91static __inline unsigned short
92__uint8_swap_uint16(unsigned short __x)
92static __inline __uint16_t
93__uint8_swap_uint16(__uint16_t __x)
93{
94 __asm ("xchgb %h1, %b1" : "=q" (__x) : "0" (__x));
95
96 return __x;
97}
98
99/*
100 * Macros for network/external number representation conversion.

--- 17 unchanged lines hidden ---
94{
95 __asm ("xchgb %h1, %b1" : "=q" (__x) : "0" (__x));
96
97 return __x;
98}
99
100/*
101 * Macros for network/external number representation conversion.

--- 17 unchanged lines hidden ---