OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [include/] [asm-mips/] [byteorder.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#ifndef __ASM_MIPS_BYTEORDER_H
2
#define __ASM_MIPS_BYTEORDER_H
3
 
4
/*
5
 * FIXME: Add big endian support
6
 */
7
#undef ntohl
8
#undef ntohs
9
#undef htonl
10
#undef htons
11
 
12
#if defined (__MIPSEL__)
13
#define __LITTLE_ENDIAN
14
#define __LITTLE_ENDIAN_BITFIELD
15
#elif defined (__MIPSEB__)
16
#define __BIG_ENDIAN
17
#define __BIG_ENDIAN_BITFIELD
18
#else
19
#error "MIPS but neither __MIPSEL__ nor __MIPSEB__?"
20
#endif
21
 
22
extern unsigned long int        ntohl(unsigned long int);
23
extern unsigned short int       ntohs(unsigned short int);
24
extern unsigned long int        htonl(unsigned long int);
25
extern unsigned short int       htons(unsigned short int);
26
 
27
extern __inline__ unsigned long int     __ntohl(unsigned long int);
28
extern __inline__ unsigned short int    __ntohs(unsigned short int);
29
extern __inline__ unsigned long int     __constant_ntohl(unsigned long int);
30
extern __inline__ unsigned short int    __constant_ntohs(unsigned short int);
31
 
32
/*
33
 * The constant and non-constant versions here are the same.
34
 * Maybe I'll come up with an mips-optimized routine for the
35
 * non-constant ones (the constant ones don't need it: gcc
36
 * will optimize it to the correct constant).  Oh, and the
37
 * big endian routines that are still missing will be fairly
38
 * easy to write :-)
39
 */
40
 
41
extern __inline__ unsigned long int
42
__ntohl(unsigned long int x)
43
{
44
        return (((x & 0x000000ffU) << 24) |
45
                ((x & 0x0000ff00U) <<  8) |
46
                ((x & 0x00ff0000U) >>  8) |
47
                ((x & 0xff000000U) >> 24));
48
}
49
 
50
#define __constant_ntohl(x) \
51
        ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
52
                             (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
53
                             (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
54
                             (((unsigned long int)(x) & 0xff000000U) >> 24)))
55
 
56
extern __inline__ unsigned short int
57
__ntohs(unsigned short int x)
58
{
59
        return (((x & 0x00ff) << 8) |
60
                ((x & 0xff00) >> 8));
61
}
62
 
63
#define __constant_ntohs(x) \
64
        ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
65
                              (((unsigned short int)(x) & 0xff00) >> 8))) \
66
 
67
#define __htonl(x) __ntohl(x)
68
#define __htons(x) __ntohs(x)
69
#define __constant_htonl(x) __constant_ntohl(x)
70
#define __constant_htons(x) __constant_ntohs(x)
71
 
72
#ifdef  __OPTIMIZE__
73
#  define ntohl(x) \
74
(__builtin_constant_p((long)(x)) ? \
75
 __constant_ntohl((x)) : \
76
 __ntohl((x)))
77
#  define ntohs(x) \
78
(__builtin_constant_p((short)(x)) ? \
79
 __constant_ntohs((x)) : \
80
 __ntohs((x)))
81
#  define htonl(x) \
82
(__builtin_constant_p((long)(x)) ? \
83
 __constant_htonl((x)) : \
84
 __htonl((x)))
85
#  define htons(x) \
86
(__builtin_constant_p((short)(x)) ? \
87
 __constant_htons((x)) : \
88
 __htons((x)))
89
#endif
90
 
91
#endif /* __ASM_MIPS_BYTEORDER_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.