removed DEFS.h
[unix-history] / usr / src / lib / libc / mips / net / htonl.s
CommitLineData
808d2265
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ralph Campbell.
7 *
8 * %sccs.include.redist.c%
9 */
10
073522ce 11#include <machine/machAsmDefs.h>
f1e99c02 12
808d2265 13#if defined(LIBC_SCCS) && !defined(lint)
073522ce 14 ASMSTR("@(#)htonl.s 5.4 (Berkeley) %G%")
808d2265
KB
15#endif /* LIBC_SCCS and not lint */
16
3efc1bf9
RC
17#include <machine/endian.h>
18#undef htonl
19#undef ntohl
20
808d2265
KB
21/*
22 * netorder = htonl(hostorder)
23 * hostorder = ntohl(netorder)
24 */
25LEAF(htonl) # a0 = 0x11223344, return 0x44332211
26ALEAF(ntohl)
3efc1bf9 27#if BYTE_ORDER == LITTLE_ENDIAN
808d2265
KB
28 srl v1, a0, 24 # v1 = 0x00000011
29 sll v0, a0, 24 # v0 = 0x44000000
30 or v0, v0, v1
31 and v1, a0, 0xff00
32 sll v1, v1, 8 # v1 = 0x00330000
33 or v0, v0, v1
34 srl v1, a0, 8
35 and v1, v1, 0xff00 # v1 = 0x00002200
36 or v0, v0, v1
3efc1bf9
RC
37#else
38#if BYTE_ORDER == BIG_ENDIAN
39 move v0, a0
40#else
41 ERROR
42#endif
43#endif
808d2265
KB
44 j ra
45END(htonl)