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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-armnommu/] [byteorder.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
#ifndef __ASM_ARM_BYTEORDER_H
2
#define __ASM_ARM_BYTEORDER_H
3
 
4
#undef ntohl
5
#undef ntohs
6
#undef htonl
7
#undef htons
8
 
9
#ifndef __LITTLE_ENDIAN
10
#define __LITTLE_ENDIAN 1234
11
#endif
12
 
13
#ifndef __LITTLE_ENDIAN_BITFIELD
14
#define __LITTLE_ENDIAN_BITFIELD
15
#endif
16
 
17
extern unsigned long int        ntohl(unsigned long int);
18
extern unsigned short int       ntohs(unsigned short int);
19
extern unsigned long int        htonl(unsigned long int);
20
extern unsigned short int       htons(unsigned short int);
21
 
22
extern unsigned long int        __ntohl(unsigned long int);
23
extern unsigned short int       __ntohs(unsigned short int);
24
extern unsigned long int        __constant_ntohl(unsigned long int);
25
extern unsigned short int       __constant_ntohs(unsigned short int);
26
 
27
extern __inline__ unsigned long int
28
__ntohl(unsigned long int x)
29
{
30
        unsigned long xx;
31
        __asm__("eor\t%1, %0, %0, ror #16\n\t"
32
                "bic\t%1, %1, #0xff0000\n\t"
33
                "mov\t%0, %0, ror #8\n\t"
34
                "eor\t%0, %0, %1, lsr #8\n\t"
35
                : "=r" (x), "=&r" (xx)
36
                : "0" (x));
37
        return x;
38
}
39
 
40
#define __constant_ntohl(x) \
41
        ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
42
                             (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
43
                             (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
44
                             (((unsigned long int)(x) & 0xff000000U) >> 24)))
45
 
46
extern __inline__ unsigned short int
47
__ntohs(unsigned short int x)
48
{
49
        __asm__("eor\t%0, %0, %0, lsr #8\n\t"
50
                "eor\t%0, %0, %0, lsl #8\n\t"
51
                "bic\t%0, %0, #0xff0000\n\t"
52
                "eor\t%0, %0, %0, lsr #8\n\t"
53
                : "=r" (x)
54
                : "0" (x));
55
        return x;
56
}
57
 
58
#define __constant_ntohs(x) \
59
        ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
60
                              (((unsigned short int)(x) & 0xff00) >> 8)))
61
 
62
#define __htonl(x) __ntohl(x)
63
#define __htons(x) __ntohs(x)
64
#define __constant_htonl(x) __constant_ntohl(x)
65
#define __constant_htons(x) __constant_ntohs(x)
66
 
67
#ifdef  __OPTIMIZE__
68
#  define ntohl(x) \
69
(__builtin_constant_p((long)(x)) ? \
70
 __constant_ntohl((x)) : \
71
 __ntohl((x)))
72
#  define ntohs(x) \
73
(__builtin_constant_p((short)(x)) ? \
74
 __constant_ntohs((x)) : \
75
 __ntohs((x)))
76
#  define htonl(x) \
77
(__builtin_constant_p((long)(x)) ? \
78
 __constant_htonl((x)) : \
79
 __htonl((x)))
80
#  define htons(x) \
81
(__builtin_constant_p((short)(x)) ? \
82
 __constant_htons((x)) : \
83
 __htons((x)))
84
#endif
85
 
86
#endif
87
 

powered by: WebSVN 2.1.0

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