tte_byteorder.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TTE_BYTEORDER_H_
00019 #define TTE_BYTEORDER_H_
00020
00021 #define BIG_ENDIAN
00022
00023
00024 #ifdef OS_ARCH_LINUX
00025
00026 #include <asm/byteorder.h>
00027 # define tte_cpu_to_be16(x) __cpu_to_be16(x)
00028 # define tte_cpu_to_be32(x) __cpu_to_be32(x)
00029 # define tte_cpu_to_be64(x) __cpu_to_be64(x)
00030
00031 # define tte_be16_to_cpu(x) __be16_to_cpu(x)
00032 # define tte_be32_to_cpu(x) __be32_to_cpu(x)
00033 # define tte_be64_to_cpu(x) __be64_to_cpu(x)
00034
00035 # define tte_cpu_to_le16(x) __cpu_to_le16(x)
00036 # define tte_cpu_to_le32(x) __cpu_to_le32(x)
00037 # define tte_cpu_to_le64(x) __cpu_to_le64(x)
00038
00039 # define tte_le16_to_cpu(x) __le16_to_cpu(x)
00040 # define tte_le32_to_cpu(x) __le32_to_cpu(x)
00041 # define tte_le64_to_cpu(x) __le64_to_cpu(x)
00042
00043 #else
00044
00045
00046 #if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
00047 # error "You cannot have it both ways"
00048 #endif
00049
00050 #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
00051 # error "You must define LITTLE_ENDIAN or BIG_ENDIAN"
00052 #endif
00053
00054
00055
00056
00057 #ifdef BIG_ENDIAN
00058 # define tte_cpu_to_be16(x) ((uint16_t)(x))
00059 # define tte_cpu_to_be32(x) ((uint32_t)(x))
00060 # define tte_cpu_to_be64(x) ((uint64_t)(x))
00061
00062 # define tte_be16_to_cpu(x) ((uint16_t)(x))
00063 # define tte_be32_to_cpu(x) ((uint32_t)(x))
00064 # define tte_be64_to_cpu(x) ((uint64_t)(x))
00065
00066 # define tte_cpu_to_le16(x) swab16(x)
00067 # define tte_cpu_to_le32(x) swab32(x)
00068 # define tte_cpu_to_le64(x) swab64(x)
00069
00070 # define tte_le16_to_cpu(x) swab16(x)
00071 # define tte_le32_to_cpu(x) swab32(x)
00072 # define tte_le64_to_cpu(x) swab64(x)
00073
00074 #endif
00075
00076 #ifdef LITTLE_ENDIAN
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 static unsigned short swab16(unsigned short x)
00105 {
00106 return (unsigned short)(x>>8) | (unsigned short)(x<<8);
00107 }
00108
00109 static unsigned long swab32(unsigned long x)
00110 {
00111 return ( (unsigned long)((unsigned long)x>>24u) & 0xFF)
00112 | ( (unsigned long)((unsigned long)x>>8u) & 0XFF00 )
00113 | ( (unsigned long)((unsigned long)x<<8u) & 0XFF0000 )
00114 | ( (unsigned long)((unsigned long)x<<24u) & 0XFF000000 );
00115 }
00116
00117 static unsigned long long swab64(unsigned long long x)
00118 {
00119 return ( (unsigned long long)((unsigned long long)x>>56u) & 0xFF)
00120 | ( (unsigned long long)((unsigned long long)x>>40u) & 0XFF00 )
00121 | ( (unsigned long long)((unsigned long long)x>>24u) & 0XFF0000 )
00122 | ( (unsigned long long)((unsigned long long)x>>8u) & 0XFF000000 )
00123 | ( (unsigned long long)((unsigned long long)x<<8u) & 0XFF00000000 )
00124 | ( (unsigned long long)((unsigned long long)x<<24u) & 0XFF0000000000 )
00125 | ( (unsigned long long)((unsigned long long)x<<40u) & 0XFF000000000000 )
00126 | ( (unsigned long long)((unsigned long long)x<<56u) & 0XFF00000000000000 );
00127 }
00128
00129
00130 # define tte_cpu_to_be16(x) swab16(x)
00131 # define tte_cpu_to_be32(x) swab32(x)
00132 # define tte_cpu_to_be64(x) swab64(x)
00133
00134 # define tte_be16_to_cpu(x) swab16(x)
00135 # define tte_be32_to_cpu(x) swab32(x)
00136 # define tte_be64_to_cpu(x) swab64(x)
00137
00138 # define tte_cpu_to_le16(x) ((uint16_t)(x))
00139 # define tte_cpu_to_le32(x) ((uint32_t)(x))
00140 # define tte_cpu_to_le64(x) ((uint64_t)(x))
00141
00142 # define tte_le16_to_cpu(x) ((uint16_t)(x))
00143 # define tte_le32_to_cpu(x) ((uint32_t)(x))
00144 # define tte_le64_to_cpu(x) ((uint64_t)(x))
00145 #endif
00146
00147 #endif
00148
00149
00150 #endif
00151
00152