StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rts.h
1 /*
2  This is the main, steering include file that _MUST_
3  be used before any other STAR/RTS include.
4 
5  It is currently working only for GNU C/C++ on the following
6  platforms:
7 
8  Host: Solaris SPARC
9  Linux Intel
10  Linux Alpha
11  OSF Alpha
12 
13  Target: Solaris SPARC
14  Linux Intel/AMD
15  Linux PowerPC
16  Linux Alpha
17  vxWorks PowerPC
18  vxWorks I960
19 
20 */
21 
22 /* History
23 
24  Oct 2004: made ANSI compliant, added OSF; Tonko
25  first try, June 2003, tonko
26 */
27 #include <string.h>
28 
29 #ifndef _RTS_H_
30 #define _RTS_H_
31 
32 // jml 1/8/13
33 // This ifndef __CINT__ made its way into the code
34 // when the APPLE changes were made. It causes the endianness to
35 // remain unset when CINT is processing. I've no idea what it was
36 // for, so if it is needed please figure out a way to implement it
37 // without breaking the CINT endiness...
38 //#ifndef __CINT__
39 #ifndef __GNUC__
40 #warning "This may NOT work on non-GNUC compilers!"
41 #endif
42 
43 
44 /* From this point on GNU C is assumed */
45 
46 /* ********************* Let's get the endianess, unless already defined ****************/
47 
48 #if defined(RTS_LITTLE_ENDIAN)
49 #elif defined(RTS_BIG_ENDIAN)
50 #else
51 
52 /* Let's get the target CPU */
53 #if defined(__i386__) /* assume linux, GCC 3.X (new!) */
54 
55 #define RTS_LITTLE_ENDIAN
56 
57 #elif defined(__x86_64)
58 
59 #define RTS_LITTLE_ENDIAN
60 
61 #elif defined(__i960__) /* assume vxworks, GCC 2.7 */
62 
63 #define RTS_LITTLE_ENDIAN
64 
65 #elif defined(_ARCH_PPC) /* assume vxworks, really old GCC 2.7 */
66 
67 #define RTS_BIG_ENDIAN
68 
69 #elif defined(__ppc__) /* assume GCC 2.95 at least? */
70 
71 #define RTS_BIG_ENDIAN
72 
73 #elif defined(__sparc__) /* assume Solaris ultrasparc, GCC 2.8 */
74 
75 #define RTS_BIG_ENDIAN
76 
77 #elif defined(__alpha__)
78 
79  #if defined(__osf__)
80  #define RTS_BIG_ENDIAN /* OSF is big endian */
81  #else
82  #define RTS_LITTLE_ENDIAN
83  #endif
84 
85 #else
86 
87 #error "Unknown CPU type - can't proceed!"
88 
89 #endif /* CPU types */
90 
91 #endif /* RTS_XXX_ENDIAN */
92 
93 /*********************** Find the TARGET_SYSTEM unless already defined *******************************/
94 #ifndef TARGET_SYSTEM
95 
96 #if defined(__linux__)
97 #define TARGET_SYSTEM "LINUX"
98 #elif defined(__APPLE__)
99 #define TARGET_SYSTEM "LINUX"
100 #elif defined(__sun__)
101 #define TARGET_SYSTEM "SUN"
102 #elif defined(__osf__)
103 #define TARGET_SYSTEM "OSF1"
104 #elif defined(__vxworks__)
105 
106 #if defined(__i960__)
107 #define TARGET_SYSTEM "I960"
108 #else
109 #define TARGET_SYSTEM "MVME"
110 #endif
111 
112 #else
113 #error "Unknown OS type - can't proceed!"
114 #endif
115 
116 #endif /* TARGET_SYSTEM */
117 //#endif /* !__CINT__ */
118 
119 /******************** if any of RTS_PROJECT_XXX variables are not defined, we'll define it here ******/
120 #ifdef RTS_PROJECT_STAR
121 
122  #define RTS_PROJECT "STAR"
123  #ifndef PROJDIR
124  #define PROJDIR "/RTS"
125  #endif
126 
127 #else
128  #ifdef RTS_PROJECT_PP
129 
130  #define RTS_PROJECT "PP"
131  #ifndef PROJDIR
132  #define PROJDIR "/PP"
133  #endif
134  #else /* no variable defined in the Makefile - assume STAR/unknown... */
135 
136  #define RTS_PROJECT_STAR
137  #define RTS_PROJECT "STAR"
138  #define PROJDIR "/tmp" /* unknown */
139  #endif
140 #endif
141 
142 #ifndef RTS_BINDIR
143 #define RTS_BINDIR PROJDIR "/bin/" TARGET_SYSTEM
144 #endif
145 
146 /* ********************** BYTESWAPPING STUFF ***********************/
147 
148 #if defined(__linux__) && ! defined(__APPLE__)
149 /* linux has its own (fast) swaps */
150 #include <byteswap.h>
151 
152 #define swap16(x) bswap_16(x)
153 #define swap32(x) bswap_32(x)
154 
155 #else /* non-linux stuff */
156 
157 extern inline unsigned short swap16(unsigned short x)
158 {
159  return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) ;
160 }
161 
162 extern inline unsigned int swap32(unsigned int x)
163 {
164  return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
165  (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) ;
166 }
167 
168 extern inline unsigned long long swap64(unsigned long long x) {
169  unsigned long long ret = x;
170  unsigned int *low = (unsigned int *)&ret;
171  unsigned int *high = low + 1;
172  *low = swap32(*low);
173  *high = swap32(*high);
174  return ret;
175 }
176 
177 
178 #endif /* BYTESWAP */
179 
180 /* Don't let floats get casts to ints before swapping.... */
181 extern inline float swapf(float f)
182 {
183  unsigned int x;
184  memcpy((char *)&x, (char *)&f, 4);
185  x = swap32(x);
186  memcpy((char *)&f, (char *)&x, 4);
187  return f;
188 }
189 
190 extern inline void swapBuff32(unsigned int *buff, int n)
191 {
192  for(int i=0;i<n;i++) {
193  *buff = swap32(*buff);
194  buff++;
195  }
196 }
197 
198 #if defined(RTS_LITTLE_ENDIAN)
199 
200 #define RTS_ENDIAN 0
201 
202 #define l2hfloat(x) (x)
203 #define l2h64(x) (x)
204 #define l2h32(x) (x)
205 #define l2h16(x) (x)
206 #define b2hfloat(x) swapf(x)
207 #define b2h64(x) swap64(x)
208 #define b2h32(x) swap32(x)
209 #define b2h16(x) swap16(x)
210 
211 #elif defined(RTS_BIG_ENDIAN)
212 
213 #define RTS_ENDIAN 1
214 
215 #define l2hfloat(x) swapf(x)
216 #define l2h64(x) swap64(x)
217 #define l2h32(x) swap32(x)
218 #define l2h16(x) swap16(x)
219 #define b2hfloat(x) (x)
220 #define b2h64(x) (x)
221 #define b2h32(x) (x)
222 #define b2h16(x) (x)
223 
224 #else
225 
226 #error "ENDIANESS NOT DEFINED!"
227 
228 #endif
229 
230 #define qswap16(test,x) ((test)?swap16(x):(x))
231 #define qswap32(test,x) ((test)?swap32(x):(x))
232 #define qswap64(test,x) ((test)?swap64(x):(x))
233 
234 
235 /* *** COMPILER TRICKS ***********************************************************/
236 
237 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
238 #define __builtin_expect(x, expected_value) (x)
239 #endif
240 
241 #define likely(x) __builtin_expect((x),1)
242 #define unlikely(x) __builtin_expect((x),0)
243 
244 
245 /********** UGLINESS for CINT which does not seem to be able to parse "sys/types.h" ********/
246 
247 #ifdef __CINT__
248 #define u_int unsigned int
249 typedef unsigned char u_char ;
250 typedef unsigned short u_short ;
251 #endif
252 
253 
254 // 64 bit int
255 
256 typedef unsigned long long int UINT64;
257 
258 #define hi64(x) ((UINT32)(x >> 32))
259 #define lo64(x) ((UINT32)(x & 0xffffffff))
260 #define make64(lo, hi) ((UINT64)(((UINT64)hi << 32) | lo))
261 
262 #ifdef __APPLE__
263 #define open64 open
264 #define lseek64 lseek
265 #define mmap64 mmap
266 #endif /* __APPLE__ */
267 
268 #endif /* _RTS_H_ */