00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <string.h>
00028
00029 #ifndef _RTS_H_
00030 #define _RTS_H_
00031
00032 #ifndef __GNUC__
00033 #warning "This may NOT work on non-GNUC compilers!"
00034 #endif
00035
00036
00037
00038
00039
00040
00041 #if defined(RTS_LITTLE_ENDIAN)
00042 #elif defined(RTS_BIG_ENDIAN)
00043 #else
00044
00045
00046 #if defined(__i386__)
00047
00048 #define RTS_LITTLE_ENDIAN
00049
00050 #elif defined(__x86_64)
00051
00052 #define RTS_LITTLE_ENDIAN
00053
00054 #elif defined(__i960__)
00055
00056 #define RTS_LITTLE_ENDIAN
00057
00058 #elif defined(_ARCH_PPC)
00059
00060 #define RTS_BIG_ENDIAN
00061
00062 #elif defined(__ppc__)
00063
00064 #define RTS_BIG_ENDIAN
00065
00066 #elif defined(__sparc__)
00067
00068 #define RTS_BIG_ENDIAN
00069
00070 #elif defined(__alpha__)
00071
00072 #if defined(__osf__)
00073 #define RTS_BIG_ENDIAN
00074 #else
00075 #define RTS_LITTLE_ENDIAN
00076 #endif
00077
00078 #else
00079
00080 #error "Unknown CPU type - can't proceed!"
00081
00082 #endif
00083
00084 #endif
00085
00086
00087 #ifndef TARGET_SYSTEM
00088
00089 #if defined(__linux__)
00090 #define TARGET_SYSTEM "LINUX"
00091 #elif defined(__sun__)
00092 #define TARGET_SYSTEM "SUN"
00093 #elif defined(__osf__)
00094 #define TARGET_SYSTEM "OSF1"
00095 #elif defined(__vxworks__)
00096
00097 #if defined(__i960__)
00098 #define TARGET_SYSTEM "I960"
00099 #else
00100 #define TARGET_SYSTEM "MVME"
00101 #endif
00102
00103 #else
00104 #error "Unknown OS type - can't proceed!"
00105 #endif
00106
00107 #endif
00108
00109
00110 #ifdef RTS_PROJECT_STAR
00111
00112 #define RTS_PROJECT "STAR"
00113 #ifndef PROJDIR
00114 #define PROJDIR "/RTS"
00115 #endif
00116
00117 #else
00118 #ifdef RTS_PROJECT_PP
00119
00120 #define RTS_PROJECT "PP"
00121 #ifndef PROJDIR
00122 #define PROJDIR "/PP"
00123 #endif
00124 #else
00125
00126 #define RTS_PROJECT_STAR
00127 #define RTS_PROJECT "STAR"
00128 #define PROJDIR "/tmp"
00129 #endif
00130 #endif
00131
00132 #ifndef RTS_BINDIR
00133 #define RTS_BINDIR PROJDIR "/bin/" TARGET_SYSTEM
00134 #endif
00135
00136
00137
00138 #ifdef __linux__
00139
00140 #include <byteswap.h>
00141
00142 #define swap16(x) bswap_16(x)
00143 #define swap32(x) bswap_32(x)
00144
00145 #else
00146
00147 extern inline unsigned short swap16(unsigned short x)
00148 {
00149 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) ;
00150 }
00151
00152 extern inline unsigned int swap32(unsigned int x)
00153 {
00154 return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
00155 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) ;
00156 }
00157
00158
00159 #endif
00160
00161
00162 extern inline float swapf(float f)
00163 {
00164 unsigned int x;
00165 memcpy((char *)&x, (char *)&f, 4);
00166 x = swap32(x);
00167 memcpy((char *)&f, (char *)&x, 4);
00168 return f;
00169 }
00170
00171 extern inline void swapBuff32(unsigned int *buff, int n)
00172 {
00173 for(int i=0;i<n;i++) {
00174 *buff = swap32(*buff);
00175 buff++;
00176 }
00177 }
00178
00179 #if defined(RTS_LITTLE_ENDIAN)
00180
00181 #define RTS_ENDIAN 0
00182
00183 #define l2hfloat(x) (x)
00184 #define l2h32(x) (x)
00185 #define l2h16(x) (x)
00186 #define b2hfloat(x) swapf(x)
00187 #define b2h32(x) swap32(x)
00188 #define b2h16(x) swap16(x)
00189
00190 #elif defined(RTS_BIG_ENDIAN)
00191
00192 #define RTS_ENDIAN 1
00193
00194 #define l2hfloat(x) swapf(x)
00195 #define l2h32(x) swap32(x)
00196 #define l2h16(x) swap16(x)
00197 #define b2hfloat(x) (x)
00198 #define b2h32(x) (x)
00199 #define b2h16(x) (x)
00200
00201 #else
00202
00203 #error "ENDIANESS NOT DEFINED!"
00204
00205 #endif
00206
00207 #define qswap16(test,x) ((test)?swap16(x):(x))
00208 #define qswap32(test,x) ((test)?swap32(x):(x))
00209
00210
00211
00212
00213
00214 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
00215 #define __builtin_expect(x, expected_value) (x)
00216 #endif
00217
00218 #define likely(x) __builtin_expect((x),1)
00219 #define unlikely(x) __builtin_expect((x),0)
00220
00221
00222
00223 #ifdef __CINT__
00224 #define u_int unsigned int
00225 typedef unsigned char u_char ;
00226 typedef unsigned short u_short ;
00227 #endif
00228
00229
00230
00231
00232 typedef unsigned long long int UINT64;
00233
00234 #define hi64(x) ((UINT32)(x >> 32))
00235 #define lo64(x) ((UINT32)(x & 0xffffffff))
00236 #define make64(lo, hi) ((UINT64)(((UINT64)hi << 32) | lo))
00237
00238 #endif