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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1632 jcastillo
#ifndef _ALPHA_BYTEORDER_H
2
#define _ALPHA_BYTEORDER_H
3
 
4
#undef ntohl
5
#undef ntohs
6
#undef htonl
7
#undef htons
8
 
9
#ifndef __LITTLE_ENDIAN
10
#define __LITTLE_ENDIAN
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
 
25
#ifdef __GNUC__
26
 
27
extern unsigned long int        __constant_ntohl(unsigned long int);
28
extern unsigned short int       __constant_ntohs(unsigned short int);
29
 
30
/*
31
 * The constant and non-constant versions here are the same.
32
 * Maybe I'll come up with an alpha-optimized routine for the
33
 * non-constant ones (the constant ones don't need it: gcc
34
 * will optimize it to the correct constant)
35
 */
36
 
37
extern __inline__ unsigned long int
38
__ntohl(unsigned long int x)
39
{
40
        unsigned long int res, t1, t2;
41
 
42
        __asm__(
43
        "# bswap input: %0 (aabbccdd)\n\t"
44
        "# output: %0, used %1 %2\n\t"
45
        "extlh  %0,5,%1         # %1 = dd000000\n\t"
46
        "zap    %0,0xfd,%2      # %2 = 0000cc00\n\t"
47
        "sll    %2,5,%2         # %2 = 00198000\n\t"
48
        "s8addq %2,%1,%1        # %1 = ddcc0000\n\t"
49
        "zap    %0,0xfb,%2      # %2 = 00bb0000\n\t"
50
        "srl    %2,8,%2         # %2 = 0000bb00\n\t"
51
        "extbl  %0,3,%0         # %0 = 000000aa\n\t"
52
        "or     %1,%0,%0        # %0 = ddcc00aa\n\t"
53
        "or     %2,%0,%0        # %0 = ddccbbaa\n"
54
        : "r="(res), "r="(t1), "r="(t2)
55
        : "0" (x & 0xffffffffUL));
56
        return res;
57
}
58
 
59
#define __constant_ntohl(x) \
60
   ((unsigned long int)((((x) & 0x000000ffUL) << 24) | \
61
                        (((x) & 0x0000ff00UL) <<  8) | \
62
                        (((x) & 0x00ff0000UL) >>  8) | \
63
                        (((x) & 0xff000000UL) >> 24)))
64
 
65
extern __inline__ unsigned short int
66
__ntohs(unsigned short int x)
67
{
68
        unsigned long int res, t1;
69
 
70
        __asm__(
71
        "# v0 is result; swap in-place.\n\t"
72
        "bis    %2,%2,%0        # v0 = aabb\n\t"
73
        "extwh  %0,7,%1         # t1 = bb00\n\t"
74
        "extbl  %0,1,%0         # v0 = 00aa\n\t"
75
        "bis    %0,%1,%0        # v0 = bbaa\n"
76
        : "r="(res), "r="(t1) : "r"(x));
77
        return res;
78
}
79
 
80
#define __constant_ntohs(x) \
81
((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
82
                      (((unsigned short int)(x) & 0xff00) >> 8)))
83
 
84
#define __htonl(x) __ntohl(x)
85
#define __htons(x) __ntohs(x)
86
#define __constant_htonl(x) __constant_ntohl(x)
87
#define __constant_htons(x) __constant_ntohs(x)
88
 
89
#ifdef  __OPTIMIZE__
90
#  define ntohl(x) \
91
(__builtin_constant_p((long)(x)) ? \
92
 __constant_ntohl((x)) : \
93
 __ntohl((x)))
94
#  define ntohs(x) \
95
(__builtin_constant_p((short)(x)) ? \
96
 __constant_ntohs((x)) : \
97
 __ntohs((x)))
98
#  define htonl(x) \
99
(__builtin_constant_p((long)(x)) ? \
100
 __constant_htonl((x)) : \
101
 __htonl((x)))
102
#  define htons(x) \
103
(__builtin_constant_p((short)(x)) ? \
104
 __constant_htons((x)) : \
105
 __htons((x)))
106
#endif /* __OPTIMIZE__ */
107
 
108
#endif /* __GNUC__ */
109
 
110
#endif /* _ALPHA_BYTEORDER_H */

powered by: WebSVN 2.1.0

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