--- Net2/arch/i386/include/endian.h 2018/04/24 18:04:01 1.1 +++ Net2/arch/i386/include/endian.h 2018/04/24 18:20:40 1.1.1.3 @@ -30,7 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)endian.h 7.8 (Berkeley) 4/3/91 + * from: @(#)endian.h 7.8 (Berkeley) 4/3/91 + * endian.h,v 1.3 1993/05/22 08:00:16 cgd Exp */ /* @@ -47,12 +48,39 @@ #include #endif -__BEGIN_DECLS -unsigned long htonl __P((unsigned long)); -unsigned short htons __P((unsigned short)); -unsigned long ntohl __P((unsigned long)); -unsigned short ntohs __P((unsigned short)); -__END_DECLS +#define __word_swap_long(x) \ +({ register u_long X = (x); \ + asm ("rorl $16, %1" \ + : "=r" (X) \ + : "0" (X)); \ + X; }) +#if __GNUC__ >= 2 +#define __byte_swap_long(x) \ +({ register u_long X = (x); \ + asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \ + : "=q" (X) \ + : "0" (X)); \ + X; }) +#define __byte_swap_word(x) \ +({ register u_short X = (x); \ + asm ("xchgb %h1, %b1" \ + : "=q" (X) \ + : "0" (X)); \ + X; }) +#else /* __GNUC__ >= 2 */ +#define __byte_swap_long(x) \ +({ register u_long X = (x); \ + asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \ + : "=r" (X) \ + : "0" (X)); \ + X; }) +#define __byte_swap_word(x) \ +({ register u_short X = (x); \ + asm ("rorw $8, %w1" \ + : "=r" (X) \ + : "0" (X)); \ + X; }) +#endif /* __GNUC__ >= 2 */ /* * Macros for network/external number representation conversion. @@ -70,6 +98,11 @@ __END_DECLS #else +#define ntohl __byte_swap_long +#define ntohs __byte_swap_word +#define htonl __byte_swap_long +#define htons __byte_swap_word + #define NTOHL(x) (x) = ntohl((u_long)x) #define NTOHS(x) (x) = ntohs((u_short)x) #define HTONL(x) (x) = htonl((u_long)x)