g4tools  5.4.0
platform
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_platform
5 #define tools_platform
6 
7 // We do not byteswap on intel (LE) (common platform).
8 // We have then a better compression on these machines.
9 // NOTE : this is the contrary to what is done in CERN-ROOT (and Rio).
10 
11 namespace tools {
12 
13 inline bool is_little_endian() {
14  unsigned int i = 1;
15  unsigned char* b = (unsigned char*)&i;
16  // BE = Big Endian, LE = Little Endian.
17  // The Intels x86 are LE.
18  // Mac PPC b[3] is 1 (BE)
19  // Mac Intel b[0] is 1 (LE)
20  // Linux i386 b[0] is 1 (LE)
21  // Linux x86_64 b[0] is 1 (LE)
22  return (b[0]==1?true:false);
23 }
24 
25 }
26 
27 #if defined(__APPLE__)
28 #include <TargetConditionals.h>
29 #endif
30 
31 namespace tools {
32 namespace device {
33 
34 #if TARGET_OS_IPHONE
35 inline bool is_iOS() {return true;}
36 #else
37 inline bool is_iOS() {return false;}
38 #endif
39 
40 #ifdef ANDROID
41 inline bool is_Android() {return true;}
42 #else
43 inline bool is_Android() {return false;}
44 #endif
45 
46 #ifdef EMSCRIPTEN
47 inline bool is_emscripten() {return true;}
48 #else
49 inline bool is_emscripten() {return false;}
50 #endif
51 
52 
53 #if defined(ANDROID) || TARGET_OS_IPHONE
54 inline bool small_screen() {return true;}
55 //inline bool no_cursor() {return true;}
56 inline bool stop_app_button() {return true;} //the device has a button to stop the app.
57 #elif defined(EMSCRIPTEN)
58 inline bool small_screen() {return false;}
59 //inline bool no_cursor() {return false;}
60 inline bool stop_app_button() {return true;} //the device has a button to stop the app.
61 #else
62 inline bool small_screen() {return false;}
63 //inline bool no_cursor() {return false;}
64 inline bool stop_app_button() {return false;}
65 #endif
66 #if TARGET_OS_IPHONE
67 inline bool slow_cpu() {return true;}
68 #else
69 inline bool slow_cpu() {return false;}
70 #endif
71 
72 inline unsigned int tex_mem_limit() {
73  // glGet(GL_MAX_TEXTURE_SIZE) :
74  // MacBookPro : it returns 8192.
75  // SGS : it returns 2048.
76  // iPad1 : it returns 2048.
77  // iPod : it returns ?
78  // Nexus 10 : it returns ?
79 
80  // 1024*1024 //*3 = 3 145 728
81  // 2048*2048 //*3 = 12 582 912
82  // 4096*4096 //*3 = 50 331 648
83  // 8192*8192 //*3 = 201 326 592
84  // 8192*4096 //*3 = 100 663 296
85  if(small_screen()) {
86  //iOS : Apple says that max 2D tex size is 1024*1024 with two units
87  // texture available. From doc on PowerVR MBX.
88  return 2048*2048*3;
89  } else {
90  //limit = 4096*4096*3; //=8192*2048 //permit to pass ATLAS big image.
91  //permit to pass fete_science_2010/power2/image_0.jpg
92  return 8192*4096*3; //100663296
93  }
94 }
95 
96 }}
97 
101 
102 //NOTE : we avoid to have std includes here to be sure
103 // that in the below ifdef things come only from the compiler.
104 
105 namespace tools {
106 
107 inline const char* os() {
108 
109 #if TARGET_OS_IPHONE
110  static const char s_s[] = "iOS";
111 #elif defined(ANDROID)
112  static const char s_s[] = "Android";
113 #elif defined(EMSCRIPTEN)
114  static const char s_s[] = "emscripten";
115 #elif defined(_WIN32)
116  static const char s_s[] = "Windows_NT";
117 #elif __APPLE__
118  static const char s_s[] = "Darwin";
119 #elif defined(__linux)
120  static const char s_s[] = "Linux";
121 #elif defined(__alpha)
122  static const char s_s[] = "OSF1";
123 #elif defined(__CYGWIN__)
124  static const char s_s[] = "CYGWIN";
125 #else
126  static const char s_s[] = "unknown";
127 #endif
128  return s_s;
129 }
130 
131 inline bool _WIN32_defined() {
132 #ifdef _WIN32
133  return true;
134 #else
135  return false;
136 #endif
137 }
138 
139 inline const char* processor() {
140 
141 #if defined(__GNUC__)
142 
143 #if defined(__ppc__)
144  static const char s_s[] = "ppc";
145 #elif defined(__ppc64__)
146  static const char s_s[] = "ppc64";
147 #elif defined(__i386__)
148  static const char s_s[] = "i386";
149 #elif defined(__x86_64__)
150  static const char s_s[] = "x86_64";
151 #elif defined(__ia64__)
152  static const char s_s[] = "ia64";
153 #else
154  static const char s_s[] = "unknown";
155 #endif
156 
157 #elif defined(_MSC_VER)
158 
159 #if defined(_M_IX86)
160  static const char s_s[] = "ix86";
161 #elif defined(_M_X64)
162  static const char s_s[] = "x64";
163 #else
164  static const char s_s[] = "unknown";
165 #endif
166 
167 #elif defined(__alpha)
168  static const char s_s[] = "alpha";
169 
170 #else
171  static const char s_s[] = "unknown";
172 #endif
173  return s_s;
174 }
175 
176 inline const char* compiler_name() {
177 
178 #if defined(__clang__)
179  static const char s_s[] = "clang";
180 #elif defined(__GNUC__)
181  static const char s_s[] = "gcc";
182 #elif defined(_MSC_VER)
183  static const char s_s[] = "cl";
184 #elif defined(__alpha)
185  static const char s_s[] = "cxx";
186 #else
187  static const char s_s[] = "unknown";
188 #endif
189  return s_s;
190 }
191 
192 }
193 
194 #include "tosu" //does not bring any std include.
195 
196 namespace tools {
197 
198 inline void compiler(char a_s[128]) {
199  char* pos = a_s;
200  unsigned int l;
201  toss(compiler_name(),pos,l);pos += l;
202 
203 #if defined(__clang__)
204  *pos = '_';pos++;
205  tosu<unsigned int>(__clang_major__,pos,l);pos += l;
206  tosu<unsigned int>(__clang_minor__,pos,l);pos += l;
207  tosu<unsigned int>(__clang_patchlevel__,pos,l);pos += l;
208 #elif defined(__GNUC__)
209  *pos = '_';pos++;
210  tosu<unsigned int>(__GNUC__,pos,l);pos += l;
211  tosu<unsigned int>(__GNUC_MINOR__,pos,l);pos += l;
212  tosu<unsigned int>(__GNUC_PATCHLEVEL__,pos,l);pos += l;
213 #elif defined(_MSC_VER)
214  *pos = '_';pos++;
215  tosu<unsigned int>(_MSC_VER,pos,l);pos += l;
216  //_mfc_
217  //tosu<unsigned int>(_MFC_VER,pos,l);pos += l;
218 #elif defined(__alpha)
219 #else
220 #endif
221  *pos = 0;
222 }
223 
224 }
225 
226 #endif
227 
228 
229 /* We prefer to handle endianity dynamically, but with cpp macro
230  it would looks like (from luaconf.h) :
231 #if defined(__i386__) || defined(__i386) || \
232  defined(__X86__) || defined (__x86_64)
233 #define TOOLS_IS_BE 0
234 #define TOOLS_IS_LE 1
235 #elif defined(__POWERPC__) || defined(__ppc__)
236 #define TOOLS_IS_BE 1
237 #define TOOLS_IS_LE 0
238 #endif
239 */
tools::device::tex_mem_limit
unsigned int tex_mem_limit()
Definition: platform:72
tools::device::stop_app_button
bool stop_app_button()
Definition: platform:64
tools::is_little_endian
bool is_little_endian()
Definition: platform:13
tools::toss
void toss(const char *a_from, char a_s[], unsigned int &a_l)
Definition: tosu:12
tools::device::is_iOS
bool is_iOS()
Definition: platform:37
tools::os
const char * os()
Definition: platform:107
tools::device::is_Android
bool is_Android()
Definition: platform:43
tools::device::slow_cpu
bool slow_cpu()
Definition: platform:69
tools::compiler_name
const char * compiler_name()
Definition: platform:176
tools::processor
const char * processor()
Definition: platform:139
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tosu
tools::_WIN32_defined
bool _WIN32_defined()
Definition: platform:131
tools::compiler
void compiler(char a_s[128])
Definition: platform:198
tools::device::is_emscripten
bool is_emscripten()
Definition: platform:49
tools::device::small_screen
bool small_screen()
Definition: platform:62